Q42. A nonconjugate prior and a change of variable
[12 marks]
Suppose X\mid\theta\sim\operatorname{Binomial}(n,\theta). Define Z=\log\frac{\theta}{1-\theta}, and assign the prior Z\sim N(1,1).
(a) Derive the prior density of \theta, including the Jacobian. [3 marks]
(b) Find the posterior kernel p(\theta\mid x). Is this prior conjugate? [2 marks]
(c) Derive the posterior kernel p(z\mid x). [3 marks]
(d) Construct a random-walk Metropolis–Hastings algorithm targeting p(z\mid x), using Z^*\mid Z^{(t)}=z\sim N(z,s^2). Explain how its output can estimate \mathbb{E}(\theta\mid x). [4 marks]
Definitions. The sampling parameter is 0<\theta<1, and its logit coordinate is z=\log\{\theta/(1-\theta)\}. The prior is Z\sim N(1,1), where the second argument is variance. For an invertible transformation, densities obey p_\theta(\theta)=p_Z(z(\theta))|dz/d\theta|. A kernel is always defined relative to its coordinate and reference measure; here these are d\theta or dz.
(a) Prior density of \theta. The inverse transformation is \theta=g(z)=\frac{e^z}{1+e^z},\qquad z\in\mathbb R, and \frac{dz}{d\theta} =\frac{d}{d\theta}\{\log\theta-\log(1-\theta)\} =\frac1{\theta(1-\theta)}. Since Z\sim N(1,1), the change-of-variable formula gives \boxed{ p(\theta) =\frac{1}{\sqrt{2\pi}\,\theta(1-\theta)} \exp\left[-\frac12\left\{\log\frac{\theta}{1-\theta}-1\right\}^2\right], \quad 0<\theta<1. } The density is zero outside (0,1). This is a logit-normal prior.
(b) Posterior kernel for \theta. For an observed count x\in\{0,\ldots,n\}, L(\theta;x)=\binom nx\theta^x(1-\theta)^{n-x}. Multiplication by the prior gives \boxed{ p(\theta\mid x)\propto \theta^{x-1}(1-\theta)^{n-x-1} \exp\left[-\frac12\left\{\log\frac{\theta}{1-\theta}-1\right\}^2\right], \quad 0<\theta<1. } This prior is not conjugate: the posterior does not in general remain logit-normal. In particular, its logit-transformed posterior is not Normal, as the following kernel shows.
(c) Posterior kernel for z. Substituting \theta=g(z) in the likelihood, \theta^x(1-\theta)^{n-x} =\frac{e^{xz}}{(1+e^z)^n}. Multiplying by the Normal prior density for z yields \boxed{ p(z\mid x)\propto \exp\left\{xz-n\log(1+e^z)-\frac12(z-1)^2\right\}, \quad z\in\mathbb R. } Alternatively, transforming the posterior from part (b) requires |d\theta/dz|=\theta(1-\theta), which cancels the prior’s Jacobian factor. Simply substituting \theta=g(z) into a density in \theta without this Jacobian would give the wrong density in z.
(d) Random-walk Metropolis–Hastings sampler. Define the log posterior kernel h(z)=xz-n\log(1+e^z)-\frac12(z-1)^2. The proposal density is symmetric because q(z^*\mid z) =\frac1{\sqrt{2\pi s^2}}\exp\left\{-\frac{(z^*-z)^2}{2s^2}\right\} =q(z\mid z^*). Thus the acceptance probability is A(z,z^*)=\min\{1,\exp[h(z^*)-h(z)]\}. Equivalently, the log of the untruncated ratio is \begin{aligned} \Delta=h(z^*)-h(z) &=x(z^*-z)-n\{\log(1+e^{z^*})-\log(1+e^z)\}\\ &\quad-\frac12\{(z^*-1)^2-(z-1)^2\}. \end{aligned}
Pseudocode. Choose any z^{(0)}\in\mathbb R and a fixed s>0. For t=0,\ldots,T-1:
1. Propose z^*\sim N(z^{(t)},s^2).
2. Calculate \Delta=h(z^*)-h(z^{(t)}).
3. Independently draw U\sim\operatorname{Uniform}(0,1).
4. If \log U\le\min\{0,\Delta\}, set z^{(t+1)}=z^*; otherwise set z^{(t+1)}=z^{(t)}.
This Markov chain has p(z\mid x) as its equilibrium density. Initial draws from an arbitrary start are not automatically posterior draws, and successive draws are generally dependent.
Estimating the requested posterior mean. After discarding a suitable initial burn-in of B iterations, transform each retained state and average: \theta^{(t)}=g(z^{(t)}), \qquad \boxed{ \widehat{\mathbb{E}(\theta\mid x)} =\frac1{T-B}\sum_{t=B+1}^T\frac{e^{z^{(t)}}}{1+e^{z^{(t)}}} }. With adequate convergence and a sufficiently long run, the ergodic average estimates the posterior expectation. Assess mixing and Monte Carlo error; the retained values are not independent.
For stable numerical evaluation, use \log(1+e^z)=\max\{0,z\}+\log(1+e^{-|z|}) and a stable logistic function.
Key result. Average the transformed draws. In general, \mathbb{E}\{g(Z)\mid x\}\ne g\{\mathbb{E}(Z\mid x)\}, so transforming the average of the z draws does not estimate the same quantity.