Skip to content

Instantly share code, notes, and snippets.

View paulocerqueirajr's full-sized avatar
🎯
Focusing

Paulo Cerqueira Junior paulocerqueirajr

🎯
Focusing
View GitHub Profile
@gaberoo
gaberoo / 1-metropolis.R
Last active June 25, 2024 18:05
R code to run an **MCMC** chain using a **Metropolis-Hastings** algorithm with a Gaussian proposal distribution. Although there are hundreds of these in various packages, none that I could find returned the likelihood values along with the samples from the posterior distribution. However, if you have these likelihood values, it's very easy to ca…
##############################################################################
# Metropolis-Hastings MCMC
#
# Runs a Metropolis-Hasting MCMC chain for a given likelihood function.
# Proposal steps are sampled from a Gaussian distribution, either in a single
# step or sequentially over the parameter space.
#
# Input:
# theta : starting value of the chain
# lik.fun : likelihood function