mcmc: Run a mcmc sampler

View source: R/mcmc.R

mcmcR Documentation

Run a mcmc sampler

Description

Run a mcmc sampler

Usage

mcmc(pars, n_steps, compare = NULL, progress = FALSE, n_chains = 1)

Arguments

pars

A ['mcmc_parameters'] object containing information about parameters ( parameter ranges, priors, proposal kernel, observation functions).

n_steps

Number of MCMC steps to run

compare

likelihood function to compare data to epidemic trajectory should return a single value representing the log-likelihood. Default is compare_basic()

progress

Logical, indicating if a progress bar should be displayed, using ['progress::progress_bar'].

n_chains

Optional integer, indicating the number of chains to run. If more than one then we run a series of chains and merge them with [mcmc_combine()]. Chains are run in series, with the same model.

Details

This is a basic Metropolis-Hastings MCMC sampler. The 'model' is run with a set of parameters to evaluate the likelihood. A new set of parameters is proposed, and these likelihoods are compared, jumping with probability equal to their ratio. This is repeated for 'n_steps' proposals.

This function is adapted from the 'pmcmc' in the mcstate package https://github.com/mrc-ide/mcstate

Value

A 'gonovax_mcmc' object containing 'pars' (sampled parameters) and 'probabilities' (log prior, log likelihood and log posterior values for these probabilities).


mrc-ide/gonovax documentation built on Dec. 15, 2024, 11:02 a.m.