reconstruct_fd_from_PCA {fdaACF} | R Documentation |
Obtain the reconstructed curves after PCA
Description
This function reconstructs the functional curves from a score vector using the basis obtained after applying functional PCA. This allows the user to draw estimations from the joint density of the FPCA scores and reconstruct the curves for those new scores.
Usage
reconstruct_fd_from_PCA(pca_struct, scores, centerfns = T)
Arguments
pca_struct |
List obtained after calling
function |
scores |
Numerical vector that contains the scores of the fPCA decomposition for one functional observation. |
centerfns |
Logical value specifying
wheter the FPCA performed used |
Value
Returns a object of type fd
that contains the reconstructed curve.
Examples
# Example 1
# Simulate fd
nobs <- 200
dv <- 10
basis<-fda::create.bspline.basis(rangeval=c(0,1),nbasis=10)
set.seed(5)
C <- matrix(rnorm(nobs*dv), ncol = dv, nrow = nobs)
fd_sim <- fda::fd(coef=t(C),basis)
# Perform FPCA
pca_struct <- fda::pca.fd(fd_sim,nharm = 6)
# Reconstruct first curve
fd_rec <- reconstruct_fd_from_PCA(pca_struct = pca_struct, scores = pca_struct$scores[1,])
plot(fd_sim[1])
plot(fd_rec, add = TRUE, col = "red")
legend("topright",
legend = c("Real Curve", "PCA Reconstructed"),
col = c("black","red"),
lty = 1)
# Example 2 (Perfect reconstruction)
# Simulate fd
nobs <- 200
dv <- 7
basis<-fda::create.bspline.basis(rangeval=c(0,1),nbasis=dv)
set.seed(5)
C <- matrix(rnorm(nobs*dv), ncol = dv, nrow = nobs)
fd_sim <- fda::fd(coef=t(C),basis)
# Perform FPCA
pca_struct <- fda::pca.fd(fd_sim,nharm = dv)
# Reconstruct first curve
fd_rec <- reconstruct_fd_from_PCA(pca_struct = pca_struct, scores = pca_struct$scores[1,])
plot(fd_sim[1])
plot(fd_rec, add = TRUE, col = "red")
legend("topright",
legend = c("Real Curve", "PCA Reconstructed"),
col = c("black","red"),
lty = 1)
[Package fdaACF version 1.0.0 Index]