smooth.Pspline | Language Reference for FDA Library
|
smooth.spline
, that permits
a penalty on the size of the derivative of any order m rather
than just m = 2. It uses functions coded in C or Fortran that
economize on
storage and are much faster than the native S-PLUS code that is used in
function
smooth.basis
. Consequently, it is more suitable for
problems involving the need for very large number of basis functions,
meaning in practice more than about 100.
smooth.Pspline(x, y, w=rep(1, length(x)), norder=2, df=norder + 2, spar=0, method=3)
argvals
containing weights
to be applied to the observations.
method = 2.
method
= 3 or
4.
spar
.df
.y.
The need to choose the order m of the derivative arises if one needs smooth estimates of one or more derivatives. Generally, the advice is to choose m to be 2 larger than the highest order of derivative required. This in effect penalizes the curvature of that derive. So if the second derivative or acceleration is required, then use m = 4.
Like S-PLUS function
smooth.spline
, this function also
comes with additional functions:
predict.smooth.Pspline
:
calculates values of a derivative of the smoothing function at argument
values
argvals.
The call is
predict.smooth.Pspline(splobj, argvals, nderiv = 0)where <CODE>splobj</CODE> is the object of class "smooth.Pspline" returned by <CODE>smooth.Pspline.</CODE></P> <P><P> <CODE>plot.smooth.Pspline</CODE>: plots an object of class "smooth.Pspline". The call is
plot.smooth.Pspline(splobj, ...)where
splobj
is the object of class "smooth.Pspline" returned
by
smooth.Pspline.
Additional arguments for controlling the
plot may also supplied, as in the regular
plot
function.
lines.smooth.Pspline
: adds lines to an existing plot
showing an object of class "smooth.Pspline". The call is
lines.smooth.Pspline(splobj, ...)where <CODE>splobj</CODE> is the object of class "smooth.Pspline" returned by <CODE>smooth.Pspline.</CODE> Additional arguments for controlling the plot may also supplied, as in the regular <CODE>lines</CODE> function.</P> <P><P> <CODE>print.smooth.Pspline</CODE>: prints an object of class "smooth.Pspline". The call is
print.smooth.Pspline(splobj, ...)where
splobj
is the object of class "smooth.Pspline" returned
by
smooth.Pspline.
Additional arguments for controlling the
plot may also supplied, as in the regular
print
function.
One should not put complete faith in any automatic method for
selecting
lambda
, including the GCV method. There are many
reasons for this. For example, if derivatives are required, then the
smoothing level that is automatically selected may give unacceptably
rough derivatives. These methods are also highly sensitive to the
assumption of independent errors, which is usually dubious with
functional data. The best advice is to start with the value minimizing
the
gcv
measure, and then explore
lambda
values a few
log units up and down from this value to see what the smoothing function
and its derivatives look like.
x <- seq(-1,1,0.02) y <- x + 3*exp(-6*x^2) + rnorm(rep(1,101))*0.2 # smooth the data by minimizing the GCV criterion # penalize the 4th derivative to get a smooth 2nd derivative splobj <- smooth.Pspline(y, x, norder = 4) plot(x,y) # plot the data lines.smooth.Pspline(splobj) # add the smooth print.smooth.Pspline(splobj) # display the results # plot the 2nd derivative accel <- predict.smooth.Pspline(splobj, argvals, nderiv=2) plot(argvals, accel, type="l")