# Expected value of an estimate done using Gibbs sampling

This is related to this question. I am concerned about the expected value of a function estimated using sampling.

If the samples were obtained by a sampling method such as Gibbs sampling, and if I do the following estimation,

$\mathbb{E}[g(x)] \approx \hat{g} = \dfrac{1}{N}\sum g(x_s) \quad s=1\dots N$

Can we say $\mathbb{E}[\hat{g}] = \mathbb{E}[g(x)]$ ?

I think we can arrive at this by

$\mathbb{E} \big[\dfrac{1}{N}\sum g(x_s)\big] = \dfrac{1}{N}\sum \mathbb{E}[g(x)] = \mathbb{E}[g(x)]$.

• if the g(x_s) are each i.i.d samples then they each have the same expected value, and any given combination has the same expected value. Perhaps I'm misunderstanding the question. – redcalx Aug 14 '16 at 6:54

If the Gibbs sampler has not converged as yet, then $x_s$ is not a draw from the equilibrium distribution. Thus the expectation is not calculated with respect to the equilibrium distribution. Let $P^s$ be the distribution of the $x_s$ draw of the Gibbs sampler. If the sampler has not converged then $P^s \ne \pi$ where $\pi$ is the equilibrium distribution. So there will be some left over bias.

If the sampler has converged, then $P^s$ is sufficiently close to $\pi$ so that, $$E_{\pi}\left[ \dfrac{1}{N} \sum_{s=1}^{N} g(x_s) \right] = \dfrac{1}{N} E[g(x_s)] = E[g(x)].$$

As a side, the more important question is that in practical settings it doesn't matter as much whether the sampler has converged perfectly, since as you get more samples, you do better estimation. Here is the reason.

If instead of Gibbs sampling, the samples were obtained as iid samples, then the sample mean is a good estimate of the truth since $$\hat{g} = \dfrac{1}{N} \sum_{s= 1}^{N} g(x_s) \overset{a.s.}{\to} E[g(x)] \quad \text {as } N \to \infty,$$

where $\overset{a.s.}{\to}$ means convergence almost surely. This is often called the Strong Law of Large Numbers (SLNN). It is due to this convergence, if $N$ is large enough, we know that $E[g(x)] \approx \hat{g}$.

This SLLN also holds for MCMC sampling (and hence for Gibbs sampling) if the Markov chain is Harris ergodic, i.e., the Markov chain is irreducible, aperiodic and positive Harris recurrent. This seems difficult to verify, but in fact holds for most MCMC algorithms.

If your full conditionals in the Gibbs sampler are all valid distributions, then the Gibbs sampler is Harris ergodic, and thus the strong law of large numbers hold.

• Thank you for the detailed answer. Is there any reference that contains proofs for Harris ergodic Markov chain gives iid samples ? and also Harris ergodicity in general ? – user2939212 Aug 15 '16 at 5:39
• One fundamental issue is that it is almost always impossible to assert that "the sampler has converged". Except for perfect sampling (rarely applicable) and renewal (usually costly), I know of no technique that allows to spot exactly the time $s$ when $X_s$ starts being distributed from the target. – Xi'an Jan 27 '19 at 10:26
• @Xi'an Certainly. The only other way I can think of is if you can possibly start from stationarity. Like a rejection sampler that's inefficient for Monte Carlo, but reasonable for one starting value. – Greenparker Jan 27 '19 at 16:01