Draw MCMC samples from a model posterior using the No-U-Turn (NUTS) sampler with dual averaging.
Source:R/sample_tmb_deprecated.R
sample_tmb_nuts.Rd
Draw MCMC samples from a model posterior using the No-U-Turn (NUTS) sampler with dual averaging.
Usage
sample_tmb_nuts(
iter,
fn,
gr,
init,
warmup = floor(iter/2),
chain = 1,
thin = 1,
seed = NULL,
control = NULL
)
Arguments
- iter
The number of samples to draw.
- fn
A function that returns the log of the posterior density.
- gr
A function that returns a vector of gradients of the log of the posterior density (same as
fn
).- init
Can be either a list containing a vector for each chain, a function which returns a vector of parameters, or NULL which specifies to use the MLE as stored in the admodel.hes file. It is generally recommended to use dispersed initial values to improve diagnostic checks (starting from the same point makes it less likely to find multiple modes).
- warmup
The number of warmup iterations.
- chain
The chain number, for printing only.
- thin
The thinning rate to apply to samples. Typically not used with NUTS.
- seed
The random seed to use.
- control
A list to control the sampler. See details for further use.
Details
This function implements algorithm 6 of Hoffman and Gelman
(2014), which includes adaptive step sizes (eps
) via an
algorithm called dual averaging. It also includes an adaptation scheme
to tune a diagonal mass matrix (metric) during warmup.
These fn
and gr
functions must have Jacobians already
applied if there are transformations used.