univExpansion {MFPCA} | R Documentation |
Calculate a univariate basis expansion
Description
This function calculates a univariate basis expansion based on given scores (coefficients) and basis functions.
Usage
univExpansion(
type,
scores,
argvals = ifelse(!is.null(functions), functions@argvals, NULL),
functions,
params = NULL
)
Arguments
type |
A character string, specifying the basis for which the decomposition is to be calculated. |
scores |
A matrix of scores (coefficients) for each observation based on the given basis functions. |
argvals |
A list, representing the domain of the basis functions.
If |
functions |
A functional data object, representing the basis
functions. Can be |
params |
A list containing the parameters for the particular basis to use. |
Details
This function calculates functional data X_i(t), i= 1 \ldots N
that is represented as a linear combination of basis functions
b_k(t)
X_i(t) = \sum_{k = 1}^K \theta_{ik} b_k(t), i = 1,
\ldots, N.
The basis functions may be prespecified (such as spline
basis functions or Fourier bases) or can be estimated from observed
data (e.g. by functional principal component analysis). If type =
"default"
(i.e. a linear combination of arbitrary basis functions is
to be calculated), both scores and basis functions must be supplied.
Value
An object of class funData
with N
observations on
argvals
, corresponding to the linear combination of the basis
functions.
Warning
The options type = "spline2Dpen"
, type =
"DCT2D"
and type = "DCT3D"
have not been tested with
ATLAS/MKL/OpenBLAS.
See Also
MFPCA
, splineFunction1D
,
splineFunction2D
, splineFunction2Dpen
,
dctFunction2D
, dctFunction3D
,
expandBasisFunction
Examples
oldPar <- par(no.readonly = TRUE)
par(mfrow = c(1,1))
set.seed(1234)
### Spline basis ###
# simulate coefficients (scores) for N = 10 observations and K = 8 basis functions
N <- 10
K <- 8
scores <- t(replicate(n = N, rnorm(K, sd = (K:1)/K)))
dim(scores)
# expand spline basis on [0,1]
funs <- univExpansion(type = "splines1D", scores = scores, argvals = list(seq(0,1,0.01)),
functions = NULL, # spline functions are known, need not be given
params = list(bs = "ps", m = 2, k = K)) # params for mgcv
plot(funs, main = "Spline reconstruction")
### PCA basis ###
# simulate coefficients (scores) for N = 10 observations and K = 8 basis functions
N <- 10
K <- 8
scores <- t(replicate(n = N, rnorm(K, sd = (K:1)/K)))
dim(scores)
# Fourier basis functions as eigenfunctions
eFuns <- eFun(argvals = seq(0,1,0.01), M = K, type = "Fourier")
# expand eigenfunction basis
funs <- univExpansion(type = "uFPCA", scores = scores,
argvals = NULL, # use argvals of eFuns (default)
functions = eFuns)
plot(funs, main = "PCA reconstruction")
par(oldPar)