Description Usage Arguments Value
The Adaptive Metropolis-within-Gibbs algorithm. Given a starting point and the necessary MCMC parameters as set out below, performs a random-walk of the posterior space to produce an MCMC chain that can be used to generate MCMC density and iteration plots. The algorithm undergoes an adaptive period, where it changes the step size of the random walk for each parameter to approach the desired acceptance rate, popt. After this, a burn in period is established, and the algorithm then uses univ_proposal
or mvr_proposal
to explore the parameter space, recording the value and posterior value at each step. The MCMC chain is saved in blocks as a .csv file at the location given by filename.
1 2 3 4 5 6 7 8 9 10 11 |
parTab |
the parameter table controlling information such as bounds, initial values etc |
data |
the data frame of data to be fitted |
mcmcPars |
named vector named vector with parameters for the MCMC procedure. iterations, popt, opt_freq, thin, burnin, adaptive_period and save_block. |
filename |
the full filepath at which the MCMC chain should be saved. "_chain.csv" will be appended to the end of this, so filename should have no file extensions |
CREATE_POSTERIOR_FUNC |
pointer to posterior function creator used to calculate a likelihood. See the main example - this should return your likelihood function (that only takes a single vector of parameters as an argument). |
mvrPars |
a list of parameters if using a multivariate proposal. Must contain an initial covariance matrix, weighting for adapting cov matrix, and an initial scaling parameter (0-1) |
PRIOR_FUNC |
user function of prior for model parameters. Should take values, names and local from param_table |
OPT_TUNING |
constant used to indicate what proportion of the adaptive period should be used to build the covariance matrix, if needed |
a list with: 1) full file path at which the MCMC chain is saved as a .csv file; 2) the last used covariance matrix; 3) the last used scale size
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.