Skip to content

ChaoSpecies error (Error in if (var_iChao2 > 0) { : missing value where TRUE/FALSE needed #3

@PeterSoroye

Description

@PeterSoroye

Hello Anne,

I'm attempting to run the ChaoSpecies function (method=incidence, k=10, conf=0.95) for about 360 quadrats (each in a different column) for which I have a variable number of sampling units and a possible 271 species (two example quadrats are included in the attached text file).
I have a script which goes through each quadrat (column), determines whether the proportion of singleton species is greater than 0.5 (in which case it would be inappropriate to resample), and then performs the ChaoSpecies function on the quadrat and extracts certain species richness estimates to a final table.

quads <- nrow(ebquads) #determine number of quadrats
ebuttresamp <- data.frame(1:quads, NA, NA, NA, NA) #create final table where estimates will go
colnames(ebuttresamp) <- c("obssprich", "ichao", "ichaoSE", "jk2", "jk2SE")

for (i in 2:quads) #loop through all quadrats 
{
  singletons <- sum(ebuttsamp3[,i] == 1) ##count number singletons
  totspobs <- sum(ebuttsamp3[,i] > 0) ##count totnumber sp (obs richness)
  singratio <- singletons/totspobs
  ebuttresamp[i,1] <- totspobs #add observed species richness to all quadrats
  if (singratio >= 0.5) {
    ebuttresamp[i,2:5] <- "NA"   #if ratio singletons to total is greater than 0.5, do not resample
  } else {
    resampstats <- ChaoSpecies(ebuttsamp3[,i], datatype= "incidence", k=10, conf=0.95)  #otherwise resample 
    ebuttresamp[i,2] <- resampstats$Species.Table$Estimate[4]  #extracting iChao2 and add to final table
    ebuttresamp[i,3] <- resampstats$Species.Table$s.e.[4]      #extracting iChao2 SE and add to final table
    ebuttresamp[i,4] <- resampstats$Species.Table$Estimate[8]  #extracting jacknife2 and add to final table
    ebuttresamp[i,5] <- resampstats$Species.Table$s.e.[8]      #extracting jacknife2 SE and add to final table
    } #end if/else
}  #end for

The script works fine for most quadrats (ex. it works fine for the first example quadrat, Q22), however when it gets to certain quadrats (ex. the second example quadrat, Q23), it stops the loop and returns the following error:

Error in if (var_iChao2 > 0) { : missing value where TRUE/FALSE needed

And the traceback function traces the error to

3: SpecInciiChao2(data, k, conf)
2: SpecInciOut(data, method, k, conf)
1: ChaoSpecies(ebuttsamp3[, i], datatype = "incidence", k = 10,
conf = 0.95) at #12

Like I mentioned, it's only an issue for certain, specific quadrats, and the problematic quadrats don't seem to be obviously different from others in terms of observed species richness, sampling units or proportion of singletons. That said my knowledge on exactly how the ChaoSpecies function works, and therefore it's limitations/requirements is not comprehensive, so I though I'd ask whether you know any reason that the ChaoSpecies function might be returning this error for some quadrats?

Thanks in advance, I'd really appreciate any help or insight into this problem that you could offer.

Sincerely,

-Peter
quad22and23.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions