run_metropolis_MCMC: Adaptive Metropolis-within-Gibbs Random Walk Algorithm.

Description Usage Arguments Value See Also

View source: R/mcmc_functions.R

Description

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 proposalfunction 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.

Usage

1
2
3
4
run_metropolis_MCMC(startvalue, iterations = 1000, data, param_table,
  popt = 0.44, opt_freq = 50, thin = 1, burnin = 100,
  adaptive_period = 1, LIKELIHOOD_FUNCTION, MODEL_FUNCTION, filename,
  save_block = 500, VERBOSE = FALSE)

Arguments

startvalue

a vector of parameter values used as the starting point for the MCMC chain. MUST be valid parameters for the model function

iterations

number of iterations to run the MCMC chain for. Note that each parameter is moved once independently for each iteration. Defaults to 1000

data

the data against which the likelihood is calculated

param_table

a table of parameter data used for information such as bounds and prior function pointers. See load_param_table

popt

the desired acceptance rate. Defaults to 0.44

opt_freq

how frequently the acceptance rate is adapted. Defaults to 50

thin

thinning value for the MCMC chain. Default is 1

burnin

the length of the burn in period. Defaults to 100

adaptive_period

length of the adaptive period. Defaults to 1

LIKELIHOOD_FUNCTION

a valid pointer to an R function which returns a single, log likelihood of the data given the current parameters

MODEL_FUNCTION

a valid pointer to an R function which is used to evaluate the model for the current set of parameters

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

save_block

the number of iterations that R will keep in memory before writing to .csv. Defaults to 500

VERBOSE

boolean flag for additional output. Defaults to FALSE

Value

the full file path at which the MCMC chain is saved as a .csv file

See Also

posterior, proposalfunction


jameshay218/mcmcJH documentation built on May 18, 2019, 11:20 a.m.