Learn R Programming

TMB (version 1.7.4)

run_mcmc.rwm: [BETA VERSION] Draw MCMC samples from a model posterior using a Random Walk Metropolis (RWM) sampler.

Description

[BETA VERSION] Draw MCMC samples from a model posterior using a Random Walk Metropolis (RWM) sampler.

Usage

run_mcmc.rwm(nsim, fn, params.init, alpha = 1, covar = NULL, diagnostic = FALSE)

Arguments

nsim
The number of samples to return.
fn
A function that returns the log of the posterior density.
params.init
A vector of initial parameter values.
alpha
The amount to scale the proposal, i.e, Xnew=Xcur+alpha*Xproposed where Xproposed is generated from a mean-zero multivariate normal. Varying alpha varies the acceptance rate.
covar
An optional covariance matrix which can be used to improve the efficiency of sampling. The lower Cholesky decomposition of this matrix is used to transform the parameter space. If the posterior is approximately multivariate normal and covar approximates the covariance, then the transformed parameter space will be close to multivariate standard normal. In this case the algorithm will be more efficient, but there will be overhead in the matrix calculations which need to be done at each step. The default of NULL specifies to not do this transformation.
diagnostic
Whether to return a list of diagnostic metrics about the chain. Useful for assessing efficiency and tuning chain.

Value

If diagnostic is FALSE (default), returns a matrix of nsim samples from the posterior. Otherwise returns a list containing samples ('par'), proposed samples ('par.proposed'), vector of which proposals were accepted ('accepted'), and the total function calls ('n.calls'), which for this algorithm is nsim

Details

This algorithm does not yet contain adaptation of alpha so some trial and error may be required for efficient sampling.

See Also

run_mcmc, run_mcmc.nuts, run_mcmc.hmc