prcomp 位于 stats 包(package)。 说明
对给定的数据矩阵执行主成分分析,并将结果作为类 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, rank. = NULL, ...)
## S3 method for class 'prcomp'
predict(object, newdata, ...)
参数
| formula | 没有响应变量的公式,仅引用数字变量。 | 
| data | 包含公式  | 
| subset | 用于选择数据矩阵  | 
| na.action | 一个函数,指示当数据包含  | 
| ... | 传递给其他方法或从其他方法传递的参数。如果  | 
| x | 为主成分分析提供数据的数字或复杂矩阵(或 DataFrame )。 | 
| retx | 指示是否应返回旋转变量的逻辑值。 | 
| center | 一个逻辑值,指示变量是否应移动到以零为中心的位置。或者,可以提供长度等于 | 
| scale. | 一个逻辑值,指示在进行分析之前是否应将变量缩放为具有单位方差。默认值为  | 
| tol | 指示大小的值,低于该值的分量应被忽略。 (如果组件的标准差小于或等于  | 
| rank. | 可选地,指定最大等级的数字,即要使用的主成分的最大数量。可以设置为  | 
| object | 继承自 | 
| newdata | 一个可选的 DataFrame 或矩阵,用于查找用于预测的变量。如果省略,则使用分数。如果原始拟合使用具有列名称的公式或 DataFrame 或矩阵,则  | 
细节
计算是通过(中心且可能缩放的)数据矩阵的奇异值分解来完成的,而不是通过在协方差矩阵上使用eigen来完成。这通常是保证数值精度的首选方法。这些对象的 print 方法以良好的格式打印结果,而 plot 方法生成屏幕图。
与 princomp 不同,方差是使用常用除数  计算的。
请注意,如果变量为零或常量(对于 center = TRUE ),则无法使用 scale = TRUE 。
值
prcomp 返回类 "prcomp" 的列表,其中包含以下组件:
| sdev | 主成分的标准差(即协方差/相关矩阵的特征值的平方根,尽管计算实际上是使用数据矩阵的奇异值完成的)。 | 
| rotation | 变量载荷矩阵(即,其列包含特征向量的矩阵)。函数  | 
| x | 如果  | 
| center, scale | 使用的居中和缩放,或  | 
注意
旋转矩阵的列的符号是任意的,因此不同的 PCA 程序之间,甚至不同的 PCA 版本之间可能会有所不同。R.
例子
C <- chol(S <- toeplitz(.9 ^ (0:31))) # Cov.matrix and its root
all.equal(S, crossprod(C))
set.seed(17)
X <- matrix(rnorm(32000), 1000, 32)
Z <- X %*% C  ## ==>  cov(Z) ~=  C'C = S
all.equal(cov(Z), S, tolerance = 0.08)
pZ <- prcomp(Z, tol = 0.1)
summary(pZ) # only ~14 PCs (out of 32)
## or choose only 3 PCs more directly:
pz3 <- prcomp(Z, rank. = 3)
summary(pz3) # same numbers as the first 3 above
stopifnot(ncol(pZ$rotation) == 14, ncol(pz3$rotation) == 3,
          all.equal(pz3$sdev, pZ$sdev, tolerance = 1e-15)) # exactly equal typically
## 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))
参考
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.
也可以看看
相关用法
- R predict.smooth.spline 通过平滑样条拟合进行预测
- R predict 模型预测
- R profile.nls 分析 nls 对象的方法
- R predict.HoltWinters 拟合 Holt-Winters 模型的预测函数
- R proj 模型预测
- R predict.loess 预测黄土曲线或表面
- R preplot 绘图对象的预计算
- R printCoefmat 打印系数矩阵
- R profile 分析模型的通用函数
- R prop.test 等比例或给定比例检验
- R profile.glm 分析 glm 对象的方法
- R print.ts 时间序列对象的打印和格式化
- R prop.trend.test 检验比例趋势
- R predict.Arima ARIMA 的预测适合
- R predict.lm 线性模型拟合的预测方法
- R princomp 主成分分析
- R predict.nls 根据非线性最小二乘拟合进行预测
- R predict.glm GLM 拟合的预测方法
- R print.power.htest 假设检验和功效计算对象的打印方法
- R plot.stepfun 绘制阶跃函数
- R pairwise.t.test 成对 t 检验
- R plot.profile.nls 绘制 profile.nls 对象
- R plot.isoreg isoreg 对象的绘图方法
- R plot.HoltWinters HoltWinters 对象的绘图函数
- R ppoints 概率图的坐标
注:本文由纯净天空筛选整理自R-devel大神的英文原创作品 Principal Components Analysis。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
