mm.wbugs {mixstock} | R Documentation

## Run many-to-many model via WinBUGS (or JAGS)

### Description

Sets up the many-to-many model and passes it to WinBUGS via R2WinBUGS (or R2jags)

### Usage

    mm.wbugs(x, sourcesize,
    n.iter=20000,  n.burnin=floor(n.iter/2),
    n.chains=x$R,
    n.thin=max(1, floor(n.chains * (n.iter - n.burnin)/1000)),
    files.only = FALSE,
    inittype=c("dispersed","random"),bugs.code=c("TO","BB"),
                         returntype=c("mixstock","coda","bugs"),
    pkg=c("WinBUGS","JAGS"),
    mixprior=1,
    which.init,
    debug=FALSE,
    working.directory,...)
    write.TO.bugscode(fn,MIX)

### Arguments

`x` | a mixstock data object
`sourcesize` | Relative sizes of sources
`n.iter` | Total length of each chain
`n.burnin` | Number of burn-in iterations
`n.chains` | Number of chains (default, number of sources)
`n.thin` | thinning rate. Must be a positive integer. Set 'n.thin' > 1 to save memory and computation time if 'n.iter' is large. Default is 'max(1, floor(n.chains * (n.iter-n.burnin) / 1000))' which will only thin if there are at least 2000 simulations.
`files.only` | (unimplemented) don't run WinBUGS, just produce input files
`inittype` | "dispersed" or "random" depending on how you want multiple chains to be initialized
`bugs.code` | "TO" or "BB" depending on whether you want old-style (Toshi Okuyama=TO) or more compact but possibly slower (Ben Bolker=BB) code
`mixprior` | Dirichlet prior for contributions to mixed stocks. Should be either a vector of length (nmix+1) – one extra for the unknown stock – or a single numeric value which will be replicated
`which.init` | for "dispersed" start with fewer chains than sources, which sources should be used as the dominant sources in the chains? (default is a random sample without replacement from the list of sources)
`debug` | run BUGS in debug mode? (i.e. don't exit and go back to R automatically)
`...` | other arguments to `bugs`
`fn` | file name to write BUGS code to
`MIX` | number of mixed stocks
`returntype` | return value as a `mixstock.est` object, a CODA object, or a BUGS object?
`pkg` | which package to use for back-end calculations
`working.directory` | working directory for BUGS calculations

### Value

results of WinBUGS run, as a `mixstock.est` object by default: type varies according to `returntype`. `write.TO.code` produces a BUGS model file.

### Note

For diagnostic purposes, it may be worth running the code initially with `returntype="bugs"` and using `as.mcmc.bugs` and `as.mixstock.est.bugs` to convert the result to either CODA format or mixstock format.

pkg="JAGS" is still experimental.

### Author(s)

Ben Bolker

[Package mixstock version 0.9.2 Index]