princomp
Principal Components Analysis

Description

Calculates a set of values of uncorrelated variables from a set of values that may be correlated.

Usage

princomp(x, ...)
## S3 method for class 'formula':
princomp(formula, data = NULL, subset, na.action, ...)
## Default S3 method:
princomp(x, cor = FALSE, scores = TRUE, covmat = NULL, subset = rep(TRUE, nrow(as.matrix(x))), ...)

Arguments

You must specify at least one of x, data, or covmat.
x, formula a matrix, data frame, or formula. If you specify a matrix, the columns should correspond to variables and the rows to observations. If you specify a formula, do not place any variables on the left (response) side.
data a data frame or matrix. This argument is usually used only when you provide a formula.
covmat a list or matrix. You can specify a list of the form returned by cov.wt and cov.mve. Components must include center and cov. A cor component will not be used, however, an n.obs component, if present, will be used. If you specify a matrix, x is ignored.
scores a logical value, or an integer. If scores is TRUE, the function returns a matrix of scores for all of the components. If scores is numeric, then scores and loadings for the first scores components are returned. If scores is FALSE, scores are not computed.
cor a logical value. If TRUE, then the principal components are based on the correlation matrix rather than the covariance matrix. That is, the variables are scaled to have unit variance.
na.action a character string that specifies how to handle missing values (NAs). By default, an error is returned if missing values (NAs) are present.
subset the subset of the observations to use.
... other arguments passed in or from function.

Details

If cor = TRUE, then the data, if it exists, is standardized by the scales.
princomp is generic function. It has a method for class formula and a default method.
Value
returns a list object of class princomp that contains the standard deviations of the principal components, the loadings, and the scores (optional).
sdev a vector of standard deviations of the principal components.
loadings an orthogonal matrix of class loadings that specifies the loadings. The first column is the linear combination of columns of x that define the first principal component, and so on. If argument scores is numeric, then this contains that number of columns.
n.obs number of observations on which the estimates are based. This may not be present if covmat was used.
scores scores of some or all of the principal components for the observations.
center vector of centers for the variables.
scale vector of numbers by which the variables are scaled. If cor = FALSE, these are all 1. If cor = TRUE, then scales is the square roots of the diagonal of the cov component of covmat, if present, and otherwise it is the standard deviations of the input data variables.
terms terms object of the formula. This is not present if a formula was not used.
call an image of the call to princomp.
Background
Principal component analysis defines a rotation of the variables of x. The first derived direction (a linear combination of the variables) is chosen to maximize the standard deviation of the derived variable, the second to maximize the standard deviation among directions uncorrelated with the first, and so on.
Principal component analysis is often used as a data reduction technique, sometimes in conjunction with regression. If the variables are not all in the same units, we recommend that you scale the columns of the input before performing the principal component analysis since a variable with large variance relative to the others will dominate the first principal component.
Differences between Spotfire Enterprise Runtime for R and Open-source R
References
Many multivariate statistics books (and some regression texts) include a discussion of principal components. Below are a few examples:
Dillon, W. R. and Goldstein, M. 1984. Multivariate Analysis, Methods and Applications. New York, NY: Wiley.
Johnson, R. A. and Wichern, D. W. 1982. Applied Multivariate Statistical Analysis. Englewood Cliffs, NJ: Prentice-Hall.
Mardia, K. V., Kent, J. T., and Bibby, J. M. 1979. Multivariate Analysis. London, UK: Academic Press.
Venables, W. N. and Ripley, B. D. 2002. Modern Applied Statistics with S. Fourth Edition. New York, NY: Springer.
See Also
princomp.object, loadings, biplot, screeplot, plot.loadings, svd, cancor.
Examples
princomp(Sdatasets::prim4) 
# Use a robust estimate of the covariances and scale the variables 
prim4.pcr <- princomp(Sdatasets::prim4, covmat=cov.wt(Sdatasets::prim4),
    cor=TRUE)

print(loadings(prim4.pcr), cutoff=.5) 

princomp(~ pre.mean + post.mean + pre.dev + post.dev, data=Sdatasets::wafer)

princomp(~ Unemployed + Employed, data=Sdatasets::longley, subset=Year >1956)

Package stats version 6.1.4-13
Package Index