create.basis {onlinePCA}R Documentation

Create a smooth B-spline basis

Description

This function creates a smooth B-spline basis and provides tools to find the coefficients of functional data in the basis and to recover functional data from basis coefficients.

Usage

create.basis(x, p, sp = 1e-09, degree = 3, nderiv = 2)

Arguments

x

vector of observation times

p

number of basis functions

sp

smoothing parameter

degree

degree of the B splines

nderiv

order of the derivative to penalize for smoothing

Details

The knots of the B-spline basis are taken as regular quantiles of x. The function output is intended for use with functions coef2fd and fd2coef.

Value

A list with fields

B

matrix of B-splines evaluated at x (each column represents a basis function)

S

matrix that maps functional data to their (smoothed) coefficients of their projection in the basis set. For the purpose of PCA, the coefficients are premultiplied by M^{1/2}, where M is the Gram matrix associated with B

invsqrtM

matrix M^{-1/2} used to recover functional # data from their coefficients in the basis set

See Also

coef2fd, fd2coef

Examples

n <- 100 # number of curves
d <- 500 # number of observation points
grid <- (1:d)/d # observation points
p <- 50 # number of B-spline basis functions 

# Simulate Brownian motion
x <- matrix(rnorm(n*d,sd=1/sqrt(d)),n,d)
x <- t(apply(x,1,cumsum))

# Create B-spline basis 
mybasis <- create.basis(grid, p, 1e-4)

# Compute smooth basis coefficients 
beta <- fd2coef(x, mybasis)

# Recover smooth functional data
x.smooth <- coef2fd(beta, mybasis) 
	
# Standard PCA and Functional PCA
pca <- prcomp(x)
fpca <- prcomp(beta)

[Package onlinePCA version 1.3.2 Index]