Description Usage Arguments Value Examples
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.
1 | reconstruct_fd_from_PCA(pca_struct, scores, centerfns = T)
|
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 |
Returns a object of type fd
that contains the reconstructed curve.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | # 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)
|
[1] "done"
[1] "done"
[1] "done"
[1] "done"
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.