Usage
run_mcmc.nuts(nsim, fn, gr, params.init, max_doublings = 4, eps = NULL, Madapt = NULL, delta = 0.5, covar = 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.
max_doublings
Integer representing the maximum times the path
length should double within an MCMC iteration. Default of 4, so 16
steps. If a U-turn has not occured before this many steps the algorithm
will stop and return a sample from the given tree.
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.
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
.
delta
The target acceptance rate for the dual averaging
algorithm. Defaults to 50%. NUTS does not include an accept/reject
Metropolis step, so this rate can be understood as the "average acceptance
probability that HMC would give to the position-momentum states explored
during the final doubling iteration."
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.