I am reviewing an example (p. 180-181, Example 11.3 and 11.4) from All of Statistics by Larry Wasserman. The example intends to illustrate that the posterior can be found analytically and can be approximated by simulation approach:
Let $X_1,...X_n \sim Bernoulli(p)$ and $f(p) = 1$ so that $p|X_1,...,X_n \sim Beta(s+1, n-s+1)$ with $s = \sum_{i=1}^{n} x_i $. Let $\psi = log(p/(1-p))$. Find the posterior density of $\Psi|X_1,...,X_n$.
By analytical approach, it is shown that the exact pdf of the posterior is as follows:
$h(\psi|x_1,...,x_n) = H'(\psi|x_1,...,x_n) = \frac{\Gamma(n+2)}{\Gamma(s+1)\Gamma(n-s+1)}(\frac{e^\psi}{1+e^\psi})^{s}(\frac{1}{1+e^\psi})^{n-s+2}$
To approximate the above exact pdf, one can perform simulation approach as follows:
- Draw $P_1,...,P_B \sim Beta(s+1, n-s+1)$
- Let $\psi_i = log(P_i / (1 - P_i))$ for $ i = 1,...,B.$ Now $\psi_1,...,\psi_B$ are IID draws from $h(\psi|x_1,...,x_n).$
- Plot the histogram for $\psi.$
Based on the above procedures, I tried to do a simulation experiment to see if the simulated result is actually closed to the exact pdf. The plots below are my result:
The upper graph is the exact pdf derived by analytical approach while the lower graph is the simulated histogram. Their shapes are pretty similar, but they are different in the heights. Particularly, the peak of the simulated histogram is greater than 1 even after the normalisation, while the peak of the exact pdf is below 1. I am trying to figure out the reason for such discrepancy. Could anyone provide me any clues? Thanks!
- You can find my whole work in the link below: Full Simulation Result