vegandevs / vegan

R package for community ecologists: popular ordination methods, ecological null models & diversity analysis
https://vegandevs.github.io/vegan/
GNU General Public License v2.0
457 stars 98 forks source link

Function 'nullmodel' does not recognize most methods anymore #618

Closed fmassol closed 8 months ago

fmassol commented 9 months ago

Hi,

it seems like the current version (2.6-4) of nullmodel does not accept a lot of methods. Notably, it's now difficult to introduce objects made with commsim. Here is the call to nullmodel to see what is inside the function:

function (web, N = 1000, method = "r2d", ...) 
{
    methods <- c("r2dtable", "swap.web", "vaznull", "shuffle.web", 
        "mgen")
    if (is.numeric(method)) {
        m <- method
    }
    else {
        m <- pmatch(method, methods)
    }
    if (is.na(m)) 
        stop("Abbreviated name does not uniquely identify method.")
    if (m == 1) {
        if (length(unique(web)) < 3) 
            warning("This seems to be a binary web. Only methods shuffle.web and mgen should be used!\n  I proceeded nonetheless. Read the note in the help file!")
        rs <- rowSums(web)
        cs <- colSums(web)
        out <- r2dtable(N, r = rs, c = cs)
    }
    if (m == 2) {
        if (length(unique(web)) < 3) 
            warning("This seems to be a binary web. Only methods shuffle.web and mgen should be used!\n  I proceeded nonetheless. Read the note in the help file!")
        out <- swap.web(N, web, ...)
    }
    if (m == 3) {
        if (length(unique(web)) < 3) {
            warning("This seems to be a binary web. Only methods shuffle.web and mgen should be used!\n  I proceeded nonetheless. Read the note in the help file!")
        }
        out <- vaznull(N, web)
    }
    if (m == 4) {
        if (any(web > 1)) 
            out <- shuffle.web(web, N, ...)
        if (all(web < 2)) {
            out <- unname(simulate(vegan::nullmodel(web, method = "quasiswap"), 
                nsim = N, ...))
            out <- lapply(seq_len(N), function(i) out[, , i])
        }
    }
    if (m == 5) {
        out <- replicate(n = N, unname(mgen(web, autotransform = "equiprobable")), 
            simplify = FALSE)
    }
    if (!(m %in% 1:5)) 
        stop("Please choose a valid method.")
    return(out)
}

Old scripts I have that worked fine with former versions of vegan now have difficulties running since nullmodel sees almost every other method as r2dtable. Would it be possible to put back the old version of the function nullmodel? Thanks in advance.

François

jarioksa commented 9 months ago

Dear François,

I think you are confusing vegan::nullmodel with some other function from some other packages. Models "swap.web", "vaznull", "shuffle.web", and "mgen" have never been in vegan, and your function should have never worked in vegan. Moreover, the only change in vegan::nullmodel since its release is wording in one error message. I know that the bipartite package has similar functions as vegan, although I don't know it so well that I could say that those nullmodels are in that package.

There are more radical changes in vegan::commsim function, but your example does not show any application of that function. Can you provide a script that worked earlier in vegan (with information on the vegan version where it worked) and fails now so that we can verify the problem and and find where and when we possibly broke the function.