= Solution
Write
$$
\bar z=\frac1n\sum_{i=1}^nz_i,
\qquad
S(\mu)=\sum_{i=1}^n(z_i-\mu)^2.
$$
Multiplying the likelihood by the <improper prior> gives the <Bayesian posterior> kernel
$$
\pi(\mu,\omega\mid z)
\propto
\omega^{n/2}
\exp\left\{-\omega\left(\lambda+\frac12S(\mu)\right)\right\},
\qquad \omega>0.
$$
Since
$$
S(\mu)=\sum_{i=1}^n(z_i-\bar z)^2+n(\mu-\bar z)^2,
$$
the first full conditional is
$$
\boxed{\mu\mid\omega,z\sim
N\left(\bar z,\frac1{n\omega}\right)}.
$$
Holding $\mu$ fixed and comparing powers and exponential rates gives
$$
\boxed{\omega\mid\mu,z\sim
\operatorname{Gamma}\left(
m,\lambda+\frac12S(\mu)\right)},
\qquad
m=\frac n2+1.
$$
The assumed parity of $n$ makes $m$ a positive integer.
Initialize $\mu_0$ arbitrarily. At iteration $j$, put
$$
r_j=\lambda+\frac12S(\mu_{j-1}).
$$
Draw $m$ independent uniform variables $U_{j1},\ldots,U_{jm}$ and set
$$
\omega_j=-\frac1{r_j}\sum_{\ell=1}^m\log U_{j\ell}.
$$
By <sampling an integer-shape gamma distribution>, this has the required $\operatorname{Gamma}(m,r_j)$ law. Next draw $G_j\sim N(0,1)$ independently and set
$$
\mu_j=\bar z+\frac{G_j}{\sqrt{n\omega_j}}.
$$
These are exactly the two full-conditional updates of the <normal mean-precision Gibbs sampler>. After discarding burn-in, the pairs $(\mu_j,\omega_j)$ are approximate samples from the posterior by <Markov chain Monte Carlo>.
Back to article page