tmbstan: Draw MCMC samples from a TMB model object using Stan

Description Usage Arguments Details Value Examples

View source: R/tmbstan.R

Description

Draw MCMC samples from a TMB model object using Stan

Usage

1
2
tmbstan(obj, ..., lower = numeric(0), upper = numeric(0), laplace = FALSE,
  silent = TRUE, debug = FALSE)

Arguments

obj

TMB model object.

...

Passed to rstan::sampling with some modifications - see details.

lower

Vector of lower parameter bounds.

upper

Vector of upper parameter bounds.

laplace

Apply the Laplace approximation to random subset of parameters ? The default disables the Laplace approximation.

silent

Be silent during samling ?

debug

Should not be used.

Details

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 laplace=TRUE. All methods provided by the rstan package can be applied to a fitted object. Get a complete list using methods(class="stanfit").

Lower and upper bounds can be set using lower and upper. The bounds can be specified in one of two ways. Either in short format, i.e. have the same length as obj$par. Remaining 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 random effects. In both cases -Inf and Inf are valid components of lower and upper respectively. Note that initial values must be within the specified bounds.

The function arguments ... are passed to rstan's fitting function, see ?rstan::sampling. A few notable arguments are:

Value

Object of class stanfit

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
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)

tmbstan documentation built on Dec. 15, 2021, 1:06 a.m.

Related to tmbstan in tmbstan...