griffithdan / cooccur

Probabilistic Species Co-occurrence Analysis in R
3 stars 6 forks source link

Is abundance data converted to presence-absence? #8

Open minna-miha opened 2 years ago

minna-miha commented 2 years ago

In the cooccur paper, it says "In the probabilistic co-occurrence model, community data is used in presence-absence form and will be converted to occupancies if abundances, cover-classes, or counts (etc.) are supplied (anything not 0 is a presence and coded as “1”)"

I take this to mean that if you input a table with abundance data, it will treat anything that isn't 0 as a 1. However, the output differs dramatically if I use an unedited table with abundance data versus adding an extra line in R to convert all non-0 values to 1.

Looking for clarification on the above, and wondering if the discrepancy is a fault of my own as opposed to a difference in how the program is interpreting the input data. Thanks

ErikKusch commented 2 years ago

Hiya, not the package maintainer here, but I tested this out of curiosity since I am using cooccur for some of my work myself. I could not reproduce this issue. I ran the following:

## presence/absence analysis
data <- t(data.frame(
  sp1 = c(1,1,1,1,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0),
  sp2 = c(1,0,1,1,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0),
  sp3 = c(0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,1,1,1,0),
  sp4 = c(0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,1,1,1,1,1)))
colnames(data) <- paste0("site", 1:20)
occur1 <- cooccur(data, type = "spp_site", thresh = TRUE, spp_names = TRUE, prob = "comb")

## abundance analysis
data <- t(data.frame(
  sp1 = c(7,1,8,1,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0),
  sp2 = c(1,0,1,1,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0),
  sp3 = c(0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,1,100,1,0),
  sp4 = c(0,0,0,0,0,0,0,0,0,0,10,1,1,0,0,1,23,1,1,1)))
colnames(data) <- paste0("site", 1:20)
occur2 <- cooccur(data, type = "spp_site", thresh = TRUE, spp_names = TRUE, prob = "comb")

## test for outputs being the same
all.equal(occur1, occur2)

This returns TRUE which suggests to me that abundance data is correctly transformed into presence/absence data. Can you supply the data and code you see discrepancies in the outputs with?

Note: I am not using the CRAN version of cooccur but a custom one in which I have fixed a bug with the current distribution of cooccur (pull request #6). See if installing from my repo with devtools::install_github("ErikKusch/cooccur") fixes the discrepancies.