Description Usage Arguments Details Value Note Author(s) References See Also Examples
Fast computation of the principal components analysis using the randomized singular value decomposition.
1 2 3 4 5 6 7 8 9 10 |
A |
array_like; |
k |
integer; |
center |
bool, optional; |
scale |
bool, optional; |
retx |
bool, optional; |
p |
integer, optional; |
q |
integer, optional; |
rand |
bool, optional; |
Principal component analysis is an important linear dimension reduction technique.
Randomized PCA is computed via the randomized SVD algorithm (rsvd
).
The computational gain is substantial, if the desired number of principal components
is relatively small, i.e. k << min(m,n).
The print and summary method can be used to present the results in a nice format.
A scree plot can be produced with ggscreeplot
.
The individuals factor map can be produced with ggindplot
,
and a correlation plot with ggcorplot
.
The predict function can be used to compute the scores of new observations. The data will automatically be centered (and scaled if requested). This is not fully supported for complex input matrices.
rpca
returns a list with class rpca containing the following components:
array_like;
the rotation (eigenvectors); (n, k) dimensional array.
array_like;
eigenvalues; k dimensional vector.
array_like;
standard deviations of the principal components; k dimensional vector.
array_like;
the scores / rotated data; (m, k) dimensional array.
array_like;
the centering and scaling used.
The principal components are not unique and only defined up to sign (a constant of modulus one in the complex case) and so may differ between different PCA implementations.
Similar to prcomp
the variances are computed with the usual divisor N - 1.
N. Benjamin Erichson, erichson@berkeley.edu
[1] N. B. Erichson, S. Voronin, S. L. Brunton and J. N. Kutz. 2019. Randomized Matrix Decompositions Using R. Journal of Statistical Software, 89(11), 1-48. doi: 10.18637/jss.v089.i11.
[2] N. Halko, P. Martinsson, and J. Tropp. "Finding structure with randomness: probabilistic algorithms for constructing approximate matrix decompositions" (2009). (available at arXiv https://arxiv.org/abs/0909.4061).
ggscreeplot
, ggindplot
,
ggcorplot
, plot.rpca
,
predict
, rsvd
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 | library('rsvd')
#
# Load Edgar Anderson's Iris Data
#
data('iris')
#
# log transform
#
log.iris <- log( iris[ , 1:4] )
iris.species <- iris[ , 5]
#
# Perform rPCA and compute only the first two PCs
#
iris.rpca <- rpca(log.iris, k=2)
summary(iris.rpca) # Summary
print(iris.rpca) # Prints the rotations
#
# Use rPCA to compute all PCs, similar to \code{\link{prcomp}}
#
iris.rpca <- rpca(log.iris)
summary(iris.rpca) # Summary
print(iris.rpca) # Prints the rotations
plot(iris.rpca) # Produce screeplot, variable and individuls factor maps.
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.