Gabriel E Leventhal

R Scripts

Metropolis-Hastings MCMC

Why another Metropolis-Hastings script in R? Well, the short answer is most others suck. And the reason is that they don't return the likelihood values that are calculated while sampling from the posterior. Normally, this isn't interesting because you're trying to get an estimate of the posterior distribution.

If you want to estimate quantities like the marginal likelihood or the deviance information criterion (DIC), it's quite handy to have those likelihood values, which can be expensive to calculate in some circumstances. So here are some code snippets to caluclate the DIC, the marginal likelihood from a Metropolis-Hastings run using an arbitraty function coded in R. Ideally this should be rewritten in a language that's fast like C or FORTRAN, but for some things it's quite handy to have it in R.