biometry / bipartite

repository for the bipartite R-package for network analysis
36 stars 17 forks source link

bug in second.extinct / extinction? #6

Closed nefff1 closed 4 years ago

nefff1 commented 4 years ago

Dear Carsten,

There seems to be a problem in the second.extinct function (or in the extinction function). When you run it with the "abundance" method on "lower", there are special cases for which only one column will be left in m2 (after i iterations in the repeat loop), which will cause problems in the extinction function (L40). Example:

web <- matrix(c(3, 2, 3, 0, 0, 0, 0, 1, 0, 0, 0, 1), ncol = 3) second.extinct(web, participant = "lower", method = "abundance")

From my understanding, the problem could be solved by changing line 39 in extinction to

web <- web[sample(1:nrow(web)), sample(1:ncol(web)), drop = FALSE]

or by changing line 38 in second.extinct to

 if (any(dim(m2) == 1)) break;

Seems to yield the same result. Or do I miss something?

Best, Felix

https://github.com/biometry/bipartite/blob/f016fbd6a5d9d722273ed2878036b1445b2f346c/bipartite/R/extinction.R#L39

cdormann commented 4 years ago

Correct! I adopted your proposal for the extinction function (rather than second.extinct). I wonder why I so far didn't run into this problem! Many thanks for reporting and fixing. I will commit the fix immediately.