特征向量/载荷存储在由loadings
返回的模型对象的元素中princomp
。请参阅(run )Value
的帮助部分。这是关键部分:princomp
?princomp
价值
princomp返回一个包含以下组件的类“princomp”列表:
加载 可变载荷矩阵(即,其列包含特征向量的矩阵)。这是“加载”类:请参阅加载以了解其打印方法。
您可以使用 访问载荷loadings(pca)
。下面的第一个矩阵包含每个主成分的特征向量。
loadings(pca)
Loadings:
Comp.1 Comp.2 Comp.3
red 0.588 -0.505 0.631
green 0.584 -0.274 -0.764
blue 0.559 0.818 0.134
Comp.1 Comp.2 Comp.3
SS loadings 1.000 1.000 1.000
Proportion Var 0.333 0.333 0.333
Cumulative Var 0.333 0.667 1.000
该summary
函数为您提供每台 PC 解释的方差比例:
summary(pca)
Importance of components:
Comp.1 Comp.2 Comp.3
Standard deviation 136.9251939 16.85462507 1.4842831706
Proportion of Variance 0.9849601 0.01492417 0.0001157405
Cumulative Proportion 0.9849601 0.99988426 1.0000000000
你可以对任何R
对象做的另一件事是 run str
,它会告诉你对象包含什么。例如,请参阅下面的princomp
模型对象包含的内容,并注意其中一个元素是loadings
.
str(pca)
List of 7
$ sdev : Named num [1:3] 136.5 17.63 1.43
..- attr(*, "names")= chr [1:3] "Comp.1" "Comp.2" "Comp.3"
$ loadings: loadings [1:3, 1:3] 0.587 0.583 0.562 -0.515 -0.267 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : chr [1:3] "red" "green" "blue"
.. ..$ : chr [1:3] "Comp.1" "Comp.2" "Comp.3"
$ center : Named num [1:3] 162 165 173
..- attr(*, "names")= chr [1:3] "red" "green" "blue"
$ scale : Named num [1:3] 1 1 1
..- attr(*, "names")= chr [1:3] "red" "green" "blue"
$ n.obs : int 100
$ scores : num [1:100, 1:3] 85.4 110.4 151.3 149 22.8 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : NULL
.. ..$ : chr [1:3] "Comp.1" "Comp.2" "Comp.3"
$ call : language princomp(x = sr)
- attr(*, "class")= chr "princomp"
- attr(*, "class")= chr "princomp"