Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 914
Neeraj Bhatnagar Avatar asked Mar 14 '15 01:03

Neeraj Bhatnagar


People also ask

How do you calculate the proportion of variance in R?

In simple regression, the proportion of variance explained is equal to r2; in multiple regression, it is equal to R2. where N is the total number of observations and p is the number of predictor variables.

What is proportion of variance?

“Proportion of variance” is a generic term to mean a part of variance as a whole. For example, the total variance in any system is 100%, but there might be many different causes for the total variance — each of which have their own proportion associated with them.

What is the proportion of variance explained by the second principal component?

The Proportion of Variance Explained The first principal component in our example therefore explains 62% of the variability, and the second principal component explains 25%. Together, the first two principal components explain 87% of the variability.

How do you calculate variation in PCA?

The total variance is the sum of variances of all individual principal components. The fraction of variance explained by a principal component is the ratio between the variance of that principal component and the total variance. For several principal components, add up their variances and divide by the total variance.


2 Answers

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

like image 81
Marat Talipov Avatar answered Oct 19 '22 16:10

Marat Talipov


Just:

summary(pc)$importance[2,]
like image 39
Neggor Avatar answered Oct 19 '22 16:10

Neggor