smooth.basis | Language Reference for FDA Library
|
data2fd
, which does not employ a rougness
penalty, this function controls the nature and degree of smoothing by
penalyzing a measure of rougness. Roughness is definable in a wide
variety of ways using either derivatives or a linear differential
operator.
smooth.basis(argvals, y, fdParobj, wtvec=rep(1,n), dffactor=1, fdnames=list(NULL, dimnames(y)[2], NULL))
y
.
y
is a three-dimensional array, the first dimension
corresponds to argument values, the second to replications,
and the third to variables within replications.
If
y
is a vector, only one replicate and variable are assumed.
smooth.basis
is essentially the same as
data2fd
.
argvals
containing
weights for the values to be smoothed.
If the smoothing parameter
lambda
is zero,
there is no penalty on roughness. As
lambda increases, usually in logarithmic terms, the penalty on roughness
increases and the fitted curves become more and more smooth.
Ultimately, the curves are forced to have zero roughness in the sense of
being in the null space of the linear differential operator
object
Lfdobj
that is a member of the
fdParobj
.
For example, a common choice of roughness penalty is the integrated square
of the second derivative. This penalizes curvature. Since the second
derivative of a straight line is zero, very large values of
lambda
will force the fit to become linear.
It is also possible to control the amount of roughness by using a
degrees of freedom measure. The value equivalent to
lambda
is
found in the list returned by the function. On the other hand, it is
possible to specify a degrees of freedom value, and then use function
df2lambda
to determine the equivalent value of
lambda
.
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. The function
plotfit.fd
was
designed for this purpose.
An alternative to using
smooth.basis
is to first represent
the data in a basis system with reasonably high resolution using
data2fd
, and then smooth the resulting functional data object
using function
smooth.fd
.
# Shows the effects of three 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),101) lambda <- 1 fdParobj <- fdPar(basisobj, 3, lambda) result1 <- smooth.basis(x, y, fdParobj) yfd1 <- result1$fdobj c(result1$df,result1$gcv) # display df and gcv measures lambda <- 1e-4 fdParobj <- fdPar(basisobj, 3, lambda) result2 <- smooth.basis(x, y, fdParobj) yfd2 <- result2$fdobj c(result2$df,result2$gcv) lambda <- 0 fdParobj <- fdPar(basisobj, 3, lambda) result3 <- smooth.basis(x, y, fdParobj) yfd3 <- result3$fdobj c(result3$df,result3$gcv) plot(x,y) # plot the data lines(yfd1, lty=2) # add heavily penalized smooth lines(yfd2, lty=1) # add reasonably penalized smooth lines(yfd3, lty=3) # add smooth without any penalty legend(-1,3,c("1","0.0001","0"),lty=c(2,1,3)) plotfit.fd(y, x, yfd2) # plot data and smooth