Skip to contents

During Markov chain Monte Carlo a given parameter needs to be updated, the model needs to be simulated at the updated point.

Usage

metropolis_update(
  simulate,
  logLikelihood = ll,
  dprior = function(x) prod(dnorm(x)),
  Sigma = NULL,
  parAcceptable = function(p) {
     all(is.finite(p))
 }
)

Arguments

simulate

a function that simulates the model

logLikelihood

a function that returns the log-likelihood value given the paramegter value, with simulations attached to the parameter as an attreibute (probably a closure)

dprior

a function that returns the prior density of the given parameter vector

Sigma

the transition kernel's covariance matrix.

parAcceptable

a function that can be used to reject a proposal based on the values of the parameters alone (shortcut to rejection, sans simulation)

Details

Using the simulations, and an acceptance rule, the proposed update is either accepted or rejected.

This function returns a closure metropolis, with only parMCMC as it's sole argument: parProposal <- metropolis(parGiven)

An optional argument to this function is parAcceptable, during sampling, when metropolis is called as the update function, and parAcceptable(parProposal) returns FALSE, then metropolis shortcuts to retrun(parGiven) without performing simulations.

This function can be used to weed out parameter combinations that would result in obviously nonsensical simulations without wasting CPU-time.