Suppose we want to estimate posterior variance of $\alpha$ given x, i.e. var($\alpha|x$). We have MCMC posterior samples $a_1,\dots, a_B$, which are not independent. Does $\hat{\text{var}}(\alpha|x) = \frac{1}{B} \sum (a_i-\bar{a})^2$ still serve as a good estimator for var($\alpha|x$)? Since the samples are not independent, we can't get consistency of $\hat{\text{var}}(\alpha|x)$ from law of large number.

In an extreme case of correlated posterior samples, if $a_i $s are all the same, then $\hat{\text{var}}(\alpha|x)$ is definitely not a good estimator.

So in practice how should we estimate posterior variance from MCMC samples?

  • $\begingroup$ Check Kipnis and Varadhan (1986). $\endgroup$
    – Xi'an
    May 9, 2018 at 8:40
  • $\begingroup$ @Xi'an As I recall, Kipnis and Varadhan talk about variance of Monte Carlo averages, not estimating the variance of the target distribution. $\endgroup$ May 9, 2018 at 15:36

1 Answer 1


The usual sample variance still works because the strong law still holds for ergodic Markov chains. That is, we can apply a strong law of large numbers.

If the Markov chain used in MCMC is Harris ergodic (irreducible, aperiodic, and Harris recurrent), the strong law of large numbers holds for functions with finite expectations. That is for Markov chain samples $X_1, X_2, \dots, X_n$, with stationary distribution $\pi$, and a function $f$ such that $\int f \pi(dx) < \infty$ $$\dfrac{1}{n} \sum_{i = 1}^{n} f(X_i) \overset{a.s.}{\to} \int f \pi(dx) \,. $$

The above is called the Birkhoff ergodic theorem, and essentially why MCMC is used so widely. Most reaonsbale MCMC algorithms usually satisfy the Harris ergodicity conditions.

So essentially, if you can write the sample variance as a function of Monte Carlo averages, strong consistency would follow naturally. The Math post here does exactly that.

  • $\begingroup$ Thanks a lot! I actually learned ergodic theorems in class but I never thought I would use them in practice. $\endgroup$
    – black corn
    May 9, 2018 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.