【问题标题】:Error in indval (labdsv) in R - "All species must occur in at least one plot"R中的indval(labdsv)错误-“所有物种必须至少出现在一个地块中”
【发布时间】:2021-11-18 03:20:59
【问题描述】:

我在名为“data”的数据框上运行了 R 中 labdsv 包中的以下指标物种分析 (indval) 代码,其中物种丰度是列,位点是行,如下所示:

     Site    Species X  Species Y  Species Z etc
     1       10         3          5
     2       5          15         220
     3       0          1          0
     4       21         100        3

在一个单独的文件中是每个站点的相应组数据,即组 1 或组 2(称为此 spe.grp),如下所示:

    Groups 
    1
    2
    1
    2
   

我删除了分类变量,因此 spe.only 只有物种数据

   spe.only <- data[,2:1521]

然后我删除了任何样本中都不存在的物种

   spe.only[, (!apply(spe.only==0,2,all))] 

然后我根据组 (1) 或 (2) 运行指标物种

  (iva <- indval(spe.only, spe.grp$Groups))

但我明白了

"indval.default(spe.only, spe.grp$Status) 中的错误:所有物种 必须至少出现在一个情节中”

如何解决此错误以便我可以正确运行 indval?

【问题讨论】:

    标签: r statistics cluster-analysis analysis indicator


    【解决方案1】:

    步骤

    spe.only[, (!apply(spe.only==0,2,all))] 
    

    未分配回原始对象,即如果我们不将其分配回它,则上述步骤的输出仅在控制台上打印,不会更新原始对象

    spe.only <- spe.only[, (!apply(spe.only==0,2,all))] 
    

    现在做indval

    > library(labdsv)
    > indval(spe.only, spe.grp$Groups)
    $relfrq
               1 2
    SpeciesX 0.5 1
    SpeciesY 1.0 1
    SpeciesZ 0.5 1
    
    $relabu
                      1         2
    SpeciesX 0.27777778 0.7222222
    SpeciesY 0.03361345 0.9663866
    SpeciesZ 0.02192982 0.9780702
    
    $indval
                      1         2
    SpeciesX 0.13888889 0.7222222
    SpeciesY 0.03361345 0.9663866
    SpeciesZ 0.01096491 0.9780702
    
    $maxcls
    SpeciesX SpeciesY SpeciesZ 
           2        2        2 
    
    $indcls
     SpeciesX  SpeciesY  SpeciesZ 
    0.7222222 0.9663866 0.9780702 
    
    $pval
    SpeciesX SpeciesY SpeciesZ 
       0.678    0.319    0.671 
    

    错误可在原始“spe.only”对象上重现

    > indval(spe.only, spe.grp$Groups)
    Error in indval.default(spe.only, spe.grp$Groups) : 
      All species must occur in at least one plot
    

    数据

     
    spe.only <- structure(list(SpeciesX = c(10L, 5L, 0L, 21L), SpeciesY = c(3L, 
    15L, 1L, 100L), SpeciesZ = c(5L, 220L, 0L, 3L), SpeciesD = c(0, 
    0, 0, 0)), row.names = c(NA, -4L), class = "data.frame")
    
    spe.grp <- structure(list(Groups = c(1, 2, 1, 2)), 
    class = "data.frame", row.names = c(NA, 
    -4L))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-05
      • 2014-08-24
      • 1970-01-01
      • 1970-01-01
      • 2019-04-27
      • 1970-01-01
      • 2014-09-13
      • 2018-12-27
      相关资源
      最近更新 更多