在R中运行metaMDS时需要TRUE/FALSE的地方缺少值时出错

3gtaxfhh  于 2023-05-11  发布在  其他
关注(0)|答案(1)|浏览(362)

我试图使用Bray-Curtis相异度使用来自包 vegan 的metaMDS进行NMDS测试。请参见代码:
pc = read.csv("nmds.csv", header = TRUE) com = pc[,5:ncol(pc)] ###其中5是我的信息开始的列m_com = as.matrix(com) set.seed(123) nmds = metaMDS(m_com, distance = "bray")
这就是我的数据看起来的样子:data
然而,当我执行最后一步(nmds = metaMDS(m_com,distance =“bray”))时,我得到以下错误:Error in if (max(dis) > maxdis + sqrt(.Machine$double.eps)) { : missing value where TRUE/FALSE needed In addition: Warning messages: 1: In distfun(comm, method = distance, ...) : you have empty rows: their dissimilarities may be meaningless in method “bray” 2: In distfun(comm, method = distance, ...) : missing values in results
我已经使用相同的代码多年,从来没有遇到过这个问题。我在一些线程中看到,这是因为我的数据中有零,但我以前对包含零的数据做过这样的处理。
我在一组包含许多零的旧数据上使用了相同的代码(但数据集要小得多),它能够计算它并给予解决方案(见下面的结果)。

Wisconsin double standardization Run 0 stress 0.1232691  Run 1 stress
0.1380158  Run 2 stress 0.1232695  ... Procrustes: rmse 0.0002867434  max resid 0.002609401  ... Similar to previous best Run 3 stress
0.1232695  ... Procrustes: rmse 0.0002975044  max resid 0.002720978  ... Similar to previous best Run 4 stress 0.2390168  Run 5 stress
0.1232696  ... Procrustes: rmse 0.0002939605  max resid 0.002594778  ... Similar to previous best Run 6 stress 0.1502755  Run 7 stress
0.1232693  ... Procrustes: rmse 0.0002335296  max resid 0.002429394  ... Similar to previous best Run 8 stress 0.1232691  ... New best solution ... Procrustes: rmse 2.084762e-06  max resid 1.672081e-05  ... Similar to previous best Run 9 stress 0.1232695  ... Procrustes: rmse 0.0002904649  max resid 0.002643373  ... Similar to previous best Run 10 stress 0.1380158  Run 11 stress 0.1232695  ... Procrustes: rmse
0.0002872963  max resid 0.002608208  ... Similar to previous best Run 12 stress 0.1232695  ... Procrustes: rmse 0.0002861628  max resid
0.002597991  ... Similar to previous best Run 13 stress 0.1232696  ... Procrustes: rmse 0.000292253  max resid 0.002573828  ... Similar to previous best Run 14 stress 0.2587088  Run 15 stress 0.1232695  ... Procrustes: rmse 0.0002856807  max resid 0.002589665  ... Similar to previous best Run 16 stress 0.1232695  ... Procrustes: rmse
0.0002866945  max resid 0.002595448  ... Similar to previous best Run 17 stress 0.1232695  ... Procrustes: rmse 0.0002864601  max resid
0.002605703  ... Similar to previous best Run 18 stress 0.1232695  ... Procrustes: rmse 0.000295793  max resid 0.002704928  ... Similar to previous best Run 19 stress 0.1232695  ... Procrustes: rmse
0.0002905679  max resid 0.002632124  ... Similar to previous best Run 20 stress 0.1232695  ... Procrustes: rmse 0.0002865427  max resid
0.002612774  ... Similar to previous best
*** Best solution repeated 11 times
> nmds

Call: metaMDS(comm = m_com, distance = "bray") 

global Multidimensional Scaling using monoMDS

Data:     wisconsin(m_com)  Distance: bray 

Dimensions: 2  Stress:     0.1232691  Stress type 1, weak ties 
Best solution was repeated 11 times in 20 tries 
The best solution was from try 8 (random start) 
Scaling: centring, PC rotation, halfchange scaling  
Species: expanded scores based on ‘wisconsin(m_com)’

为什么它不能在我的新数据集上工作?我已经验证了所有框都包含一个值,即使它是零。我很困惑,为什么它只在一个数据集上工作,而不是另一个。会不会是因为文件的大小?任何帮助都很感激。谢谢大家。

hmmo2u0o

hmmo2u0o1#

我假设你的原始信息的这些行给予了你答案:

Warning messages:
1: In distfun(comm, method = distance, ...) : you have empty rows: their dissimilarities may be meaningless in method “bray” 
2: In distfun(comm, method = distance, ...) : missing values in results

您的新数据具有空行(不存在物种),并且无法计算它们的Bray-Curtis相异度,但它们被合并为缺失距离。当你计算相异度时,这是一个警告,但当你试图在metaMDS中使用它们时,这是一个错误。
原则上,我们可以处理metaMDS中的缺失值,但我们还没有实现用户界面。但是,在这种情况下,我们所能做的就是删除空行。我建议你也这么做。

tot <- rowSums(m_com)
m_com <- m_com[tot > 0, ]

相关问题