splineBasis2D: Calculate a spline basis representation for functional data...

Description Usage Arguments Details Value See Also Examples

View source: R/univDecomp.R

Description

These functions calculate a penalized or unpenalized tensor product spline basis representation for functional data on two-dimensional domains based on the gam/bam functions in the mgcv package. See Details.

Usage

1
2
3
4
splineBasis2D(funDataObject, bs = "ps", m = NA, k = -1)

splineBasis2Dpen(funDataObject, bs = "ps", m = NA, k = -1,
  parallel = FALSE)

Arguments

funDataObject

An object of class funData containing the observed functional data samples and for which the basis representation is calculated.

bs

A vector of character strings (or a single character string), specifying the type of basis functions to be used. Defaults to "ps" (P-spline functions). Please refer to te for a list of possible basis functions.

m

A numeric vector (or a single number), the order of the spline basis. Defaults to NA, i.e. the order is chosen automatically. See s for details.

k

An numeric vector (or a single number), the number of basis functions used. Defaults to -1, i.e. the number of basis functions is chosen automatically. See s for details.

parallel

Logical (only for function splineBasis2Dpen). If TRUE, the coefficients for the basis functions are calculated in parallel. The implementation is based on the foreach function and requires a parallel backend that must be registered before. See foreach for details.

Details

If the basis representation is calculated without penalization (splineBasis2D), the coefficients are computed using the gam function from the mgcv package. In the case of penalization (splineBasis2Dpen), the function bam (for large GAMs) is used instead.

Value

scores

A matrix of scores (coefficients) with dimension N x K, reflecting the weights for each basis function in each observation, where K is the total number of basis functions used.

B

A matrix containing the scalar product of all pairs of basis functions.

ortho

Logical, set to FALSE, as basis functions are not orthonormal.

functions

NULL, as basis functions are known.

settings

A list with entries bs, m and k, giving the actual parameters used for generating the spline basis functions.

See Also

univDecomp, splineBasis1D, gam, bam, foreach

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# simulate image data for N = 100 observations
N <- 100
b1 <- eFun(seq(0,1,0.01), M = 7, type = "Poly")
b2 <- eFun(seq(-pi, pi, 0.03), M = 8, type = "Fourier")
b <- tensorProduct(b1,b2) # 2D basis functions
scores <- matrix(rnorm(N*56), nrow = N)

# calculate observations (= linear combination of basis functions)
dat <- MFPCA:::expandBasisFunction(scores = scores, functions = b)

# calculate 2D spline basis decomposition (needs some time)

# use 5 basis functions in each direction
dataDec <- MFPCA:::splineBasis2D(dat, k = c(5,5)) 


# add some noise to the data
noisyDat <- addError(dat, sd = 0.5)

# calculate 2D spline basis decomposition with penalization (needs A LOT more time)

# use 5 basis functions in each direction
noisyDataDec <- MFPCA:::splineBasis2Dpen(noisyDat, k = c(5,5)) 

MFPCA documentation built on May 2, 2019, 2:49 p.m.