计算 PCA 方差解释

机器算法验证 r 主成分分析
2022-01-23 09:14:30

我在这里通读了关于计算 PCA 输出解释的方差的解释。我认为我做对了,但可能在我对 R 输出的解释中有所偏差。

在下面的示例中,我想计算由 USArrests 数据集的第一个主成分解释的方差百分比。

pca <- prcomp(USArrests, scale = TRUE)
eigs <- pca$sdev^2
eigs[1] / sum(eigs)
[1] 0.6200604

我假设 Rsdev用作特征值的平方根。所以我将它平方并将第一个值除以总数。它是否正确?

1个回答

对,那是正确的。summary.prcomp也带来了这些信息:

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

相比于

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