| rpca {rsvd} | R Documentation |
Fast computation of the principal components analysis using the randomized singular value decomposition.
rpca(A, k = NULL, center = TRUE, scale = TRUE, retx = TRUE, p = 10, q = 2, rand = TRUE)
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:
rotation |
array_like; |
eigvals |
array_like; |
sdev |
array_like; |
x |
array_like; |
center, scale |
array_like; |
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@uw.edu
ggscreeplot, ggindplot,
ggcorplot, plot.rpca,
predict, rsvd
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.