# MCMC diagnostics

Explore the difference between MC and MCMC with a sample example.

A discrete variable $\delta\sim\{1,2,3\}$ and a continuous variable $\theta\in\mathrm{I\!R}$.

The marginal density of $\theta$ would be

Firstly, generate 1000 Monte Carlo $\theta$-samples.

For 1000 MCMC samples, we have

Actually, re-run the above code, we can get much different figure. Let's try 10000 MCMC samples,

It turns out to be much stable when you re-run the above code.

## sample autocorrelation

Use R-function `acf`

. If a Markov chain with high autocorrelation, then it will move around the parameter space slowly, taking a long time to achieve the correct balance among the different regions of the parameter space.

## effective sample size

Use R command `effectiveSize`

in the `coda`

package, which can be interpreted as the number of independent Monte Carlo samples necessary to give the same precision as the MCMC samples.

Last updated