Draw MCMC samples from a TMB model object using Stan
tmbstan( obj, ..., lower = numeric(0), upper = numeric(0), laplace = FALSE, silent = TRUE, debug = FALSE )
TMB model object.
Vector of lower parameter bounds.
Vector of upper parameter bounds.
Apply the Laplace approximation to
Be silent during samling ?
Should not be used.
tmbstan works for models with or without random effects.
By default a full Bayesian analysis is carried out, i.e. both
parameters and random effects are sampled using MCMC. Models with
random effects will thus have the Laplace approximation disabled. It
is possible to mix the Laplace approximation with MCMC by setting
All methods provided by the
rstan package can be applied to a
fitted object. Get a complete list using
Lower and upper bounds can be set using
The bounds can be specified in one of two ways. Either in short
format, i.e. have the same length as
parameters (the random effects) are set as unbounded in this case.
Otherwise the bounds must be in long format, i.e. have the same
length as the full parameter vector
obj$env$par including the
In both cases
Inf are valid components of
Note that initial values must be within the specified bounds.
The function arguments
... are passed to
fitting function, see
A few notable arguments are:
chains The number of chains.
iter The number of iterations.
init Initial values for the sampler.
rstan with some additions:
"random" - see
"0" are allowed - see
Additional special characters
"last.par.best" are allowed
and will be looked up in the TMB model object.
"par" signifies to start from the defaults of the model object.
If an optimization has been carried out, the intial value
will start from the MLE.
We also allow to pass a single numeric vector, or a list of numeric vectors. List length must match the number of chains. Vector lengths must match the number of sampled parameters. Names are currently ignored.
that do not follow the previous scheme (e.g. characters) are passed on
rstan unchanged. If in doubt, use
rstan::get_inits to inspect the
applied initial values.
seed Random seed.
Object of class
TMB::runExample("simple") fit <- tmbstan(obj, chains=1) class(fit) ## "stanfit" ## The available methods are methods(class="stanfit") ## Not run: ## Pairs plot pairs(fit, pars=names(obj$par)) ## End(Not run) ## Trace plot traceplot(fit, pars=names(obj$par), inc_warmup=TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.