Chapter 7
The Multivariate Normal Model
Real measurements rarely arrive in isolation. A student takes a reading exam before and after instruction; a patient has glucose, blood pressure, skin thickness, and BMI recorded simultaneously. Treating each coordinate with a separate univariate normal model throws away the covariance structure—the very information that lets us test paired differences, quantify conditional relationships, and impute missing observations.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 7 generalizes every ingredient of Chapters 5 and 6 from scalars to vectors and positive-definite matrices.
7.1The Multivariate Normal Density and Quadratic Recognition#
A -dimensional random vector follows a multivariate normal distribution, written , where is the mean vector and is a symmetric positive-definite covariance matrix, if its density is
(7.1)Its level sets are -dimensional ellipsoids centered at whose axes align with the eigenvectors of (Figure 7.1). Expanding the exponent in (7.1) gives the vector analogue of completing the square (proven in Appendix B):
(7.2)Whenever a log-conditional density is a concave quadratic in a vector parameter , (7.2) lets us read off its precision matrix and mean in a single line.
7.2Semiconjugate Priors: MVN and Inverse-Wishart#
Given i.i.d. observations stacked as the data matrix , we place independent semiconjugate priors on the mean vector and covariance matrix:
(7.3)where and are symmetric positive-definite matrices and is the prior degrees of freedom.
7.2.1The Wishart and Inverse-Wishart Distributions#
How do we construct a probability distribution over symmetric positive-definite matrices? For any integer , draw i.i.d. vectors and sum their outer products:
(7.4)This is the exact matrix generalization of the gamma distribution (for , is , and the density extends analytically to all real ). Setting with defines Hoff’s inverse-Wishart parameterization :
(7.5)Setting gives a weakly informative prior centered at with finite expectation.Limitation of the inverse-Wishart prior: a single scalar simultaneously governs our certainty about all diagonal variances and all off-diagonal correlations! When variances differ in prior certainty from correlations, modern practice often separates scale and correlation priors (e.g., LKJ priors on correlations, published the same year as Hoff’s book and not covered there; see Section 7.5.1), or uses parameter expansion as in Chapter 12.Daniel Lewandowski, Dorota Kurowicka, and Harry Joe. Generating random correlation matrices based on vines and extended onion method. Journal of Multivariate Analysis, 100(9):1989–2001, 2009. doi: 10.1016/j.jmva.2009.04.008
7.2.2The Trace Trick and Full Conditionals#
To recognize the full conditional of from the MVN likelihood, we use the cyclic invariance of the matrix trace, :
Proposition 7.1 (The Trace Trick and MVN Full Conditionals). For any vectors and symmetric matrix , define the sum-of-squares matrix . Then
(7.6)Consequently, under the semiconjugate prior (7.3), the two full conditional distributions are:
Mean vector given covariance: , where
(7.7)Covariance matrix given mean vector:
(7.8)
Proof. Each summand is a scalar, so it equals its own trace. Applying and linearity of trace gives
For , collecting terms in from gives
which matches (7.2) directly. For , multiplying (7.5) by yields
immediately recognizable as (7.8). □
Algorithm 7.2 (Two-Block MVN Gibbs Sampler). Initialize (e.g., at the sample covariance). For :
- Compute and from (7.7) using and draw .
- Compute and draw .
7.2.3Example: Reading Comprehension (Means vs. Individuals Revisited)#
Hoff analyzes children tested before () and after () a reading program, with and sample correlation . Running Algorithm 7.2 yields —virtually certain that the population average rises—yet drawing posterior predictive pairs shows : nearly a third of individual children still score lower on the second test!
7.3Missing Data and Data Augmentation#
In real multivariate surveys, entries are frequently missing. Let be the binary observation indicator matrix ( if is observed, if missing), splitting . Following Little and RubinRoderick J. A. Little and Donald B. Rubin. Statistical Analysis with Missing Data. John Wiley & Sons, Hoboken, NJ, second edition, 2002, missingness falls into three regimes:
- MCAR (Missing Completely At Random): .
- **MAR (Missing At Random)**: —missingness may depend on observed values, but not on the unobserved values themselves.
- MNAR (Missing Not At Random): missingness depends on (e.g., high earners refusing to report income).
When the mechanism is MAR and the missingness parameter is prior-independent of (distinct parameters), the missing-data mechanism is ignorable: the factor pulls completely outside the posterior for !
Even under ignorability, computing directly breaks conjugacy because every row has a different subset of observed columns. Instead, data augmentation treats as an extra vector of unknown parameters and includes it as a third block in the Gibbs sampler! What is the full conditional of the missing entries given the observed entries in row ? It is given by the exact Schur complement conditional normal theorem (see Appendix B):
(7.9)Algorithm 7.3 (Data-Augmentation MVN Gibbs Sampler for MAR Missing Data). Initialize (e.g., by column means) and . For :
Unlike ad-hoc single imputation (which understates uncertainty by treating imputed values as real data), Algorithm 7.3 automatically propagates imputation uncertainty into every posterior interval for and !
7.4Marginal Correlations vs. Partial Regression Coefficients#
In Hoff’s Pima Indians dataset ( women; variables: glucose glu, blood pressure bp, skin-fold thickness skin, and body mass index bmi), all pairwise correlations are positive—for instance, glu correlates positively with bp, skin, and bmi. Yet from (7.9), the conditional expectation of coordinate given all other coordinates is linear with partial regression coefficients
which can be computed directly at every Gibbs draw ! In the Pima data, while bp correlates positively with glu marginally, its partial regression coefficient given bmi and skin shrinks sharply toward zero: the apparent bp–glu association is largely accounted for by body mass and skin-fold thickness. Furthermore, holding out a subset of entries and comparing imputed posterior means against true values validates the MVN model out-of-sample.
import numpy as np
from scipy import stats
# Semiconjugate MVN Gibbs sampler (illustrated on synthetic reading-score data)
rng = np.random.default_rng(7)
n, p = 22, 2
Y = rng.multivariate_normal([47.18, 53.86], [[182.16, 147.45], [147.45, 243.65]], size=n)
ybar = Y.mean(axis=0)
# Prior hyperparameters (Hoff's weakly informative reading-test prior)
mu0 = np.array([50.0, 50.0])
L0 = np.array([[625.0, 312.5], [312.5, 625.0]])
L0_inv = np.linalg.inv(L0)
nu0 = 4.0
S0 = L0.copy()
S = 4_000
theta_s = np.empty((S, p))
Sigma_s = np.empty((S, p, p))
Sigma_cur = np.cov(Y, rowvar=False)
for s in range(S):
# 1. theta | Sigma, Y
Sig_inv = np.linalg.inv(Sigma_cur)
Ln = np.linalg.inv(L0_inv + n * Sig_inv)
mun = Ln @ (L0_inv @ mu0 + n * Sig_inv @ ybar)
th_cur = rng.multivariate_normal(mun, Ln)
# 2. Sigma | theta, Y (NOTE: scipy invwishart takes scale = S_post directly!)
diff = Y - th_cur
S_th = diff.T @ diff
Sigma_cur = stats.invwishart.rvs(df=nu0 + n, scale=S0 + S_th, random_state=rng)
theta_s[s], Sigma_s[s] = th_cur, Sigma_cur
# Compare population mean difference vs. posterior predictive individual difference
y_pred = np.array([rng.multivariate_normal(th, Sg) for th, Sg in zip(theta_s, Sigma_s)])
print(f"Pr(theta_2 > theta_1 | Y) = {np.mean(theta_s[:, 1] > theta_s[:, 0]):.3f}")
print(f"Pr(Ytilde_2 > Ytilde_1 | Y) = {np.mean(y_pred[:, 1] > y_pred[:, 0]):.3f}")7.5Modern Developments: Covariance Priors, Sparse Graphs, and Missingness#
7.5.1Huang–Wand Hierarchical Inverse-Wishart and LKJ Priors#
A single extra layer of scale parameters repairs the inverse-Wishart’s main defect—one governing everything—without leaving the Gibbs sampler.Beyond Hoff (2009). This material is not in Hoff’s book; the hierarchy is due to Huang and Wand (2013), while the LKJ construction of Lewandowski, Kurowicka and Joe appeared in the same year as Hoff’s book and is not covered there.Alan Huang and M. P. Wand. Simple Marginally Noninformative Prior Distributions for Covariance Matrices. Bayesian Analysis, 8(2):439–452, 2013. doi: 10.1214/13-BA815; and Daniel Lewandowski, Dorota Kurowicka, and Harry Joe. Generating random correlation matrices based on vines and extended onion method. Journal of Multivariate Analysis, 100(9):1989–2001, 2009. doi: 10.1016/j.jmva.2009.04.008 In the notation of (7.3), let
(7.11)Given , , and mixing over makes each standard deviation a half- variable with degrees of freedom and scale . Rescaling by a diagonal matrix leaves correlations unchanged, so each has density proportional to (compare Exercise 7.6): makes every correlation marginally uniform. The updates stay conjugate: (7.8) with and , followed by .
The LKJ prior instead sets on correlation matrices, independently of the scales. At it is uniform jointly, hence not marginally uniform for .
When to use it. Keep (7.3) when carries real information. Choose Huang–Wand as the default inside Gibbs, and LKJ with separate scale priors when scales and correlations must be a priori independent and sampling is gradient-based.
7.5.2The Graphical Horseshoe#
The graphical horseshoe shrinks most off-diagonal entries of almost to zero while leaving strong ones nearly untouched.Beyond Hoff (2009). This material is not in Hoff’s book; Li, Craig and Bhadra (2019) extend the horseshoe shrinkage prior to inverse covariance matrices.Yunfan Li, Bruce A. Craig, and Anindya Bhadra. The Graphical Horseshoe Estimator for Inverse Covariance Matrices. Journal of Computational and Graphical Statistics, 28(3):747–757, 2019. doi: 10.1080/10618600.2019.1575744 By Exercise 7.4, exactly when and are conditionally independent, so sparsity in is sparsity in the coefficients (7.10). Restricted to , the prior is flat on each , with for and half-Cauchy and . Write , single out the last row and column, and let , , and . Then, given the rest,
(7.12)Why? , and the trace (7.6) contributes ; now apply (7.2). Because , every draw is positive definite. Cycle over columns; inverse-gamma auxiliary variables handle and .
When to use it. For the four Pima variables an inverse-Wishart is enough. Use the graphical horseshoe when is comparable to or larger than and few edges are expected; it yields no exact zeros, so edges must still be selected, for example by credible intervals.
7.5.3Realized versus Everywhere MAR#
The MAR condition of Section 7.3 hides two different assumptions, and Bayesian ignorability needs only the weaker.Beyond Hoff (2009). This material is not in Hoff’s book; Seaman et al. (2013) separate two readings long conflated in the literature descending from Rubin’s original definition of MAR.Shaun Seaman, John Galati, Dan Jackson, and John Carlin. What Is Meant by “Missing at Random”? Statistical Science, 28(2):257–268, 2013. doi: 10.1214/13-STS415 Let be the pattern and values actually observed. Realized MAR requires to be constant in , for every ; everywhere MAR requires this for every pattern and every data set that could have occurred. Under realized MAR,
(7.13)given prior-independent . The mechanism is constant in , so it leaves the integral, and the posterior is evaluated only at : unrealized patterns never enter. Coverage, expected information, and replicated missing-data patterns average over other data sets, so realized MAR does not justify ignoring the mechanism there; everywhere MAR, with distinct parameters, is the usual sufficient condition.
Suppose post-tests could be withheld according to their own value, but only for children with a pretest below . If every pretest in our sample was fully observed and exceeded , the data are realized MAR yet not everywhere MAR: the posterior may ignore the mechanism, while a simulation study of its coverage may not.
When to use it. For the posterior from Algorithm 7.3, argue realized MAR plus prior independence; for frequentist calibration, defend everywhere MAR or model explicitly. Hoff’s single MAR condition does not draw this distinction.
7.5.4Computational & Symbolic Check#
The script simulates (7.11) with , testing against the uniform and against the half- distribution, and then draws correlation matrices uniformly (LKJ, ). For the LKJ density of is proportional to ; for general the exponent becomes , so at , the marginal variance is rather than the uniform’s .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.
import numpy as np
from scipy import stats
# Huang-Wand, p = nu = 2: draw IW(3) with scale 4*I, then rescale by 1/a_k (correlations are invariant)
rng = np.random.default_rng(7)
N, nu, A = 50_000, 2, 2.5
Sig0 = stats.invwishart.rvs(df=nu + 1, scale=2 * nu * np.eye(2), size=N, random_state=rng)
inv_a = rng.gamma(0.5, A**2, size=(N, 2)) # NumPy scale = 1/rate = A^2
Sig = Sig0 * np.sqrt(inv_a[:, :, None] * inv_a[:, None, :])
sd1 = np.sqrt(Sig[:, 0, 0])
rho = Sig[:, 0, 1] / (sd1 * np.sqrt(Sig[:, 1, 1]))
print(f"KS(rho, U(-1,1)) = {stats.kstest(rho, stats.uniform(-1, 2).cdf).statistic:.4f}")
print(f"KS(sigma_1, half-t_2) = {stats.kstest(sd1, lambda x: 2 * stats.t.cdf(x / A, nu) - 1).statistic:.4f}")
# LKJ(eta = 1), p = 3: uniform over positive definite correlation matrices, by rejection
r = rng.uniform(-1, 1, size=(400_000, 3))
keep = 1 + 2 * r.prod(axis=1) - (r**2).sum(axis=1) > 0
print(f"LKJ p = 3: Var(rho_12) = {r[keep, 0].var():.4f} (exact 0.25; uniform 0.3333)")// Chapter 7 (modern): Huang-Wand (p = 2) correlation marginal & LKJ density
const sInt = await show`Assuming[nu > 0 && k > 0,
FullSimplify[Integrate[s^(-(nu + 2))*Exp[-k/s^2], {s, 0, Infinity}]]]`const rhoKer = await show`(1 - r^2)^(-(nu + 4)/2) * (${sInt} /. k -> nu/(a1*(1 - r^2))) * (${sInt} /. k -> nu/(a2*(1 - r^2)))`await show`Assuming[nu > 0 && a1 > 0 && a2 > 0 && -1 < r < 1,
FullSimplify[D[Log[${rhoKer} / (1 - r^2)^(nu/2 - 1)], r]]]`const rhoDen = await show`Assuming[eta > 0 && -1 < r < 1,
FullSimplify[(1 - r^2)^(eta - 1) / Integrate[(1 - t^2)^(eta - 1), {t, -1, 1}]]]`await show`{${rhoDen} /. eta -> 1, ${rhoDen} /. eta -> 2}`await show`Table[Integrate[r^2*(${rhoDen} /. eta -> e), {r, -1, 1}], {e, {1, 3/2}}]`7.6Symbolic Check in Wolfram Language#
Verifies symbolically for a general covariance matrix in wolfram-ws-bridge JavaScript mode that the Schur-complement partial regression vector equals , derives the general conditional slope and conditional variance symbolically in terms of , and instantiates them on Hoff’s reading-comprehension covariance.
// Chapter 7: Symbolic 3x3 Schur-precision identity & symbolic 2x2 conditional normal
const Sig = [[W.s11, W.s12, W.s13], [W.s12, W.s22, W.s23], [W.s13, W.s23, W.s33]]
const betaSchur = await show`FullSimplify[Inverse[{{s22, s23}, {s23, s33}}] . {s12, s13}]`const betaPrec = await show`FullSimplify[-Inverse[${Sig}][[1, {2, 3}]] / Inverse[${Sig}][[1, 1]]]`await show`FullSimplify[${betaSchur} - ${betaPrec}]`// Abstract 2x2 covariance {{s1^2, rho*s1*s2}, {rho*s1*s2, s2^2}}: symbolic slope & cond. variance
const covSym = [[W.Power(W.s1, 2), W.Times(W.rho, W.s1, W.s2)], [W.Times(W.rho, W.s1, W.s2), W.Power(W.s2, 2)]]
const slopeSym = await show`FullSimplify[${covSym}[[1, 2]] / ${covSym}[[1, 1]]]`const cvarSym = await show`FullSimplify[${covSym}[[2, 2]] - ${covSym}[[1, 2]]^2 / ${covSym}[[1, 1]]]`// Instantiate on Hoff's reading-comprehension covariance (s1^2 = 182.16, s2^2 = 243.65, cov = 147.45)
await show`N[{${slopeSym}, Sqrt[${cvarSym}]} /. {s1 -> Sqrt[182.16], s2 -> Sqrt[243.65], rho -> 147.45/Sqrt[182.16*243.65]}]`7.7Exercises#
Exercise 7.4. Let be the precision matrix of . Using the block-matrix inversion identity, show that the partial regression vector in (7.10) satisfies , and deduce that and are conditionally independent given all remaining variables if and only if .
Symbolic Solution & Instantiation
Invert a general symbolic covariance : the precision is the adjugate over .// Ex 7.1: 3x3 block-matrix proof that beta_{1|2,3} = Sigma_{1,23}*Sigma_{23,23}^(-1) = -Omega_{11}^(-1)*Omega_{1,23}
const Sig = [[W.s11, W.s12, W.s13], [W.s12, W.s22, W.s23], [W.s13, W.s23, W.s33]]
const Om = await show`Inverse[${Sig}]`const betaCov = await show`${Sig}[[1, {2, 3}]] . Inverse[${Sig}[[{2, 3}, {2, 3}]]]`const betaPrec = await show`-${Om}[[1, {2, 3}]] / ${Om}[[1, 1]]`await show`FullSimplify[${betaCov} - ${betaPrec}]`Exercise 7.5. Extend the Python script above to create missing entries in column 2 under (a) MCAR (uniform random mask), (b) MAR (missing with higher probability when is in its bottom quartile), and (c) MNAR (missing whenever falls below its 20th percentile). Implement Algorithm 7.3 and compare its posterior for against complete-case analysis across all three regimes.
Symbolic Solution & Instantiation
Integrate over to derive the inverse Mills ratio bias under left truncation.// Ex 7.2: Exact complete-case MNAR bias when observations below z0 are truncated (zero complete-case bias under MCAR only)
const shift = await show`Assuming[Element[z0, Reals],
FullSimplify[Integrate[z*Exp[-z^2/2]/Sqrt[2*Pi], {z, z0, Infinity}] / Integrate[Exp[-z^2/2]/Sqrt[2*Pi], {z, z0, Infinity}]]]`const z20 = await show`z /. FindRoot[1/2*Erfc[-z/Sqrt[2]] == 1/5, {z, -0.84}]`await show`N[{${z20}, ${shift} /. z0 -> ${z20}}]`Exercise 7.6. For and , simulate draws from for and inspect the implied prior distribution of the off-diagonal correlation . Why does produce a uniform marginal prior on each correlation ?
Symbolic Solution & Instantiation
Record the exponent of in the marginal correlation prior under .// Ex 7.3: Marginal prior p(rho) ~ (1 - rho^2)^((nu0 - p - 1)/2) under IW(nu0, I_p)
const expSym = await show`(nu0 - p - 1) / 2`await show`Assuming[nu0 > p - 1, FullSimplify[Integrate[(1 - r^2)^((nu0 - p - 1)/2), {r, -1, 1}]]]`await show`Table[${expSym} /. {p -> 3, nu0 -> v}, {v, {4, 6, 20}}]`