predict.FPCA {fdapace} | R Documentation |
Predict FPC scores and curves for a new sample given an FPCA object
Description
Return a list containing the matrix with the first k FPC scores according to conditional expectation or numerical integration, the matrix of predicted trajectories and the prediction work grid.
Usage
## S3 method for class 'FPCA'
predict(object, newLy, newLt, sigma2 = NULL, K = NULL, xiMethod = "CE", ...)
Arguments
object |
An FPCA object. |
newLy |
A list of n vectors containing the observed values for each individual. |
newLt |
A list of n vectors containing the observation time points for each individual corresponding to y. |
sigma2 |
The user-defined measurement error variance. A positive scalar. (default: rho if applicable, otherwise sigma2 if applicable, otherwise 0 if no error. ) |
K |
The scalar defining the number of clusters to define; (default: from user-specified FPCA Object). |
xiMethod |
The integration method used to calculate the functional principal component scores (standard numerical integration 'IN' or conditional expectation 'CE'); default: 'CE'. |
... |
Not used. |
Value
A list containing the following fields:
scores |
A matrix of size n-by-k which comprise of the predicted functional principal component scores. |
predCurves |
A matrix of size n-by-l where l is the length of the work grid in object. |
predGrid |
A vector of length l which is the output grid of the predicted curves. This is same is the workgrid of object. |
Examples
set.seed(1)
n <- 50
pts <- seq(0, 1, by=0.05)
# The first n samples are for training and the rest testing
sampWiener <- Wiener(2 * n, pts)
sparsity <- 2:5
train <- Sparsify(sampWiener[seq_len(n), , drop=FALSE], pts, sparsity)
test <- Sparsify(sampWiener[seq(n + 1, 2 * n), , drop=FALSE], pts, sparsity)
res <- FPCA(train$Ly, train$Lt)
pred <- predict(res, test$Ly, test$Lt, K=3)
plot(pred$predGrid, pred$predCurves[1,])