本文介绍了R中PCA的结果加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 R 中做 PCA 时,

When doing PCA in R,

p <- princomp(iris[,1:4])

我通过以下两种方法得出不同分量的系数:

I conclude different Components' coefficients by the following two methods:

IrisLoading <- p$loadings[,1:2] #methods1, use the fist two Comp.

结果是这样

     Comp.1      Comp.2
Sepal.Length  0.36138659 -0.65658877
Sepal.Width  -0.08452251 -0.73016143
Petal.Length  0.85667061  0.17337266
Petal.Width   0.35828920  0.07548102

那么如果我只查看其加载项

Then if I only View its Loadings by

p$loadings

结果是

Loadings:
             Comp.1 Comp.2 Comp.3 Comp.4
Sepal.Length  0.361 -0.657 -0.582  0.315
Sepal.Width         -0.730  0.598 -0.320
Petal.Length  0.857  0.173        -0.480
Petal.Width   0.358         0.546  0.754

为什么 Comp1 & 的系数2 在我筛选" Comp. 后改变了?

why the coefficients of Comp1 & 2 is changed after I "sift" the Comp.?

推荐答案

调用 p$loadings 等同于调用 print(p$loadings).默认情况下,R 使用 0.1 的截止值,这意味着它会删除绝对值小于 0.1 的任何值.它还四舍五入到小数点后 3 位,这是您可以覆盖的另一个默认参数.

Calling p$loadings is equivalent to calling print(p$loadings). By default R is using a cutoff of 0.1, meaning it is removing any values that have an absolute value less than 0.1. It is also rounding to 3 decimal places, another default argument you can overwrite.

要获得与 p$loadings[,1:2] 更相似的结果,请运行以下行:

To get a more similar result to p$loadings[,1:2], run this line:

print(p$loadings, digits = 8, cutoff = 0.01)

输出:

Loadings:
             Comp.1      Comp.2      Comp.3      Comp.4     
Sepal.Length  0.36138659 -0.65658877 -0.58202985  0.31548719
Sepal.Width  -0.08452251 -0.73016143  0.59791083 -0.31972310
Petal.Length  0.85667061  0.17337266  0.07623608 -0.47983899
Petal.Width   0.35828920  0.07548102  0.54583143  0.75365743

               Comp.1 Comp.2 Comp.3 Comp.4
SS loadings      1.00   1.00   1.00   1.00
Proportion Var   0.25   0.25   0.25   0.25
Cumulative Var   0.25   0.50   0.75   1.00

我在 loadings 类的文档中找到了此信息.您可以通过调用 ?loadings

I found this information in the documentation for the loadings class. You can see that documentation by calling ?loadings

这篇关于R中PCA的结果加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 07:37