Smooth Data with Using <I>m<SUP>th</SUP></I> Derivative Penalty

Smooth Data with Using mth Derivative Penalty

DESCRIPTION:

This a generalized version of one of the regular S-PLUS functions, 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.

USAGE:

smooth.Pspline(y, argvals, wtvec=rep(1, length(x)), norder=2,
               df=norder+2, lambda=0, method=3)

REQUIRED ARGUMENTS:

y
Either a vector or matrix containing the data values to be smoothed. If a matrix, the columns correspond to replications of curves or functions.
argvals
A vector of argument values corresponding the data values to be smoothed.

OPTIONAL ARGUMENTS:

wtvec
A vector of the same length as argvals containing weights to be applied to the observations.
norder
The order of the derivative whose size is to be penalized. See below for advice on what it should be.
df
A degrees of freedom measure defining the amount of smoothness or the size of the penalty if method = 2.
lambda
A penalty parameter controlling the amount of smoothness or the size of the penalty if method = 3 or 4.
method
An integer with a value from 1 to 4 specifying the way in which the amount of smoothing is determined:
  1. the amount of smoothing is controlled by the smoothing parameter lambda.
  2. the amount of smoothing is controlled by the degrees of freedom value df.
  3. the amount of smoothing optimizes the GCV or generalized cross-validation criterion.
  4. the amount of smoothing optimizes the CV or ordinary cross-validation criterion.

VALUE:

An object of class "smooth.Pspline" containing:
norder
The order of the smoothing spline, that is, the derivative whose size is penalized.
argvals
The argument value vector.
ysmth
The values of the smooth function(s) corresponding to the values in y.
lev
An vector of leverage values.
gcv
The generalized cross-validation coefficient.
cv
The ordinary cross-validation coefficient.
lambda
The final value of the penalty parameter.
my.call
The calling statement.

DETAILS:

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 splobj is the object of class "smooth.Pspline" returned by smooth.Pspline.
plot.smooth.Pspline
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 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 lines function.
print.smooth.Pspline
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.

SEE ALSO:

smooth.basis, smooth.spline, smooth.fd

EXAMPLES:

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")