rinext

Error message (Incorrect number of subscripts) when trying to use iNext()


I'm having some issues running iNEXT with this new dataset

I'm trying to get species estimates as well as sample-coverage based accumulation curve from camera trapping efforts. But am having issues with loading the dataset into iNEXT.

I've followed the format of the incidence_raw data example given in the iNEXT manual (ciliates) but to no avail.

Here's the data and how I tried to convert the data into a species incidence matrix (row = species; every column = sampling unit):

#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")

At this point, I'll run into this error:

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

I'm almost positive it's something wrong with my formatting but I'm just not sure where the problem lies.

Any help would be greatly appreciated! Thank you


Solution

  • I am not familiar with iNEXT. However, I could see that when datatype="incidence_raw", x should be a list. I converted the ct.df1 to list and tried. Here's the output.

    > 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.