首页 > 解决方案 > 尝试使用 iNext() 时出现错误消息(下标数不正确)

问题描述

我在使用这个新数据集运行 iNEXT 时遇到了一些问题

我试图从相机捕获工作中获得物种估计以及基于样本覆盖的累积曲线。但是在将数据集加载到 iNEXT 时遇到问题。

我遵循了 iNEXT 手册(纤毛虫)中给出的发病率原始数据示例的格式,但无济于事。

这是数据以及我如何尝试将数据转换为物种关联矩阵(行 = 物种;每列 = 采样单位):

#load packages

library(iNEXT)

#data here
ct <-structure(list(Station = structure(c(3L, 3L, 3L, 3L, 3L, 3L, 
3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("CT01", 
"CT02", "CT03"), class = "factor"), Date = structure(c(10L, 11L, 
12L, 12L, 13L, 14L, 16L, 16L, 17L, 17L, 1L, 1L, 15L, 15L, 15L, 
15L, 15L, 18L, 19L, 2L), .Label = c("1/11/19", "13/11/19", "14/11/19", 
"15/11/19", "17/11/19", "18/11/19", "22/11/19", "23/11/19", "25/10/19", 
"26/10/19", "27/10/10", "27/10/19", "28/10/19", "29/10/19", "3/11/19", 
"30/10/19", "31/10/19", "6/11/19", "7/11/19"), class = "factor"), 
    Time = structure(c(23L, 22L, 25L, 28L, 24L, 15L, 31L, 20L, 
    18L, 19L, 2L, 8L, 3L, 7L, 6L, 16L, 17L, 21L, 9L, 14L), .Label = c("0:34:24", 
    "0:43:46", "13:07:10", "16:49:34", "17:26:28", "19:06:56", 
    "19:11:56", "19:13:28", "19:34:58", "19:53:00", "19:56:42", 
    "2:33:36", "2:34:40", "20:21:42", "20:27:00", "20:31:42", 
    "20:32:08", "22:25:22", "23:19:00", "23:50:24", "23:50:44", 
    "3:19:00", "4:26:00", "4:28:00", "4:46:00", "4:56:04", "5:13:32", 
    "5:18:00", "5:19:00", "5:56:00", "6:31:00"), class = "factor"), 
    DateTimeOriginal = structure(c(18L, 18L, 18L, 18L, 19L, 20L, 
    20L, 17L, 22L, 23L, 1L, 2L, 11L, 13L, 12L, 14L, 15L, 24L, 
    25L, 3L), .Label = c("1/11/19 0:43", "1/11/19 19:13", "13/11/19 20:21", 
    "14/11/19 17:26", "15/11/19 19:56", "17/11/19 0:34", "18/11/19 4:56", 
    "22/11/19 5:13", "23/11/19 2:33", "23/11/19 2:34", "3/11/19 13:07", 
    "3/11/19 19:06", "3/11/19 19:11", "3/11/19 20:31", "3/11/19 20:32", 
    "30/10/19 23:22", "30/10/19 23:50", "30/10/19 23:58", "30/10/19 23:59", 
    "31/10/19 0:00", "31/10/19 16:49", "31/10/19 22:25", "31/10/19 23:19", 
    "6/11/19 23:50", "7/11/19 19:34"), class = "factor"), Scientific_name_1 = structure(c(2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L), .Label = c("Callosciurus_notatus", "Rattus_tiomanicus"
    ), class = "factor"), Abundance_1 = c(2L, 1L, 4L, 3L, 4L, 
    3L, 1L, 2L, 1L, 3L, 2L, 2L, 2L, 3L, 2L, 3L, 3L, 1L, 1L, 4L
    )), row.names = c(NA, 20L), class = "data.frame")


ct$trapnights <- paste(ct$Station, ct$Date, sep="_") 

#create contingency table
ct.matrix <- xtabs(Abundance_1~Scientific_name_1+trapnights, data=ct)


#create species incidence matrix
ct.df1 <- ifelse(ct.matrix>0,1,0) 


#run iNEXT
ct.inext <- iNEXT(ct.df2, datatype="incidence_raw")

在这一点上,我会遇到这个错误:

Error in arr[1, , ] <- t(as.matrix(ChaoSpecies(x, datatype, conf))) : 
  incorrect number of subscripts

我几乎可以肯定我的格式有问题,但我不确定问题出在哪里。

任何帮助将不胜感激!谢谢

标签: rinext

解决方案


我不熟悉 iNEXT。但是,我可以看到当 datatype="incidence_raw" 时,x 应该是一个列表。我将 ct.df1 转换为列表并尝试过。这是输出。

> ct.df1 <- ifelse(ct.matrix>0,1,0) 
> ct.df2<- list(ct.df1)
> ct.inext <- iNEXT(ct.df2, datatype="incidence_raw")
> ct.inext
Compare 1 assemblages with Hill number order q = .
$class: iNEXT

$DataInfo: basic data information
    site  T  U S.obs SC Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 Q10
1 site.1 14 15     2  1  1  0  0  0  0  0  0  0  0   0

$iNextEst: diversity estimates with rarefied and extrapolated samples.
[[1]]
    t       method order    qD qD.LCL qD.UCL    SC SC.LCL SC.UCL
1   1 interpolated     0 1.071  0.922  1.221 0.933  0.828  1.000
2   1 interpolated     0 1.071  0.922  1.221 0.933  0.828  1.000
10  7 interpolated     0 1.500  0.839  2.161 0.933  0.878  0.989
11  7 interpolated     0 1.500  0.839  2.161 0.933  0.878  0.989
20 14     observed     0 2.000  1.111  2.889 1.000  1.000  1.000
30 21 extrapolated     0 2.000  1.111  2.889 1.000  1.000  1.000
31 21 extrapolated     0 2.000  1.111  2.889 1.000  1.000  1.000
40 28 extrapolated     0 2.000  1.111  2.889 1.000  1.000  1.000


$AsyEst: asymptotic diversity estimates along with related statistics.
  Site         Diversity Observed Estimator  s.e.   LCL   UCL
1    A  Species richness    2.000     2.000 0.472 2.000 3.585
2    A Shannon diversity    1.278     1.324 0.218 1.278 1.751
3    A Simpson diversity    1.142     1.143 0.129 1.142 1.396

NOTE: Only show five estimates, call iNEXT.object$iNextEst. to show complete output.

推荐阅读