The Result loadings of PCA in R

丶灬走出姿态 提交于 2021-02-07 20:46:33

问题


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.

it results like this

     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

the result is

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

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


回答1:


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.

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

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

Output:

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

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



来源:https://stackoverflow.com/questions/48610260/the-result-loadings-of-pca-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!