主成分分析-如何获取每个参数对Prin.Comp.的贡献(%)? [英] Principal Components Analysis - how to get the contribution (%) of each parameter to a Prin.Comp.?

查看:330
本文介绍了主成分分析-如何获取每个参数对Prin.Comp.的贡献(%)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道测量/参数在多大程度上有助于计算出的主成分之一.

I want to know to what degree a measurement/parameter contributes to one of the calculated principal components.

真实描述:

  1. 我对一个物种的地理分布有五个气候参数
  2. 我用这五个参数执行了一次PCA
  3. PC1与PC2的关系图显示了一个有趣的模式

问题:如何获得每个PC的(每个参数)贡献百分比?

Question: How do I get the percentage of contribution (of each parameter) to each PC?

我期望的是:PC1由参数1的30%,参数2的50%,参数3的20%,参数4的0%和参数5的0%组成. PC2已组成...

What I expect: PC1 is composed to 30% of parameter1, to 50% of parameter2, to 20% of parameter3, 0% of parameter4 and 0% of parameter5. PC2 is composed...

具有5个虚拟参数的示例:

An example with 5 dummy-parameters:

a <- rnorm(10, 50, 20)
b <- seq(10, 100, 10)
c <- seq(88, 10, -8)
d <- rep(seq(3, 16, 3), 2)
e <- rnorm(10, 61, 27)

my_table <- data.frame(a, b, c, d, e)

pca <- princomp(my_table, cor=T)

biplot(pca) # same: plot(pca$scores[,1], pca$scores[,2])

pca
summary(pca)

我的信息隐藏在哪里?

推荐答案

您想要返回对象的$loadings组件:

You want the $loadings component of the returned object:

R> class(pca$loadings)
[1] "loadings"
R> pca$loadings

Loadings:
  Comp.1 Comp.2 Comp.3 Comp.4 Comp.5
a -0.198  0.713        -0.671       
b  0.600         0.334 -0.170  0.707
c -0.600        -0.334  0.170  0.707
d  0.439        -0.880 -0.180       
e  0.221  0.701         0.678       

               Comp.1 Comp.2 Comp.3 Comp.4 Comp.5
SS loadings       1.0    1.0    1.0    1.0    1.0
Proportion Var    0.2    0.2    0.2    0.2    0.2
Cumulative Var    0.2    0.4    0.6    0.8    1.0

请注意,这有一种特殊的print()方法,可以抑制小负载的 printing .

Note that this has a special print() method which suppresses printing of small loadings.

如果您希望这是一个相对的贡献,则将每列的负荷求和,并以列(负荷)总和的一部分表示每个负荷,请小心使用绝对值来考虑负负荷.

If you want this as a relative contribution then sum up the loadings per column and express each loading as a proportion of the column (loading) sum, taking care to use the absolute values to account for negative loadings.

R> load <- with(pca, unclass(loadings))
R> load
      Comp.1       Comp.2      Comp.3     Comp.4        Comp.5
a -0.1980087  0.712680378  0.04606100 -0.6713848  0.000000e+00
b  0.5997346 -0.014945831  0.33353047 -0.1698602  7.071068e-01
c -0.5997346  0.014945831 -0.33353047  0.1698602  7.071068e-01
d  0.4389388  0.009625746 -0.88032515 -0.1796321  5.273559e-16
e  0.2208215  0.701104321 -0.02051507  0.6776944 -1.110223e-16

然后,最后一步对每个主成分产生比例贡献

This final step then yields the proportional contribution to the each principal component

R> aload <- abs(load) ## save absolute values
R> sweep(aload, 2, colSums(aload), "/")
      Comp.1      Comp.2     Comp.3     Comp.4       Comp.5
a 0.09624979 0.490386943 0.02853908 0.35933068 0.000000e+00
b 0.29152414 0.010284050 0.20665322 0.09091055 5.000000e-01
c 0.29152414 0.010284050 0.20665322 0.09091055 5.000000e-01
d 0.21336314 0.006623362 0.54544349 0.09614059 3.728970e-16
e 0.10733880 0.482421595 0.01271100 0.36270762 7.850462e-17

R> colSums(sweep(aload, 2, colSums(aload), "/"))
Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 
     1      1      1      1      1


如果使用首选的prcomp(),则相关的载荷在$rotation组件中:


If using the preferred prcomp() then the relevant loadings are in the $rotation component:

R> pca2 <- prcomp(my_table, scale = TRUE)
R> pca2$rotation
         PC1          PC2         PC3        PC4           PC5
a -0.1980087  0.712680378 -0.04606100 -0.6713848  0.000000e+00
b  0.5997346 -0.014945831 -0.33353047 -0.1698602 -7.071068e-01
c -0.5997346  0.014945831  0.33353047  0.1698602 -7.071068e-01
d  0.4389388  0.009625746  0.88032515 -0.1796321 -3.386180e-15
e  0.2208215  0.701104321  0.02051507  0.6776944  5.551115e-17

现在的相关咒语是:

R> aload <- abs(pca2$rotation)
R> sweep(aload, 2, colSums(aload), "/")
         PC1         PC2        PC3        PC4          PC5
a 0.09624979 0.490386943 0.02853908 0.35933068 0.000000e+00
b 0.29152414 0.010284050 0.20665322 0.09091055 5.000000e-01
c 0.29152414 0.010284050 0.20665322 0.09091055 5.000000e-01
d 0.21336314 0.006623362 0.54544349 0.09614059 2.394391e-15
e 0.10733880 0.482421595 0.01271100 0.36270762 3.925231e-17

这篇关于主成分分析-如何获取每个参数对Prin.Comp.的贡献(%)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆