griffithdan / cooccur

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

"spp_site" vs. "site_spp" bug? #1

Open abarner opened 7 years ago

abarner commented 7 years ago

There is a problem in using "site_spp" matrices with the cooccur() function that I can't quite figure out. In my understanding of the cooccur function, the data matrix can be either a species by site or a site by species data frame, you just need to specify which in the "type=" argument. However, this isn't the case. First, if you transpose the example data with the package,

data(finches)
cooccur(mat=finches, type="spp_site", thresh=TRUE, spp_names=TRUE)
finches_t <- data.frame(t(finches))
cooccur(mat=finches_t, type="site_spp", thresh=TRUE, spp_names=TRUE)

This is the error I get using my data, and the same error can be reproduced using a random matrix:

set.seed(1)
r <- 125 # sites
c <- 100 # species
mat <- matrix(0, r, c)
mat <- data.frame(apply(mat, c(1,2), function(x) sample(c(0,1),1)))
cooccur(mat=mat, type="site_spp", thresh=TRUE, spp_names=FALSE)
cooccur(mat=t(mat), type="spp_site", thresh=TRUE, spp_names=FALSE)
griffithdan commented 7 years ago

Thank you. This is unfortunately an issue that I introduced in an update and have not had a chance to fix. You should be able to get by using "spp_site" and I will do my best to get around to fixing this :)

abarner commented 7 years ago

Great, thanks! It's easy enough to work around for now by just transposing the matrix.

ErikKusch commented 3 years ago

I ran into this issue, too and spent way too much time figuring out what caused this behaviour, identified the root cause (a mismatch in object naming in the function cooccur), and resolved it. See pull request #6 for the resolution to this issue.

menarest commented 3 years ago

great @ErikKusch !