19

This should be very basic and I hope someone can help me. I ran a principal component analysis with the following call:

pca <- princomp(....)
summary(pca)

Summary pca returns this description:

                          PC1    PC2     PC3
Standard deviation     2.8788 2.7862  2.1845
Proportion of Variance 0.1977 0.1549 0.07831

Look at the second line which shows the variance explained by each PC. How can I programmatically extract this vector in my script from the variable pca. I have done enough search and cannot find an answer.

1
  • Its calculated in the print method, and is not returned. Look at stats:::print.summary.princomp ti see where it is generated.
    – user20650
    Mar 14, 2015 at 2:47

2 Answers 2

24

Proportion of Variance is nothing else than normalized standard deviations. You can calculate them as PoV <- pca$sdev^2/sum(pca$sdev^2)

12

Just:

summary(pc)$importance[2,]
1
  • And the cumulative proportions are in summary(pc)$importance[3,] Jun 9, 2021 at 7:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.