Efficient computation of a truncated principal components analysis of a given data matrix
using an implicitly restarted Lanczos method from the irlba
package.
prcomp_irlba(x, n = 3, retx = TRUE, center = TRUE, scale. = FALSE, ...)
A list with class "prcomp" containing the following components:
sdev the standard deviations of the principal components (i.e., the square roots of the eigenvalues of the covariance/correlation matrix, though the calculation is actually done with the singular values of the data matrix).
rotation the matrix of variable loadings (i.e., a matrix whose columns contain the eigenvectors).
x if retx
is TRUE
the value of the rotated data (the centred
(and scaled if requested) data multiplied by the rotation
matrix) is returned. Hence, cov(x)
is the diagonal matrix
diag(sdev^2)
.
center, scale the centering and scaling used, or FALSE
.
a numeric or complex matrix (or data frame) which provides the data for the principal components analysis.
integer number of principal component vectors to return, must be less than
min(dim(x))
.
a logical value indicating whether the rotated variables should be returned.
a logical value indicating whether the variables should be
shifted to be zero centered. Alternately, a centering vector of length
equal the number of columns of x
can be supplied.
a logical value indicating whether the variables should be
scaled to have unit variance before the analysis takes place.
The default is FALSE
for consistency with S, but scaling is often advisable.
Alternatively, a vector of length equal the number of columns of x
can be supplied.
The value of scale
determines how column scaling is performed
(after centering). If scale
is a numeric vector with length
equal to the number of columns of x
, then each column of x
is
divided by the corresponding value from scale
. If scale
is
TRUE
then scaling is done by dividing the (centered) columns of
x
by their standard deviations if center=TRUE
, and the
root mean square otherwise. If scale
is FALSE
, no scaling is done.
See scale
for more details.
additional arguments passed to irlba
.
set.seed(1)
x <- matrix(rnorm(200), nrow=20)
p1 <- prcomp_irlba(x, n=3)
summary(p1)
# Compare with
p2 <- prcomp(x, tol=0.7)
summary(p2)
Run the code above in your browser using DataLab