r - 如何计算素食 rda/cca 对象的物种贡献百分比?

标签 r pca vegan

我正在尝试重现该列(FactoMineR::PCA 中的“variable”,vegan::rda 中的“species”)contribution percentages to axes from the FactoMineR包装在 vegan 中。这些贡献被编码在 FactoMiner::PCA 对象中:

library(FactoMineR)
library(vegan)

data(dune)

fm <- FactoMineR::PCA(dune, scale.unit = FALSE, graph = FALSE)

head(round(sort(fm$var$contrib[,1], decreasing = TRUE), 3))
# Lolipere Agrostol Eleopalu Planlanc  Poaprat  Poatriv 
#  17.990   16.020   13.866    7.088    6.861    4.850 

通过查看 FactoMiner::PCA 的代码,我发现贡献的计算方法是轴坐标平方除以轴特征值再乘以 100%:

head(round(sort(100*fm$var$coord[,1]^2/fm$eig[1], decreasing = TRUE), 3))
# Lolipere Agrostol Eleopalu Planlanc  Poaprat  Poatriv 
#  17.990   16.020   13.866    7.088    6.861    4.850 

我无法使用 vegan::rda 对象复制上述计算:

vg <- rda(dune)

head(round(sort(100*scores(vg, choices = 1, display = "sp", 
scaling = 0)[,1]^2/vg$CA$eig[1], decreasing = TRUE), 3))
# Lolipere Agrostol Eleopalu Planlanc  Poaprat  Poatriv 
#   0.726    0.646    0.559    0.286    0.277    0.196

我显然做错了什么,差异可能是由于这两个包计算列坐标的方式不同,因为轴的特征值非常相似(与我的实际数据集相同),但坐标不是:

# vegan eigenvalue for axis 1
vg$CA$eig[1]
#     PC1 
# 24.79532 

# FactoMineR eigenvalue for axis 1
fm$eig[1]
# [1] 23.55555

# vegan column coordinates for axis 1
head(round(scores(vg, choices = 1, display = "sp", scaling = 0)[,1], 3))
# Achimill Agrostol Airaprae Alopgeni Anthodor Bellpere 
#  -0.176    0.400    0.007    0.155   -0.163   -0.097 

#FactoMineR, column coordinates for axis 1
head(round(fm$var$coord[,1], 3))
# Achimill Agrostol Airaprae Alopgeni Anthodor Bellpere 
#   0.854   -1.943   -0.033   -0.751    0.791    0.472 

# Sum of column coordinates for vegan axis 1 to illustrate the difference
sum(scores(vg, choices = 1, display = "sp", scaling = 0)[,1])
# [1] -0.796912

# Sum of column coordinates for FactoMineR axis 1 to illustrate the difference
sum(fm$var$coord[,1])
# [1] 3.867738

如何使用 vegan rda 计算列/物种对排序轴的贡献百分比 对象?

最佳答案

vegan 中的未缩放分数在(正常)意义上未缩放,即它们的平方和为 1 -- 独立于特征值:

> colSums(scores(vg, choices=1:4,dis="sp", scaling=0)^2)
  PC1 PC2 PC3 PC4 
    1   1   1   1 

我认为这是有记录的。如果您想将这些平方项称为贡献,那对我来说没问题。 cca 也是如此,但是您需要研究加权平方和。此外,站点 (dis = "si") 的未缩放 分数将具有相同的单位平方和:这就是未缩放的概念。如果您缩放物种或地点,那么相同的关系将不再适用于另一组分数。通常,未缩放意味着分数是正交的,因此它们的叉积是单位矩阵(对角线或平方和 1 和非对角线元素 0)。对于 scaled 分数,这些平方和与特征值成正比(但阅读 vegan vignette on design decisions for constant scaling of of分数)。

vegan 函数 goodnessinertcomp 可能(也可能不会)为您提供您正在寻找的信息。

关于r - 如何计算素食 rda/cca 对象的物种贡献百分比?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50177409/

相关文章:

R Shiny : run code if req not satisfied (equivalent to "req else"? )

python - PCA:获取前 20 个最重要的维度

python - Python 中缺少值的 PCA

r - ordisurf 与 mgcv :gam model

r - 如何在 R(素食包)的 NMDS 图中绘制不同颜色的站点?

r - 如何在 R 中的稀疏矩阵中查找和命名连续的非零条目?

r - 在 print.tbl 中使用个人打印方法

使用 PCL 时私有(private)函数的 C++ 继承

r - 如何创建包含每行之间的平均绝对分数的距离矩阵?

r - 在 R 中倒数事件