The normal distribution is the workhorse of continuous-data modeling—not because real-world populations are literally Gaussian, but because the Central Limit Theorem pushes averages toward normality and because a normal model depends only on first and second moments.Peter D. Hoff. A First Course in Bayesian Statistical Methods. Springer Texts in Statistics. Springer, New York, 2009. ISBN 978-0-387-92299-7. doi:10.1007/978-0-387-92407-6 Chapter 5 marks a decisive step up in complexity: for the first time we have two unknown parameters, the population mean and variance , forcing us to confront joint priors, marginalization, and the exact trade-off between bias and variance.
For an i.i.d. sample , expanding the sum of squared deviations around the sample mean yields the algebraic workhorse identity that powers Chapters 5 through 9:
(5.2)
where is the unbiased sample variance (the cross term vanishes identically). Substituting (5.2) into the joint likelihood gives
(5.3)
By the Fisher–Neyman factorization theorem, is a jointly sufficient statistic for : the entire dataset of size compresses without loss into two numbers.
Temporarily suppose is known. Because the likelihood (5.3) is exponential-quadratic in , a normal prior is conjugate. Writing precisions as and , the log-posterior collects into a quadratic in :
(5.4)
Matching the coefficients of and (completing the square; see Appendix B) yields the additive precision rule:
Proposition5.1(Normal–Normal Conditional Update). If and with known, then , where
(5.5)
Moreover, a future observation has posterior predictive distribution .
Precisions add: posterior precision equals prior precision () plus data precision ().
Means average by precision: is a convex combination of and , weighted by their respective precisions. Setting expresses the prior precision as equivalent observations, giving
Predictive variances add: writing with independent of , we immediately get —again separating parameter uncertainty from irreducible sampling variability.
5.3Joint Inference for Mean and Variance: The Conjugate Normal–Inverse-Gamma Model#
When both and are unknown, any joint prior factors via the chain rule as . To keep the joint posterior in closed form, we tie the prior variance of proportionally to through a prior sample size :
(5.6)
equivalently , where is a prior guess for and is its prior degrees of freedom (effective sample size).
Theorem5.2(Joint Conjugate Normal–Inverse-Gamma Posterior and Student-t Marginal). Under the conjugate prior (5.6) and i.i.d. normal sampling model (5.3), define ,, and
(5.7)
Then the joint posterior is again Normal–Inverse-Gamma:
(5.8)
Integrating out yields an exact location–scale Student- marginal posterior for :
(5.9)
and the posterior predictive distribution for a future observation is .
Proof. First, substitute into Proposition 5.1 to obtain immediately. Next, to find , combine the prior quadratic and data quadratic using the algebraic identity
Now multiply by and integrate over . The -integral
cancels the factor from , leaving
which is the exact kernel of . Finally, to obtain , integrate the joint posterior over precision :
which is precisely the density kernel of a Student- distribution with degrees of freedom, location , and scale .□
Look at the third term inside in (5.7): . When the observed mean disagrees sharply with the prior mean , the posterior variance automatically inflates to reconcile the discrepancy! Notice also the subtle improper reference limit: letting corresponds to and gives a posterior with . The standard reference prior corresponds formally to ,, and , yielding and , so —matching the classical Student- interval while endowing it with a genuine posterior probability interpretation!
Grogan and Wirth measured wing lengths (in mm) of midges: , giving and . Using weak prior knowledge from related species (,,),Theorem 5.2 gives ,,, and , with 95% Student- credible interval (Figure 5.1, left panel).
Figure 5.1:Left: conjugate Normal–Inverse-Gamma joint posterior contours for the midge wing lengths. Center: relative frequentist MSE of the Bayes mean vs. when true IQ ,, and prior —even with a 12-point prior bias, beats for every . Right: sampling densities at showing how mild shrinkage trades tiny bias for substantial variance reduction.
5.4Bias, Variance, and When the Bayes Mean Beats in MSE#
A natural objection to Bayesian shrinkage is: isn’t (with ) biased whenever ? Yes—its bias is , whereas is unbiased. Yet unbiasedness ignores variance! Measuring total accuracy by Mean Squared Error () reveals a striking frequentist justification for Bayesian shrinkage:
Theorem5.3(When the Bayes Mean Beats y-bar in MSE). Suppose and
with . Then
(5.10)
Consequently, if and only if
(5.11)
Proof. Write using (5.10) and multiply both sides by :
Subtracting and dividing by gives .□
Notice how generous (5.11) is! For Hoff’s town-IQ example (,, prior , so ), taking gives for all! Even though the prior guess is wrong by almost a full standard deviation, shrinking mildly toward it strictly lowers MSE at every sample size (Figure 5.1, center and right). Conversely, setting too large () makes bias dominate once grows.
5.5Expectation-Based Priors, Robustness, and the Limit of Conjugacy#
Two deeper lessons close Chapter 5 and motivate the rest of Part II:
Why normal sampling is surprisingly robust: The normal likelihood depends on the data only through , and by the Central Limit Theorem is approximately normal even when individual observations are skewed. Still, Lukacs’ theoremEugene Lukacs. A Characterization of the Normal Distribution. The Annals of Mathematical Statistics, 13:91–93, 1942 proves that and are independent if and only if the population is strictly normal; separately, heavy-tailed non-normal populations can distort variance inference and predictions.
The awkwardness of joint conjugacy: The conjugate prior (5.6) forced , coupling our uncertainty about the mean to the unknown sampling variance . In the midge example, we actually had an independent prior belief based on positivity—independent of ! Separating the priors into breaks joint conjugacy, so no longer has a closed form. Solving that exact problem is why we turn next to the Gibbs sampler in Chapter 6.
importnumpyasnpfromscipyimportstats# Conjugate Normal-IG analysis of Hoff's midge wing length data (n=9)y=np.array([1.64,1.70,1.72,1.74,1.82,1.82,1.82,1.90,2.08])n,ybar,s2=len(y),np.mean(y),np.var(y,ddof=1)mu0,k0,s20,nu0=1.9,1.0,0.01,1.0kn,nun=k0+n,nu0+nmun=(k0*mu0+n*ybar)/kns2n=(nu0*s20+(n-1)*s2+k0*n*(ybar-mu0)**2/kn)/nun# Exact Student-t 95% credible interval for thetaci_exact=stats.t.ppf([0.025,0.975],df=nun,loc=mun,scale=np.sqrt(s2n/kn))print(f"Exact mu_n = {mun:.4f}, s2_n = {s2n:.5f}, 95% CI = {np.round(ci_exact,4)}")# Exact ancestral Monte Carlo verification (draw 1/sigma^2, then theta | sigma^2)rng=np.random.default_rng(42)S=20_000s2_mc=1.0/rng.gamma(shape=nun/2.0,scale=2.0/(nun*s2n),size=S)th_mc=rng.normal(mun,np.sqrt(s2_mc/kn))print("MC 95% CI for theta: ",np.round(np.quantile(th_mc,[0.025,0.975]),4))print("MC 95% CI for sigma: ",np.round(np.quantile(np.sqrt(s2_mc),[0.025,0.975]),4))
5.6Modern Developments: Learning the Prior and Surviving Outliers#
5.6.1Tweedie’s Formula and Empirical Bayes Shrinkage#
Tweedie’s formula computes a normal posterior mean from the marginal density of the data alone, with no explicit prior.Beyond Hoff (2009). This material is not in Hoff’s book; the identity itself is much older—Robbins reported it in 1956 and credited Maurice Tweedie—and Efron (2011) modernized it as an empirical Bayes correction for selection bias.Bradley Efron. Tweedie’s Formula and Selection Bias. Journal of the American Statistical Association, 106(496):1602–1614, 2011. doi:10.1198/jasa.2011.tm11181 Take with known and any prior , and let . Then
(5.12)
Why? Since , differentiating under the integral gives ; a second derivative gives the variance. With , is and (5.12) collapses to , exactly in (5.5).
The gain appears with many parallel problems sharing : the observed are themselves a sample from , so a smooth estimate replaces the prior. The most extreme are then pulled back by , correcting the winner’s curse: a Bayes posterior given is unchanged by having selected case for its extremeness.
When to use it. With one mean and real prior knowledge, use Proposition 5.1. With hundreds of parallel means and no trusted prior family, use Tweedie—but not in the far tails, where has little data and its derivative is unstable.
5.6.2Whole Robustness with Log-Regularly Varying Tails#
A sampling density with sufficiently heavy tails can make a conflicting outlier’s influence on the posterior of both and vanish in the limit, a property called whole robustness.Beyond Hoff (2009). This material is not in Hoff’s book; Desgagné (2015) proves whole robustness for location–scale models, sharpening the older heavy-tail advice for outliers.Alain Desgagné. Robustness to outliers in location–scale parameter model using log-regularly varying distributions. The Annals of Statistics, 43(4):1568–1595, 2015. doi:10.1214/15-AOS1316 The normal model fails badly: moving one observation drags along and inflates in (5.7) without bound. Replace it by and examine the outlier’s likelihood factor, normalized by the constant , as :
(5.13)
For ,: is protected, but the surviving factor still pushes the scale upward. If instead with regularly varying—say ,, spliced onto a normal core—then shifting and scaling alter only by lower-order terms, so the ratio tends to and the outlier drops out. Passing from factors to the whole posterior requires regularity of (symmetry, continuity, monotone tails), a prior that is controlled near , and sufficiently many non-outliers relative to outliers; otherwise the “outliers” could form the dominant cluster. The theorem in the paper gives the exact count.
When to use it. Keep Hoff’s conjugate model for clean data and closed forms; use a log-regularly varying , at the price of MCMC and of predictive distributions with no finite mean, when gross contamination must affect neither location nor scale.
The script compares (5.12), computed from a numerically integrated marginal , with the conjugate update, and then evaluates the outlier factor (5.13) for and for the log-regularly varying tail .Beyond Hoff (2009). This computational check and its Wolfram symbolic counterpart below verify the modern methods in this section and are not in Hoff’s book.
importnumpyasnpfromscipyimportintegrate,stats# Tweedie from the integrated marginal m(y); log m is quadratic, so central differences are exactmu0,t20,v,y,h=1.0,4.0,1.0,3.0,0.1deflog_m(u):f=lambdath:stats.norm.pdf(u,th,np.sqrt(v))*stats.norm.pdf(th,mu0,np.sqrt(t20))returnnp.log(integrate.quad(f,-20,20,epsabs=0,epsrel=1e-12)[0])lo,mid,hi=log_m(y-h),log_m(y),log_m(y+h)print(f"Tweedie: {y+v*(hi-lo)/(2*h):.6f}, {v*(1+v*(hi-2*mid+lo)/h**2):.6f}")print(f"Conjugate: {(t20*y+v*mu0)/(t20+v):.6f}, {t20*v/(t20+v):.6f}")# Outlier factor (1/s) f((z - th)/s) / f(z): limit s^nu = 16 for t_4, limit 1 for the LRV tailth,s,nu,b=1.0,2.0,4.0,2.0forzin(1e2,1e8,1e100):t_ratio=((1+((z-th)/s)**2/nu)/(1+z**2/nu))**(-(nu+1)/2)/slrv_ratio=z/(z-th)*(np.log(z)/np.log((z-th)/s))**bprint(f"z = {z:.0e}: Student-t {t_ratio:.4f}, log-regularly varying {lrv_ratio:.4f}")
Write the log of the Normal–Normal marginal as a function of .
Integrates precision out of the Normal–Inverse-Gamma joint posterior in wolfram-ws-bridge JavaScript mode, verifies that the ratio to the Student- kernel has zero derivative in , derives the exact symbolic Student- posterior variance , factors , and instantiates all symbolic formulas on Hoff’s midge wing lengths.
Integrate precision out of the Normal–Gamma joint posterior to obtain the marginal kernel in .
Exercise5.4. Show that taking in Theorem 5.2 gives and , whereas the reference prior gives degrees of freedom. Explain the discrepancy by tracking the factor in .
Symbolic Solution & InstantiationTake to verify that the posterior mean collapses to the sample mean .
// Ex 5.1: Marginal posterior exponent of sigma^2 under kappa_0, nu_0 -> 0+ vs. reference prior 1/sigma^2
awaitshow`Limit[(k0*mu0 + n*yb)/(k0 + n), k0 -> 0]`
Evaluate the marginal posterior exponent of in the limit .
Instantiate the resulting degrees of freedom at , showing the -df difference ( versus ).
awaitshow`{-2*(${powLim} + 1), -2*(${powRef} + 1)} /. n -> 9`
Exercise5.5. Derive the exact posterior predictive distribution in Theorem 5.2 by integrating first over and then over . Confirm that its variance is for .
Symbolic Solution & InstantiationSimplify the exact posterior predictive Student- variance for .
Exercise5.6. In Theorem 5.3, suppose ,,, and . Find the exact sample size above which achieves lower MSE than , and verify your threshold against the orange curve in Figure 5.1.
Symbolic Solution & InstantiationSolve symbolically for the exact crossover sample size .