prcompfast {Morpho}R Documentation

fast Principal Component Analysis (PCA)

Description

fast Principal Component Analysis (PCA)

Usage

prcompfast(x, retx = TRUE, center = TRUE, scale. = FALSE, tol = NULL, ...)

Arguments

x

a numeric or complex matrix (or data frame) which provides the data for the principal components analysis.

retx

a logical value indicating whether the rotated variables should be returned

center

a logical value indicating whether the variables should be shifted to be zero centered. Alternately, a vector of length

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 x can be supplied. The value is passed to scale. equal the number of columns of x can be supplied. The value is passed to scale.

tol

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.

Value

prcomp returns a list with class prcomp containing the followin 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). The function princomp returns this in the element loadings.

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). For the formula method, napredict() is applied to handle the treatment of values omitted by the na.action.

center, scale:

the centering and scaling used, or FALSE

. pcafast <- prcompfast(iris[,1:4]) pcadefault <- prcompfast(iris[,1:4]) ## check if both results are idential (ignoring the sign) all.equal(lapply(pcafast,abs),lapply(pcadefault,abs))

Note

this function returns the same results as prcomp (apart from sign differences) but uses smarter matrix decompositions making it faster for nrow(x) >> ncol(x) and nrow(x) << ncol(x).


[Package Morpho version 2.12 Index]