# Calculating PCA variance explained [duplicate]

I've read through this explanation here regarding calculating the variance explained from PCA output. I think I got it right but might be off in my interpretation of R output.

In the example below, I would like to calculate the percentage of variance explained by the first principal component of the USArrests dataset.

pca <- prcomp(USArrests, scale = TRUE)
eigs <- pca$sdev^2 eigs / sum(eigs)  0.6200604  I assumed that R uses sdev as the square root of the eigen values. So I square it and divide the first value by the total. Is this correct? ## marked as duplicate by hxd1011, ttnphns, gung♦ r StackExchange.ready(function() { if (StackExchange.options.isMobile) return;$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() { var $hover =$(this).addClass('hover-bound'), $msg =$hover.siblings('.dupe-hammer-message'); $hover.hover( function() {$hover.showInfoMessage('', { messageElement: \$msg.clone().show(), transient: false, position: { my: 'bottom left', at: 'top center', offsetTop: -7 }, dismissable: false, relativeToBody: true }); }, function() { StackExchange.helpers.removeMessages(); } ); }); }); Jan 4 '17 at 20:31

Yes, that's correct. summary.prcomp brings that information as well:

summary(pca)
#Importance of components:
#                          PC1    PC2     PC3     PC4
#Standard deviation     1.5749 0.9949 0.59713 0.41645
#Proportion of Variance 0.6201 0.2474 0.08914 0.04336
#Cumulative Proportion  0.6201 0.8675 0.95664 1.00000


Compare to

rbind(
SD = sqrt(eigs),
Proportion = eigs/sum(eigs),
Cumulative = cumsum(eigs)/sum(eigs))

#                [,1]      [,2]      [,3]       [,4]
#SD         1.5748783 0.9948694 0.5971291 0.41644938
#Proportion 0.6200604 0.2474413 0.0891408 0.04335752
#Cumulative 0.6200604 0.8675017 0.9566425 1.00000000