There are several Markov chain Monte Carlo methods. One of the commonly used methods is Metropolis-Hastings algorithm. Let be generated from which is needed only up to proportionality constant. Given an auxiliary function such that is a probability density function and , the Metropolis algorithm is as follows:
Draw from the p.d.f. , where is the current state of the Markov chain.
Compute the odds ratio .
If , then .
If , then
4. Repeat steps 1~3 until the desired sample (accepted )
are obtained. Note that will be the data generated from the posterior density. Then,