Markov Chain Monte Carlo
Gist
Used for Bayesian analysis, how to simulate the posterior distribution
Definiton
Metropolis-Hastings
Algorithm
Step 1: Propose a new location.
Conditioned on the current location
Step 2: Decide whether or not to go there
- Calculate the acceptance probability
:
$$\alpha = min(1, \frac{f(\mu') L(\mu'|y)(q(\mu|\mu')}{f(\mu') L(\mu'|y)(q(\mu|\mu')}$$ - Figuratively, flip a weighted coin. If it's Heads, with probability
, go to the proposed location . If it's Tails, with probability , stay at .
Metropolis algorithm
The Metropolis algorithm is a special case of the Metropolis Hastings in which the proposal model is symmetric.
Most MCMC uses Metropolis-Hastings algorithm. I really enjoy the Bayes Rule book description. Imagine that you're a tour manager and the chain is a tour around the range of posterior plausible values. The chain should spend more time touring values where the posterior pdf is greatest and less time visiting places where the posterior drops off.
Step 1: Propose a random location, u', for the next tour stop
Step 2: Decide whether to go to the proposed location (
We can propose Markov chain tour stops by sampling from a more different model such as a uniform proposal model. If the proposed location is greater than that of the current location- definitely go there. Otherwise, maybe go there?
Diagnostic
Trace plot

An example of a good trace-plot
Density plots of parallel chains
Effective sample ratio
Autocorrelation
See Autocorrelation
R-hat
Calculates the ratio between sources of variability - across all chains combined and then variability within any individual chain.
If R-hat = 1, this reflects stability. In contrast, R-hat > 1 indicates instability. R-hat ratio greater than 1.05 raises some red flags about the stability of the simulation
Program
Stan uses Hamiltonian Monte Carlo
Jags uses Gibb sampling