Example 5 (Posterior for a Gaussian mean) Suppose that, given the mean \(\mu\), \(X_1, \ldots, X_n \ \sim_{\operatorname{iid}}\ \operatorname{N}\mathopen{}\left(\mu, 1\right)\mathclose{}\), so the variance is known, and that the prior for \(\mu\) is \(\operatorname{N}\mathopen{}\left(0, 1\right)\mathclose{}\). Let \(\tilde{x}= (x_1, \ldots, x_n)\) be the observed data, with sample mean \(\bar x\).
The likelihood is
\[
\begin{aligned}
\operatorname{p}(\tilde{x}\mid \mu)
&= \prod_{i=1}^n (2\pi)^{-1/2} \operatorname{exp}\mathopen{}\left\{-\frac{1}{2}(x_i - \mu)^2\right\}\mathclose{}
&& \text{(independent Gaussian observations)}\\
&= (2\pi)^{-n/2} \operatorname{exp}\mathopen{}\left\{-\frac{1}{2}\sum_{i=1}^n (x_i - \mu)^2\right\}\mathclose{}
&& \text{(combining the exponents)}\\
&= (2\pi)^{-n/2} \operatorname{exp}\mathopen{}\left\{-\frac{1}{2}\mathopen{}\left(\sum_{i=1}^n x_i^2 - 2 \mu n \bar x + n \mu^2\right)\mathclose{}\right\}\mathclose{}
&& \text{(expanding the square; $\sum_i x_i = n \bar x$)}\\
&\propto \operatorname{exp}\mathopen{}\left\{-\frac{1}{2}\mathopen{}\left(n \mu^2 - 2 \mu n \bar x\right)\mathclose{}\right\}\mathclose{}
&& \text{(dropping factors that do not involve $\mu$)},
\end{aligned}
\]
and the prior density is \(\operatorname{p}(\mu) \propto \operatorname{exp}\mathopen{}\left\{-\frac{1}{2}\mu^2\right\}\mathclose{}\). Let \(m \stackrel{\text{def}}{=}\frac{n}{n+1} \bar x\). By Corollary 1,
\[
\begin{aligned}
\operatorname{p}(\mu \mid \tilde{x})
&\propto \operatorname{p}(\tilde{x}\mid \mu)\, \operatorname{p}(\mu)
&& \text{(posterior is proportional to likelihood times prior)}\\
&\propto \operatorname{exp}\mathopen{}\left\{-\frac{1}{2}\mathopen{}\left(n \mu^2 - 2 \mu n \bar x\right)\mathclose{}\right\}\mathclose{}
\cdot \operatorname{exp}\mathopen{}\left\{-\frac{1}{2}\mu^2\right\}\mathclose{}
&& \text{(substituting likelihood and prior)}\\
&= \operatorname{exp}\mathopen{}\left\{-\frac{1}{2}\mathopen{}\left((n+1)\mu^2 - 2 \mu n \bar x\right)\mathclose{}\right\}\mathclose{}
&& \text{(adding exponents)}\\
&= \operatorname{exp}\mathopen{}\left\{-\frac{1}{2}(n+1)\mathopen{}\left(\mu^2 - 2 \mu m\right)\mathclose{}\right\}\mathclose{}
&& \text{(factoring out $n+1$; definition of $m$)}\\
&= \operatorname{exp}\mathopen{}\left\{-\frac{1}{2}(n+1)\mathopen{}\left((\mu - m)^2 - m^2\right)\mathclose{}\right\}\mathclose{}
&& \text{(completing the square)}\\
&\propto \operatorname{exp}\mathopen{}\left\{-\frac{1}{2}(n+1)(\mu - m)^2\right\}\mathclose{}
&& \text{(dropping the factor $\operatorname{exp}\mathopen{}\left\{\tfrac{1}{2}(n+1)m^2\right\}\mathclose{}$)}.
\end{aligned}
\]
The last line is, up to a constant, the density of a Gaussian distribution with mean \(m\) and variance \(1/(n+1)\), so the posterior is
\[
\mu \mid \tilde{x}\;\sim\; \operatorname{N}\mathopen{}\left(\frac{n}{n+1}\bar{x},\; \frac{1}{n+1}\right)\mathclose{}.
\]
The posterior mean \(\frac{n}{n+1}\bar{x}\) is the sample mean shrunk toward the prior mean \(0\), and the shrinkage factor \(\frac{n}{n+1}\) approaches \(1\) as \(n \to \infty\).