Smooth a Functional Data Object Using a Roughness Penalty

Smooth a Functional Data Object Using a Roughness Penalty

DESCRIPTION:

This function is intended to apply a roughness penalized smooth to data already set up as a functional data object. For example, data may have been converted to a functional data object using function data2fd using a fairly large set of basis functions, and subsequently it was desired to smooth the functional data object that resulted.

USAGE:

smooth.fd(fd, Lfd=NULL, lambda=0, rebase=T)

REQUIRED ARGUMENTS:

fd
The functional data object to be smoothed.

OPTIONAL ARGUMENTS:

Lfd
Either a nonnegative integer or a linear differential operator object. If present, the derivative or the value of applying the operator is evaluated rather than the functions themselves.
lambda
A nonnegative value controlling the amount of roughness in the data.
rebase
A logical variable that is only relevant if the basis is a polygonal basis of type "polyg". If this case, if rebase is TRUE , then the basis is changed to a cubic bspline basis before smoothing.

VALUE:

A functional data object.

DETAILS:

See function smooth.basis for details.

REFERENCES:

A discussion of roughness penalties can be found in Chapter 4 of Ramsay, J. O. and Silverman, B.W. (1997) Functional Data Analysis. More information can be found in recent texts on nonparametric regression.

SEE ALSO:

data2fd, plotfit.fd, smooth.basis, project.basis

EXAMPLES:

#  Shows the effects of two levels of smoothing
#  where the size of the third derivative is penalized.
#  The null space contains quadratic functions.
x <- seq(-1,1,0.02)
y <- x + 3*exp(-6*x^2) + rnorm(rep(1,101))*0.2
#  set up a saturated B-spline basis
basisobj <- create.bspline.basis(c(-1,1),81)
#  convert to a functional data object that interpolates the data.
result <- smooth.basis(y, x, basisobj)
yfd  <- result$fd
yfd1 <- smooth.fd(yfd, Lfd = 3, lambda = 1e-6)
yfd2 <- smooth.fd(yfd, Lfd = 3, lambda = 1)
#  plot the data and smooth
plot(x,y)           # plot the data
lines.fd(yfd1, lty=1)  #  add moderately penalized smooth
lines.fd(yfd2, lty=3)  #  add heavily  penalized smooth
legend(-1,3,c("0.000001","1"),lty=c(1,3))
#  plot the data and smoothing using function plotfit.fd
plotfit.fd(y, x, yfd1)  # plot data and smooth