gpt4 book ai didi

r - R 中 NMDS 解释的累积方差

转载 作者:行者123 更新时间:2023-12-05 00:48:40 26 4
gpt4 key购买 nike

有没有办法从具有函数 metaMDS 的 NMDS 对象确定解释的累积方差(度量拟合或 R^2m)?该对象返回压力、分数、分数的值,但我没有看到差异。该函数来自 vegan 包并执行非度量多维缩放。

metaMDS(comm, distance = "bray", k = 2, try = 20, trymax = 20, 
engine = c("monoMDS", "isoMDS"), autotransform =TRUE,
noshare = (engine == "isoMDS"), wascores = TRUE, expand = TRUE,
trace = 1, plot = FALSE, previous.best, ...)

我读到 R^2 是 1-总压力?

感谢任何建议。

最佳答案

与其他轴相比,nMDS 中没有与每个轴相关的方差百分比
主成分方法,如 PCA、CA、PCoA(= MDS)。

我引用 Legendre & Legendre 2012 :

Contrary to PCA, PCoA, or CA, which are eigenvector-based methods, nMDS calculations do not maximize the variability associated with individual axes of the ordination



NMDS 的目标是在几个维度中保存和表示观察的顺序
而其他方法的目标更多的是保持观察之间的确切距离,
并找到最大化解释方差的原始轴的组合。

您可以使用 2 维检查和可视化表示的质量
“Shepard”图,表示与排序的二维中的距离
k维空间中的原始距离。
这是一个示例,用于比较 a 的 2 维中的表示质量
nMDS 和基于 Bray-Curtis 距离的 MDS (PCoA)。

library(vegan)
data(dune)

nMDS <- metaMDS(dune, distance = "bray", k = 2)
MDS <- cmdscale(vegdist(dune, method = "bray"), k = 2, eig = T, add = T )

MDS 轴解释的方差百分比

round(MDS$eig*100/sum(MDS$eig),1)
#> [1] 30.3 18.7 9.5 8.0 6.6 5.5 4.3 3.0 2.7 2.4 2.2 1.7 1.6 1.5
#> [15] 0.8 0.6 0.4 0.1 0.0 0.0

谢泼德图

# x11(width = 18/2.54, height = 9/2.54)

par(mfrow = c(1,2), mar = c(3.5,3.5,3,1), mgp = c(2, 0.6, 0), cex = 0.8, las = 1)
spear <- round(cor(vegdist(dune, method = "bray"), dist(nMDS$points), method = "spearman"),3)
plot(vegdist(dune, method = "bray"), dist(nMDS$points), main = "Shepard diagram of nMDS",
xlab = "True Bray-Curtis distance", ylab = "Distance in the reduced space")
mtext(line = 0.1, text = paste0("Spearman correlation = ", spear), cex = 0.7)

spear <- round(cor(vegdist(dune, method = "bray"), dist(MDS$points), method = "spearman"),3)
plot(vegdist(dune, method = "bray"), dist(MDS$points), main = "Shepard diagram of MDS",
xlab = "True Bray-Curtis distance", ylab = "Distance in the reduced space")
mtext(line = 0.1, text = paste0("Spearman correlation = ", spear), cex = 0.7)



要确定您需要多少维度,您可以将应力绘制为
维数。请注意,与传统的碎石图相比,每个条形图
不代表与每个轴相关的方差,而是代表总应力(一个函数
d 和 d_hat 之间的平方差)的所有维度。例如,“3Dim”栏
表示 3 维解的应力,而不是与第 3 轴相关的应力...
这里对大于 2 维的维度表示的改进很低。

n = 10
stress <- vector(length = n)
for (i in 1:n) {
stress[i] <- metaMDS(dune, distance = "bray", k = i)$stress
}
names(stress) <- paste0(1:n, "Dim")
# x11(width = 10/2.54, height = 7/2.54)
par(mar = c(3.5,3.5,1,1), mgp = c(2, 0.6, 0), cex = 0.8, las = 2)
barplot(stress, ylab = "stress")



创建于 2018-03-11 由 reprex package (v0.2.0)。

关于r - R 中 NMDS 解释的累积方差,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49223740/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com