Learn R Programming

mixOmics (version 2.8-1)

pca: Principal Components Analysis

Description

Performs a principal components analysis on the given data matrix that can contain missing values by using the nipals algorithm.

Usage

pca(x, ncomp = ncol(x), retx = TRUE, 
    center = TRUE, scale. = FALSE, tol = NULL)

Arguments

x
a numeric matrix (or data frame) which provides the data for the principal components analysis. It can contain missing values.
ncomp
integer, the number of components to keep to perform the reconstitution of the data using the nipals algorithm. If missing ncomp=ncol(X).
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 equal the number of columns of x can be supplied. The value is passed to s
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 prcomp function, but in general scaling is advisable. Alternatively
tol
a value indicating the magnitude below which components should be omitted.

Value

  • pca returns a list with class "pca" and "prcomp" containing the following components:
  • sdevthe 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).
  • rotationthe matrix of variable loadings (i.e., a matrix whose columns contain the eigenvectors).
  • xif retx is true the value of the rotated data (the centred (and scaled if requested) data multiplied by the rotation matrix) is returned.
  • center, scalethe centering and scaling used, or FALSE.

encoding

latin1

Details

The calculation is done by a singular value decomposition of the (centered and possibly scaled) data matrix, by using the nipals algorithm. Unlike princomp, the print method for these objects prints the results in a nice format and the plot method produces a scree plot. Note that scale = TRUE cannot be used if there are zero or constant (for center = TRUE) variables. 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.

See Also

nipals, prcomp, biplot, plotIndiv, plotVar, plot3dIndiv, plot3dVar.

Examples

Run this code
data(multidrug)

## this data set contains missing values, therefore 
## the 'prcomp' function cannot be applied
pca.res <- pca(multidrug$ABC.trans, ncomp = 4, scale = TRUE)
plot(pca.res)
summary(pca.res)
biplot(pca.res, xlabs = multidrug$cell.line$Class, cex = 0.7)

Run the code above in your browser using DataLab