# Rao–Blackwellization of Metropolis–Hastings

I am trying to achieve a Rao–Blackwellization of Metropolis–Hastings algorithm. In the paper by Robert et al. 2018, the following is given.

\begin{align} ℑ=&\frac{1}{T}\sum_{t=1}^Th(\theta^{(t)})=\frac{1}{T}\sum_{i=1}^Th(ϑ_t)\sum_{t=1}^T \mathbb{I}_{\theta^{(i)}=ϑ_t}\\ =&\frac{1}{T}\sum_{t=1}^Th(ϑ_t) \mathbb{E}\left[\sum_{i=1}^T \mathbb{I}_{\theta^{(i)}=ϑ_t}\middle|ϑ_1,...,ϑ_t\right] \\ =&\frac{1}{T}\sum_{t=1}^Th(ϑ_t)\left(\sum_{i=1}^T\mathbb P\left(\theta^{(i)}=ϑ_t|ϑ_1,...,ϑ_t\right)\right) \end{align}

where $$(\theta^{(t)})$$ is the Markov chain sequence, $$(ϑ_t)$$ is the sequence of proposal values. In the first line it is simply multiplying each of the proposal values by the number of times they have placed in the chain. It is another estimator of the mean. In the second line, it is conditioning this indicator function to the all of the proposal values, which are the sufficient statistics for the proposal values to be used in Rao–Blackwellization. And at the last step, it makes use of the conditional probabilities.

In my R code, I store the resulting chain, all of the proposal values, number of time they are accepted, the acceptance ratio of each proposal. But I couldn't get these things together and reach the Rao–Blackwellization.

I couldn't understand the $$\mathbb P(\theta^{(i)}=ϑ_t | ϑ_1,...,ϑ_t)$$. I have the acceptance ratio when $$i=t$$, but for the $$\theta^{(i)}=ϑ_{t \neq i}$$, how should I calculate this probability and achieve the Rao–Blackwellization of the Metropolis–Hastings?

1. The formula \begin{align} &\frac{1}{T}\sum_{t=1}^Th(ϑ_t)\sum_{i=1}^T \mathbb{I}_{\theta^{(i)}=ϑ_t}\\ &\qquad=\frac{1}{T}\sum_{t=1}^Th(ϑ_t) \mathbb{E}\left[\sum_{i=1}^T \mathbb{I}_{\theta^{(i)}=ϑ_t}\middle|ϑ_1,...,ϑ_t\right] \\ \end{align} is incorrect since the second line is the Rao-Blackwellisation of the first one: \begin{align} &\mathbb E\left[\frac{1}{T}\sum_{t=1}^Th(ϑ_t)\sum_{i=1}^T \mathbb{I}_{\theta^{(i)}=ϑ_t}\middle|ϑ_1,...,ϑ_t\right]\\ &\quad=\frac{1}{T}\sum_{t=1}^Th(ϑ_t) \mathbb{E}\left[\sum_{i=1}^T \mathbb{I}_{\theta^{(i)}=ϑ_t}\middle|ϑ_1,...,ϑ_t\right] \\ \end{align}
2. The equality \begin{align} &\frac{1}{T}\sum_{t=1}^Th(ϑ_t) \mathbb{E}\left[\sum_{i=1}^T \mathbb{I}_{\theta^{(i)}=ϑ_t}\middle|ϑ_1,...,ϑ_t\right] \\ &\quad=\frac{1}{T}\sum_{t=1}^Th(ϑ_t)\left(\sum_{i=1}^T\mathbb P\left(\theta^{(i)}=ϑ_t|ϑ_1,...,ϑ_t\right)\right) \end{align} is straightforward since \begin{align} &\mathbb{E}\left[\sum_{i=1}^T \mathbb{I}_{\theta^{(i)}=ϑ_t}\middle|ϑ_1,...,ϑ_t\right] \\ &\quad=\sum_{i=1}^T \mathbb{E}\left[\mathbb{I}_{\theta^{(i)}=ϑ_t}\middle|ϑ_1,...,ϑ_t\right]\\ &\quad=\sum_{i=1}^T\mathbb P\left(\theta^{(i)}=ϑ_t|ϑ_1,...,ϑ_t\right) \end{align}
3. The computation of $$\mathbb P\left(\theta^{(i)}=ϑ_t|ϑ_1,...,ϑ_t\right)$$ is based on the integration of the uniform variates used to make the choice between the proposed value and the current value of the Markov chain. The computation is detailed in our 1996 paper with Georges Casella, as well as in our MCMC book.