Usage
run_mcmc.hmc(nsim, fn, gr, params.init, L, eps = NULL, covar = NULL, delta = 0.5, Madapt = NULL, diagnostic = FALSE)
Arguments
nsim
The number of samples to return.
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
).
params.init
A vector of initial parameter values.
L
The number of leapfrog steps to take. The NUTS algorithm does
not require this as an input. If L=1
this function will perform
Langevin sampling. In some contexts L
can roughly be thought of
as a thinning rate.
eps
The length of the leapfrog steps. If a numeric value is
passed, it will be used throughout the entire chain. A NULL
value will initiate adaptation of eps
using the dual averaging
algorithm during the first Madapt
steps.
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.
delta
The target acceptance rate if using apative
eps
. Defaults to 50%.
Madapt
An optional argument for how many iterations to adapt
eps
in the dual averaging algorithm. A value of NULL
results in a default of Madapt=nsim/2
.
diagnostic
Whether to return a list of diagnostic metrics about
the chain. Useful for assessing efficiency and tuning chain.