Performs a principal components analysis on the given data matrix and returns the results as an object of class prcomp
.(对给定的数据矩阵执行PCA分析,通过prcomp的一个对象返回结果)
prcomp(x, ...) ## S3 method for class 'formula' prcomp(formula, data = NULL, subset, na.action, ...) ## Default S3 method: prcomp(x, retx = TRUE, center = TRUE, scale. = FALSE, tol = NULL, ...) ## S3 method for class 'prcomp' predict(object, newdata, ...)
formula |
a formula with no response variable, referring only to numeric variables. 没有响应变量的公式,只与数值变量相关! |
data |
an optional data frame (or similar: see 一个可选的数据框架包含公式formula中的变量。默认情况下,该变量来自环境(即formula) |
subset |
an optional vector used to select rows (observations) of the data matrix |
na.action |
a function which indicates what should happen when the data contain |
... |
arguments passed to or from other methods. If |
x |
a numeric or complex matrix (or data frame) which provides the data for the principal components analysis.为PCA分析提供的数值矩阵 |
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 |
scale. |
a logical value indicating whether the variables should be scaled to have unit variance before the analysis takes place. The default is 逻辑变量,表明是在进行分析前是否要为单位方差调整比例。FALSE表示固定,通常比列是可调整的。 |
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 |
object |
Object of class inheriting from |
newdata |
An optional data frame or matrix in which to look for variables with which to predict. If omitted, the scores are used. If the original fit used a formula or a data frame or a matrix with column names, |
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. The print
method for these objects prints the results in a nice format and the plot
method produces a scree plot.
Unlike princomp
, variances are computed with the usual divisor N - 1.
计算结果是对原矩阵通过奇异值分解,而不是使用协方差中特征。这通常是数值精确的首先方法。
Note that scale = TRUE
cannot be used if there are zero or constant (for center = TRUE
) variables.
prcomp
returns 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). The function |
x |
if |
center, scale |
the centering and scaling used, or |
The signs of the columns of the rotation matrix are arbitrary, and so may differ between different programs for PCA, and even between different builds of R.
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.
Mardia, K. V., J. T. Kent, and J. M. Bibby (1979) Multivariate Analysis, London: Academic Press.
Venables, W. N. and B. D. Ripley (2002) Modern Applied Statistics with S, Springer-Verlag.
biplot.prcomp
, screeplot
, princomp
, cor
, cov
, svd
, eigen
.
## signs are random require(graphics) ## the variances of the variables in the ## USArrests data vary by orders of magnitude, so scaling is appropriate prcomp(USArrests) # inappropriate prcomp(USArrests, scale = TRUE) prcomp(~ Murder + Assault + Rape, data = USArrests, scale = TRUE) plot(prcomp(USArrests)) summary(prcomp(USArrests, scale = TRUE)) biplot(prcomp(USArrests, scale = TRUE))