Neeraj Bhatnagar
Neeraj Bhatnagar

Reputation: 351

How to get "proportion of variance" vector from princomp in R

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.

Upvotes: 20

Views: 20945

Answers (2)

Neggor
Neggor

Reputation: 151

Just:

summary(pc)$importance[2,]

Upvotes: 13

Marat Talipov
Marat Talipov

Reputation: 13314

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

Upvotes: 26

Related Questions