Keywords - Function groups - @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Group: Statistical Data Analysis
Topic: Nonparametric Methods
See also:

Function: spline
Description: spline fits a cubic spline to input data.

Link:
Usage: ynew = spline(x,y,{xnew,lambda,w})
Input:
x n x 1 vector of the predictor variable. There should be at least 4 distinct x values. The x values must be ordered x[1] <= x[2] <= ...<= x[n].
y n x 1 vector of the regressor variable. This vector must be of the same dimensionality as x.
xnew m x 1 vector of the new ordered points at which the cubic spline must be computed xnew[1] <= xnew[2] <= ...<= xnew[n]. The default value is xnew = x.
lambda a scalar that controls the choice of a smoothing method. If lambda = 0 the interpolating cubic spline is computed. In the case of lambda > 0 the ordinary cubic smoothing spline with the smoothing parameter lambda is computed. If lambda < 0 then the smoothing parameter is chosen based on the Generalized Cross Validation method. The default value is -1.
w n x 1 vector of the weights. The default value is w[i]=1.
Output:
ynew m x 1 vector that contains the smoothed data.

Note:

Example:
;cubic spline interpolation
; generate a dataset
n = 5
m = 100
t = 1:n
tnew = 1:m
xnew = tnew/m-1/m
x = t/n-1/n
y = cos(10*x)
yold = cos(10*xnew)
func = xnew~yold
d = x~y
; interpolate the data y
ynew = spline(x,y,xnew,0)
; plot the data
; the uderlying function is shown by a dashed black line
; cubic spline interpolation is a blue line
; linear interpolation is a red line
dnew = xnew~ynew
results = createdisplay(2,1)
setmaskl(d,t',4,1,2)
setmaskp(d,4,3,10)
setmaskl(dnew,tnew',1,1,3)
setmaskp(dnew,1,0,1)
setmaskl(func,tnew',0,4,2)
setmaskp(func,1,0,1)
show(results,1,1,d,dnew,func)
setgopt(results,1,1,"title","cubic spline interpolation")
;
;adaptive smoothing
; generate the dataset
n = 50
m = 100
vr = 1.0
t = 1:n
tnew = 1:m
xnew = tnew/m-1/m
x = t/n-1/n
y = cos(10*x) + 3*x
;add Gaussian white noise to the data
randomize(1234567)
data = y + vr*normal(n)
d = x~y
ndata = x~data
; call the adaptive cubic spline smoother(lambda < 0.0)
ynew = spline(x,data,xnew,-10)
; plot the data
; the uderlying function is shown by a black dashed line
; adaptive estimator is a blue line
; input data are red crosses
dnew = xnew~ynew
setmaskl(d,t',0,4,2)
setmaskp(d,0,0,10)
setmaskl(ndata,t',3,1,1)
setmaskp(ndata,4,11,8)
setmaskl(dnew,tnew',1,1,4)
setmaskp(dnew,1,0,1)
show(results,2,1,d,dnew,ndata)
setgopt(results,2,1,"title","adaptive spline smoothing")

Result:
n/a



(C) MD*TECH Method and Data Technologies, 05.02.2006