View source: R/univariateExpansions.R
univExpansion | R Documentation |
This function calculates a univariate basis expansion based on given scores (coefficients) and basis functions.
univExpansion( type, scores, argvals = ifelse(!is.null(functions), functions@argvals, NULL), functions, params = NULL )
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. |
This function calculates functional data X_i(t), i= 1 … N that is represented as a linear combination of basis functions b_k(t)
X_i(t) = ∑_{k = 1}^K θ_{ik} b_k(t), i = 1, …, 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.
An object of class funData
with N
observations on
argvals
, corresponding to the linear combination of the basis
functions.
The options type = "spline2Dpen"
, type =
"DCT2D"
and type = "DCT3D"
have not been tested with
ATLAS/MKL/OpenBLAS.
MFPCA
, splineFunction1D
,
splineFunction2D
, splineFunction2Dpen
,
dctFunction2D
, dctFunction3D
,
expandBasisFunction
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.