The eigenvectors/loadings are stored in the loadings
element of the model object returned by princomp
. See the Value
section of the help for princomp
(run ?princomp
). Here's the key section:
Value
princomp returns a list with class "princomp" containing the following
components:
loadings the matrix of variable loadings (i.e., a matrix whose
columns contain the eigenvectors). This is of class "loadings": see
loadings for its print method.
You can access the loadings with loadings(pca)
. The first matrix below contains the eigenvector of each principal component.
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
The summary
function gives you the proportion of variance explained by each 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
Another thing you can always do with any R
object is run str
, which will tell you what the object contains. For example, see below for what a princomp
model object contains, and note that one of the elements is 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"