principal_components
relates the data to a set of a components through
the eigen-decomposition of the correlation matrix, where each component explains
some variance of the data and returns the results as an object of class prcomp.
principal_components(data, retx = TRUE, center = TRUE, scale. = FALSE,
tol = NULL, ...)
numeric data.
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 vector of length equal the number of columns of x can be supplied. The value is passed to scale.
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 in general scaling is advisable. Alternatively, a vector of length equal
the number of columns of data
can be supplied. The value is passed to scale.
a value indicating the magnitude below which components should be omitted.
(Components are omitted if their standard deviations are less than or equal to tol
times the standard deviation of the first component.) With the default null setting,
no components are omitted. Other settings for tol could be tol = 0
or
tol = sqrt(.Machine$double.eps)
, which would omit essentially constant components.
arguments passed to or from other methods.
principal_components
returns a list containing the following components:
pca_sdev
: the standard deviations of the principal components (i.e., the square roots of the eigenvalues of the correlation matrix, though the calculation is actually done with the singular values of the data matrix).
pca_loadings
: the matrix of variable loadings (i.e., a matrix whose columns contain the eigenvectors).
pca_rotated
: 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)
.
pca_center
: the centering used
pca_scale
: whether scaling was used
The calculation is done by a singular value decomposition of the (centered and possibly scaled) data matrix, not by using eigen on the covariance matrix. This is generally the preferred method for numerical accuracy
# NOT RUN {
x <- matrix(rnorm(200 * 3), ncol = 10)
principal_components(x)
principal_components(x, scale = TRUE)
# }
Run the code above in your browser using DataLab