fpc {goffda} | R Documentation |
Computation of functional principal components
Description
Computation of Functional Principal Components (FPC) for equispaced and non equispaced functional data.
Usage
fpc(X_fdata, n_fpc = 3, centered = FALSE, int_rule = "trapezoid",
equispaced = FALSE, verbose = FALSE)
Arguments
X_fdata |
sample of functional data as an
|
n_fpc |
number of FPC to be computed. If |
centered |
flag to indicate if |
int_rule |
quadrature rule for approximating the definite
unidimensional integral: trapezoidal rule ( |
equispaced |
flag to indicate if |
verbose |
whether to show or not information about the |
Details
The FPC are obtained by performing the single value decomposition
\mathbf{X} \mathbf{W}^{1/2} =
\mathbf{U} \mathbf{D} (\mathbf{V}' \mathbf{W}^{1/2})
where \mathbf{X}
is the matrix of discretized functional data,
\mathbf{W}
is a diagonal matrix of weights (computed by
w_integral1D
according to int_rule
), \mathbf{D}
is the diagonal matrix with singular values (standard deviations of FPC),
\mathbf{U}
is a matrix whose columns contain the left singular
vectors, and \mathbf{V}
is a matrix whose columns contain the
right singular vectors (FPC).
Value
An "fpc"
object containing the following elements:
d |
standard deviations of the FPC (i.e., square roots of eigenvalues of the empirical autocovariance estimator). |
rotation |
orthonormal eigenfunctions (loadings or functional
principal components), as an |
scores |
rotated samples: inner products.
between |
l |
vector of index of FPC. |
equispaced |
|
Author(s)
Javier Álvarez-Liébana and Gonzalo Álvarez-Pérez.
References
Jolliffe, I. T. (2002). Principal Component Analysis. Springer-Verlag, New York.
Examples
## Computing FPC for equispaced data
# Sample data
X_fdata1 <- r_ou(n = 200, t = seq(2, 4, l = 201))
# FPC with trapezoid rule
X_fpc1 <- fpc(X_fdata = X_fdata1, n_fpc = 50, equispaced = TRUE,
int_rule = "trapezoid")
# FPC with Simpsons's rule
X_fpc2 <- fpc(X_fdata = X_fdata1, n_fpc = 50, equispaced = TRUE,
int_rule = "Simpson")
# Check if FPC are orthonormal
norms1 <- rep(0, length(X_fpc1$l))
for (i in X_fpc1$l) {
norms1[i] <- integral1D(fx = X_fpc1$rotation$data[i, ]^2,
t = X_fdata1$argvals)
}
norms2 <- rep(0, length(X_fpc2$l))
for (i in X_fpc2$l) {
norms2[i] <- integral1D(fx = X_fpc2$rotation$data[i, ]^2,
t = X_fdata1$argvals)
}
## Computing FPC for non equispaced data
# Sample data
X_fdata2 <- r_ou(n = 200, t = c(seq(0, 0.5, l = 201), seq(0.51, 1, l = 301)))
# FPC with trapezoid rule
X_fpc3 <- fpc(X_fdata = X_fdata2, n_fpc = 5, int_rule = "trapezoid",
equispaced = FALSE)
# Check if FPC are orthonormal
norms3 <- rep(0, length(X_fpc3$l))
for (i in X_fpc3$l) {
norms3[i] <- integral1D(fx = X_fpc3$rotation$data[i, ]^2,
t = X_fdata2$argvals)
}
## Efficiency comparisons
# fpc() vs. fda.usc::fdata2pc()
data(phoneme, package = "fda.usc")
mlearn <- phoneme$learn[1:10, ]
res1 <- fda.usc::fdata2pc(mlearn, ncomp = 3)
res2 <- fpc(X_fdata = mlearn, n_fpc = 3)
plot(res1$x[, 1:3], col = 1)
points(res2$scores, col = 2)
microbenchmark::microbenchmark(fda.usc::fdata2pc(mlearn, ncomp = 3),
fpc(X_fdata = mlearn, n_fpc = 3), times = 1e3,
control = list(warmup = 20))