R/toCoda.R

Defines functions `toCoda.oecosimu` `toCoda`

`toCoda` <-
    function(x) UseMethod("toCoda")

`toCoda.oecosimu` <-
    function(x)
{
    ## mcmc only for sequential methods
    if (!x$oecosimu$isSeq)
        stop("'toCoda' is only available for sequential null models")
    ## named variables
    rownames(x$oecosimu$simulated) <- names(x$oecosimu$z)
    chains <- attr(x$oecosimu$simulated, "chains")
    ## chains: will make each chain as an mcmc object and combine
    ## these to an mcmc.list
    if (!is.null(chains) && chains > 1) {
        x <- x$oecosimu$simulated
        nsim <- dim(x)[2]
        niter <- nsim / chains
        ## iterate over chains
        x <- lapply(1:chains, function(i) {
                        z <- x[, ((i-1) * niter + 1):(i * niter), drop = FALSE]
                        attr(z, "mcpar") <-
                            c(attr(x, "burnin") + attr(x, "thin"),
                              attr(x, "burnin") + attr(x, "thin") * niter,
                              attr(x, "thin"))
                        attr(z, "class") <- c("mcmc", class(z))
                        t(z)
                    })
        ## combine list of mcmc objects to a coda mcmc.list
        #x <- as.mcmc.list(x)
        class(x) <- "mcmc.list"
    } else { # one chain: make to a single mcmc object
        x <- as.ts(x)
        mcpar <- attr(x, "tsp")
        mcpar[3] <- round(1/mcpar[3])
        attr(x, "mcpar") <- mcpar
        class(x) <- c("mcmc", class(x))
    }
    x
}

`toCoda.permat` <- toCoda.oecosimu

Try the vegan package in your browser

Any scripts or data that you put into this service are public.

vegan documentation built on Sept. 11, 2024, 7:57 p.m.