bsplinepen: B-Spline Penalty Matrix

View source: R/bsplinepen.R

bsplinepenR Documentation

B-Spline Penalty Matrix

Description

Computes the matrix defining the roughness penalty for functions expressed in terms of a B-spline basis.

Usage

  bsplinepen(basisobj, Lfdobj=2, rng=basisobj$rangeval, returnMatrix=FALSE)

Arguments

basisobj

a B-spline basis object.

Lfdobj

either a nonnegative integer or a linear differential operator object.

rng

a vector of length 2 defining range over which the basis penalty is to be computed.

returnMatrix

logical: If TRUE, a two-dimensional is returned using a special class from the Matrix package.

Details

A roughness penalty for a function $x(t)$ is defined by integrating the square of either the derivative of $x(t)$ or, more generally, the result of applying a linear differential operator $L$ to it. The most common roughness penalty is the integral of the square of the second derivative, and this is the default. To apply this roughness penalty, the matrix of inner products of the basis functions (possibly after applying the linear differential operator to them) defining this function is necessary. This function just calls the roughness penalty evaluation function specific to the basis involved.

Value

a symmetric matrix of order equal to the number of basis functions defined by the B-spline basis object. Each element is the inner product of two B-spline basis functions after applying the derivative or linear differential operator defined by Lfdobj.

References

Ramsay, James O., Hooker, Giles, and Graves, Spencer (2009), Functional data analysis with R and Matlab, Springer, New York.

Ramsay, James O., and Silverman, Bernard W. (2005), Functional Data Analysis, 2nd ed., Springer, New York.

Ramsay, James O., and Silverman, Bernard W. (2002), Applied Functional Data Analysis, Springer, New York.

Examples

##
## bsplinepen with only one basis function
##
bspl1.1 <- create.bspline.basis(nbasis=1, norder=1)
pen1.1 <- bsplinepen(bspl1.1, 0)

##
## bspline pen for a cubic spline with knots at seq(0, 1, .1)
##
basisobj <- create.bspline.basis(c(0,1),13)
#  compute the 13 by 13 matrix of inner products of second derivatives
penmat <- bsplinepen(basisobj)

##
## with rng of class Date or POSIXct
##
# Date
invasion1 <- as.Date('1775-09-04')
invasion2 <- as.Date('1812-07-12')
earlyUS.Canada <- c(invasion1, invasion2)
BspInvade1 <- create.bspline.basis(earlyUS.Canada)
Binvadmat <- bsplinepen(BspInvade1)

# POSIXct
AmRev.ct <- as.POSIXct1970(c('1776-07-04', '1789-04-30'))
BspRev1.ct <- create.bspline.basis(AmRev.ct)
Brevmat <- bsplinepen(BspRev1.ct)


fda documentation built on Sept. 30, 2024, 9:19 a.m.