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 pp-dimensional random vector 𝐘=(Y1,…,Yp)T\mathbf{Y} = (Y_1, \dots, Y_p)^T follows a multivariate normal distribution, written 𝐘∼𝒩p(𝜽,Σ)\mathbf{Y} \sim \mathcal{N}_p(\boldsymbol{\theta}, \Sigma), where 𝜽∈ℝp\boldsymbol{\theta} \in \mathbb{R}^p is the mean vector and Σ∈ℝp×p\Sigma \in \mathbb{R}^{p \times p} is a symmetric positive-definite covariance matrix, if its density is

p(𝐲∣𝜽,Σ)=(2π)−p/2 ∣Σ∣−1/2exp⁡{−12(𝐲−𝜽)TΣ−1(𝐲−𝜽)}. p(\mathbf{y} \mid \boldsymbol{\theta}, \Sigma) = (2\pi)^{-p/2}\,\lvert \Sigma \rvert^{-1/2} \exp\left\{-\frac{1}{2}(\mathbf{y} - \boldsymbol{\theta})^T \Sigma^{-1} (\mathbf{y} - \boldsymbol{\theta})\right\}. (7.1)

Its level sets are pp-dimensional ellipsoids centered at 𝜽\boldsymbol{\theta} whose axes align with the eigenvectors of Σ\Sigma (Figure 7.1). Expanding the exponent in (7.1) gives the vector analogue of completing the square (proven in Appendix B):

p(𝐱)∝exp⁡{−12𝐱TA𝐱+𝐱T𝐛}(A=AT≻0)  ⟺  𝐱∼𝒩p(A−1𝐛, A−1). p(\mathbf{x}) \propto \exp\left\{-\frac{1}{2}\mathbf{x}^T A \mathbf{x} + \mathbf{x}^T \mathbf{b}\right\} \quad (A = A^T \succ 0) \iff \mathbf{x} \sim \mathcal{N}_p(A^{-1}\mathbf{b},\, A^{-1}). (7.2)

Whenever a log-conditional density is a concave quadratic in a vector parameter 𝐱\mathbf{x}, (7.2) lets us read off its precision matrix AA and mean A−1𝐛A^{-1}\mathbf{b} in a single line.

Three panels showing bivariate normal density contours, simulated data points, and linear conditional expectation lines E[Y2 | Y1] for correlations rho equals -0.5, 0.0, and +0.5
Figure 7.1: Bivariate normal contours (𝜽=(50,50)T\boldsymbol{\theta} = (50, 50)^T, σ1=8\sigma_1 = 8, σ2=12\sigma_2 = 12) for ρ∈{−0.5,0,+0.5}\rho \in \{-0.5, 0, +0.5\}, with simulated samples and the linear conditional expectation E[Y2∣Y1=y1]=θ2+ρσ2σ1(y1−θ1)E[Y_2 \mid Y_1 = y_1] = \theta_2 + \rho\frac{\sigma_2}{\sigma_1}(y_1 - \theta_1) (dashed).

7.2Semiconjugate Priors: MVN and Inverse-Wishart

Given i.i.d. observations 𝐲1,…,𝐲n∣𝜽,Σ∼i.i.d.𝒩p(𝜽,Σ)\mathbf{y}_1, \dots, \mathbf{y}_n \mid \boldsymbol{\theta}, \Sigma \stackrel{\text{i.i.d.}}{\sim} \mathcal{N}_p(\boldsymbol{\theta}, \Sigma) stacked as the n×pn \times p data matrix 𝐘\mathbf{Y}, we place independent semiconjugate priors on the mean vector and covariance matrix:

𝜽∼𝒩p(𝝁0,Λ0),Σ∼inverse-Wishart⁡(ν0,S0−1), \boldsymbol{\theta} \sim \mathcal{N}_p(\boldsymbol{\mu}_0, \Lambda_0), \qquad \Sigma \sim \operatorname{inverse-Wishart}(\nu_0, S_0^{-1}), (7.3)

where Λ0≻0\Lambda_0 \succ 0 and S0≻0S_0 \succ 0 are symmetric positive-definite matrices and ν0>p−1\nu_0 > p - 1 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 p×pp \times p matrices? For any integer ν0≥p\nu_0 \ge p, draw ν0\nu_0 i.i.d. vectors 𝐳1,…,𝐳ν0∼𝒩p(𝟎,Ψ)\mathbf{z}_1, \dots, \mathbf{z}_{\nu_0} \sim \mathcal{N}_p(\mathbf{0}, \Psi) and sum their outer products:

𝐖=∑i=1ν0𝐳i𝐳iT=𝐙T𝐙∼Wishart⁡(ν0,Ψ),E[𝐖]=ν0Ψ. \mathbf{W} = \sum_{i=1}^{\nu_0} \mathbf{z}_i \mathbf{z}_i^T = \mathbf{Z}^T \mathbf{Z} \sim \operatorname{Wishart}(\nu_0, \Psi), \qquad E[\mathbf{W}] = \nu_0 \Psi. (7.4)

This is the exact matrix generalization of the gamma distribution (for p=1p = 1, Wishart⁡(ν0,ψ)\operatorname{Wishart}(\nu_0, \psi) is gamma⁡(ν0/2, (2ψ)−1)\operatorname{gamma}(\nu_0/2,\, (2\psi)^{-1}), and the density extends analytically to all real ν0>p−1\nu_0 > p - 1). Setting Σ=𝐖−1\Sigma = \mathbf{W}^{-1} with Ψ=S0−1\Psi = S_0^{-1} defines Hoff’s inverse-Wishart parameterization Σ∼inverse-Wishart⁡(ν0,S0−1)\Sigma \sim \operatorname{inverse-Wishart}(\nu_0, S_0^{-1}):

p(Σ)∝∣Σ∣−(ν0+p+1)/2exp⁡{−12tr⁡(S0Σ−1)},E[Σ]=1ν0−p−1S0(ν0>p+1). p(\Sigma) \propto \lvert \Sigma \rvert^{-(\nu_0 + p + 1)/2} \exp\left\{-\frac{1}{2}\operatorname{tr}(S_0 \Sigma^{-1})\right\}, \qquad E[\Sigma] = \frac{1}{\nu_0 - p - 1} S_0 \quad (\nu_0 > p + 1). (7.5)

Setting ν0=p+2\nu_0 = p + 2 gives a weakly informative prior centered at E[Σ]=S0E[\Sigma] = S_0 with finite expectation.Limitation of the inverse-Wishart prior: a single scalar ν0\nu_0 simultaneously governs our certainty about all pp diagonal variances and all p(p−1)/2p(p-1)/2 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 Σ\Sigma from the MVN likelihood, we use the cyclic invariance of the matrix trace, tr⁡(AB)=tr⁡(BA)\operatorname{tr}(AB) = \operatorname{tr}(BA):

Proposition 7.1 (The Trace Trick and MVN Full Conditionals). For any vectors 𝐲1,…,𝐲n,𝜽∈ℝp\mathbf{y}_1, \dots, \mathbf{y}_n, \boldsymbol{\theta} \in \mathbb{R}^p and symmetric matrix Σ−1\Sigma^{-1}, define the sum-of-squares matrix 𝐒𝜽=∑i=1n(𝐲i−𝜽)(𝐲i−𝜽)T\mathbf{S}_{\boldsymbol{\theta}} = \sum_{i=1}^n (\mathbf{y}_i - \boldsymbol{\theta})(\mathbf{y}_i - \boldsymbol{\theta})^T. Then

∑i=1n(𝐲i−𝜽)TΣ−1(𝐲i−𝜽)=tr⁡(𝐒𝜽Σ−1). \sum_{i=1}^n (\mathbf{y}_i - \boldsymbol{\theta})^T \Sigma^{-1} (\mathbf{y}_i - \boldsymbol{\theta}) = \operatorname{tr}(\mathbf{S}_{\boldsymbol{\theta}} \Sigma^{-1}). (7.6)

Consequently, under the semiconjugate prior (7.3), the two full conditional distributions are:

  1. Mean vector given covariance: 𝜽∣Σ,𝐘∼𝒩p(𝝁n,Λn)\boldsymbol{\theta} \mid \Sigma, \mathbf{Y} \sim \mathcal{N}_p(\boldsymbol{\mu}_n, \Lambda_n), where

    Λn=(Λ0−1+nΣ−1)−1,𝝁n=Λn(Λ0−1𝝁0+nΣ−1𝐲¯). \Lambda_n = \left(\Lambda_0^{-1} + n\Sigma^{-1}\right)^{-1}, \qquad \boldsymbol{\mu}_n = \Lambda_n\left(\Lambda_0^{-1}\boldsymbol{\mu}_0 + n\Sigma^{-1}\bar{\mathbf{y}}\right). (7.7)
  2. Covariance matrix given mean vector:

    Σ∣𝜽,𝐘∼inverse-Wishart⁡ ⁣(ν0+n,  (S0+𝐒𝜽)−1). \Sigma \mid \boldsymbol{\theta}, \mathbf{Y} \sim \operatorname{inverse-Wishart}\!\left(\nu_0 + n,\; (S_0 + \mathbf{S}_{\boldsymbol{\theta}})^{-1}\right). (7.8)

Proof. Each summand (𝐲i−𝜽)TΣ−1(𝐲i−𝜽)(\mathbf{y}_i - \boldsymbol{\theta})^T \Sigma^{-1}(\mathbf{y}_i - \boldsymbol{\theta}) is a 1×11 \times 1 scalar, so it equals its own trace. Applying tr⁡(ABC)=tr⁡(CAB)\operatorname{tr}(ABC) = \operatorname{tr}(CAB) and linearity of trace gives

∑i=1ntr⁡ ⁣((𝐲i−𝜽)TΣ−1(𝐲i−𝜽))=∑i=1ntr⁡ ⁣((𝐲i−𝜽)(𝐲i−𝜽)TΣ−1)=tr⁡(𝐒𝜽Σ−1). \sum_{i=1}^n \operatorname{tr}\!\left((\mathbf{y}_i - \boldsymbol{\theta})^T \Sigma^{-1}(\mathbf{y}_i - \boldsymbol{\theta})\right) = \sum_{i=1}^n \operatorname{tr}\!\left((\mathbf{y}_i - \boldsymbol{\theta})(\mathbf{y}_i - \boldsymbol{\theta})^T \Sigma^{-1}\right) = \operatorname{tr}(\mathbf{S}_{\boldsymbol{\theta}} \Sigma^{-1}).

For 𝜽∣Σ,𝐘\boldsymbol{\theta} \mid \Sigma, \mathbf{Y}, collecting terms in 𝜽\boldsymbol{\theta} from log⁡p(𝜽)+log⁡p(𝐘∣𝜽,Σ)\log p(\boldsymbol{\theta}) + \log p(\mathbf{Y} \mid \boldsymbol{\theta}, \Sigma) gives

−12𝜽T(Λ0−1+nΣ−1)𝜽+𝜽T(Λ0−1𝝁0+nΣ−1𝐲¯), -\frac{1}{2}\boldsymbol{\theta}^T(\Lambda_0^{-1} + n\Sigma^{-1})\boldsymbol{\theta} + \boldsymbol{\theta}^T(\Lambda_0^{-1}\boldsymbol{\mu}_0 + n\Sigma^{-1}\bar{\mathbf{y}}),

which matches (7.2) directly. For Σ∣𝜽,𝐘\Sigma \mid \boldsymbol{\theta}, \mathbf{Y}, multiplying (7.5) by ∣Σ∣−n/2exp⁡(−12tr⁡(𝐒𝜽Σ−1))\lvert \Sigma \rvert^{-n/2}\exp\bigl(-\frac{1}{2}\operatorname{tr}(\mathbf{S}_{\boldsymbol{\theta}}\Sigma^{-1})\bigr) yields

∣Σ∣−(ν0+n+p+1)/2exp⁡(−12tr⁡((S0+𝐒𝜽)Σ−1)), \lvert \Sigma \rvert^{-(\nu_0 + n + p + 1)/2}\exp\bigl(-\frac{1}{2}\operatorname{tr}((S_0 + \mathbf{S}_{\boldsymbol{\theta}})\Sigma^{-1})\bigr),

immediately recognizable as (7.8). □

Algorithm 7.2 (Two-Block MVN Gibbs Sampler). Initialize Σ(0)\Sigma^{(0)} (e.g., at the sample covariance). For s=1,…,Ss = 1, \dots, S:

  1. Compute Λn\Lambda_n and 𝝁n\boldsymbol{\mu}_n from (7.7) using Σ(s−1)\Sigma^{(s-1)} and draw 𝜽(s)∼𝒩p(𝝁n,Λn)\boldsymbol{\theta}^{(s)} \sim \mathcal{N}_p(\boldsymbol{\mu}_n, \Lambda_n).
  2. Compute 𝐒𝜽(s)=∑i=1n(𝐲i−𝜽(s))(𝐲i−𝜽(s))T\mathbf{S}_{\boldsymbol{\theta}^{(s)}} = \sum_{i=1}^n (\mathbf{y}_i - \boldsymbol{\theta}^{(s)})(\mathbf{y}_i - \boldsymbol{\theta}^{(s)})^T and draw Σ(s)∼inverse-Wishart⁡(ν0+n, (S0+𝐒𝜽(s))−1)\Sigma^{(s)} \sim \operatorname{inverse-Wishart}\bigl(\nu_0 + n,\, (S_0 + \mathbf{S}_{\boldsymbol{\theta}^{(s)}})^{-1}\bigr).

7.2.3Example: Reading Comprehension (Means vs. Individuals Revisited)

Hoff analyzes n=22n = 22 children tested before (Yi,1Y_{i,1}) and after (Yi,2Y_{i,2}) a reading program, with 𝐲¯=(47.18,53.86)T\bar{\mathbf{y}} = (47.18, 53.86)^T and sample correlation ρ^≈0.70\hat{\rho} \approx 0.70. Running Algorithm 7.2 yields Pr⁡(θ2>θ1∣𝐘)≈0.99\Pr(\theta_2 > \theta_1 \mid \mathbf{Y}) \approx 0.99—virtually certain that the population average rises—yet drawing posterior predictive pairs 𝐲~(s)∼𝒩2(𝜽(s),Σ(s))\tilde{\mathbf{y}}^{(s)} \sim \mathcal{N}_2(\boldsymbol{\theta}^{(s)}, \Sigma^{(s)}) shows Pr⁡(Y~2>Y~1∣𝐘)≈0.71\Pr(\tilde{Y}_2 > \tilde{Y}_1 \mid \mathbf{Y}) \approx 0.71: 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 𝐎\mathbf{O} be the binary observation indicator matrix (Oi,j=1O_{i,j} = 1 if Yi,jY_{i,j} is observed, 00 if missing), splitting 𝐘=(𝐘obs,𝐘mis)\mathbf{Y} = (\mathbf{Y}_{\text{obs}}, \mathbf{Y}_{\text{mis}}). 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): p(𝐎∣𝐘obs,𝐘mis,ψ)=p(𝐎∣ψ)p(\mathbf{O} \mid \mathbf{Y}_{\text{obs}}, \mathbf{Y}_{\text{mis}}, \psi) = p(\mathbf{O} \mid \psi).
  • **MAR (Missing At Random)**: p(𝐎∣𝐘obs,𝐘mis,ψ)=p(𝐎∣𝐘obs,ψ)p(\mathbf{O} \mid \mathbf{Y}_{\text{obs}}, \mathbf{Y}_{\text{mis}}, \psi) = p(\mathbf{O} \mid \mathbf{Y}_{\text{obs}}, \psi)—missingness may depend on observed values, but not on the unobserved values themselves.
  • MNAR (Missing Not At Random): missingness depends on 𝐘mis\mathbf{Y}_{\text{mis}} (e.g., high earners refusing to report income).

When the mechanism is MAR and the missingness parameter ψ\psi is prior-independent of (𝜽,Σ)(\boldsymbol{\theta}, \Sigma) (distinct parameters), the missing-data mechanism is ignorable: the factor p(𝐎∣𝐘obs,ψ)p(\mathbf{O} \mid \mathbf{Y}_{\text{obs}}, \psi) pulls completely outside the posterior for (𝜽,Σ)(\boldsymbol{\theta}, \Sigma)!

Even under ignorability, computing p(𝐘obs∣𝜽,Σ)p(\mathbf{Y}_{\text{obs}} \mid \boldsymbol{\theta}, \Sigma) directly breaks conjugacy because every row has a different subset of observed columns. Instead, data augmentation treats 𝐘mis\mathbf{Y}_{\text{mis}} 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 𝐲i,b\mathbf{y}_{i,b} given the observed entries 𝐲i,a\mathbf{y}_{i,a} in row ii? It is given by the exact Schur complement conditional normal theorem (see Appendix B):

𝐲b∣𝐲a,𝜽,Σ∼𝒩 ⁣(𝜽b+Σb,aΣa,a−1(𝐲a−𝜽a),  Σb,b−Σb,aΣa,a−1Σa,b). \mathbf{y}_b \mid \mathbf{y}_a, \boldsymbol{\theta}, \Sigma \sim \mathcal{N}\!\left( \boldsymbol{\theta}_b + \Sigma_{b,a}\Sigma_{a,a}^{-1}(\mathbf{y}_a - \boldsymbol{\theta}_a),\; \Sigma_{b,b} - \Sigma_{b,a}\Sigma_{a,a}^{-1}\Sigma_{a,b} \right). (7.9)

Algorithm 7.3 (Data-Augmentation MVN Gibbs Sampler for MAR Missing Data). Initialize 𝐘mis(0)\mathbf{Y}_{\text{mis}}^{(0)} (e.g., by column means) and Σ(0)\Sigma^{(0)}. For s=1,…,Ss = 1, \dots, S:

  1. Update 𝜽(s)\boldsymbol{\theta}^{(s)} from (7.7) using the completed matrix 𝐘(s−1)=(𝐘obs,𝐘mis(s−1))\mathbf{Y}^{(s-1)} = (\mathbf{Y}_{\text{obs}}, \mathbf{Y}_{\text{mis}}^{(s-1)}).
  2. Update Σ(s)\Sigma^{(s)} from (7.8) using 𝜽(s)\boldsymbol{\theta}^{(s)} and 𝐘(s−1)\mathbf{Y}^{(s-1)}.
  3. Impute 𝐘mis(s)\mathbf{Y}_{\text{mis}}^{(s)}: for each row ii with missing indices bib_i and observed indices aia_i, sample 𝐲i,bi(s)\mathbf{y}_{i,b_i}^{(s)} independently from the conditional MVN (7.9) given (𝐲i,ai,𝜽(s),Σ(s))(\mathbf{y}_{i,a_i}, \boldsymbol{\theta}^{(s)}, \Sigma^{(s)}).

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 𝜽\boldsymbol{\theta} and Σ\Sigma!

7.4Marginal Correlations vs. Partial Regression Coefficients

In Hoff’s Pima Indians dataset (n=200n = 200 women; p=4p = 4 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 jj given all other coordinates −j-j is linear with partial regression coefficients

𝜷j∣−j=Σ−j,−j−1Σ−j,j, \boldsymbol{\beta}_{j \mid -j} = \Sigma_{-j,-j}^{-1}\Sigma_{-j,j}, (7.10)

which can be computed directly at every Gibbs draw Σ(s)\Sigma^{(s)}! 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 ν0\nu_0 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

Σ∣𝐚∼inverse-Wishart⁡ ⁣(ν+p−1,  S𝐚−1),S𝐚=2νdiag⁡ ⁣(1a1,…,1ap),1ak∼gamma⁡ ⁣(12,1Ak2). \Sigma \mid \mathbf{a} \sim \operatorname{inverse-Wishart}\!\left(\nu + p - 1,\; S_{\mathbf{a}}^{-1}\right), \quad S_{\mathbf{a}} = 2\nu\operatorname{diag}\!\left(\tfrac{1}{a_1}, \dots, \tfrac{1}{a_p}\right), \quad \frac{1}{a_k} \sim \operatorname{gamma}\!\left(\tfrac12, \tfrac{1}{A_k^2}\right). (7.11)

Given 𝐚\mathbf{a}, Σk,k∼inverse-gamma⁡(ν/2,ν/ak)\Sigma_{k,k} \sim \operatorname{inverse-gamma}(\nu/2, \nu/a_k), and mixing over aka_k makes each standard deviation σk\sigma_k a half-tt variable with ν\nu degrees of freedom and scale AkA_k. Rescaling by a diagonal matrix leaves correlations unchanged, so each ρi,j\rho_{i,j} has density proportional to (1−r2)ν/2−1(1 - r^2)^{\nu/2 - 1} (compare Exercise 7.6): ν=2\nu = 2 makes every correlation marginally uniform. The updates stay conjugate: (7.8) with ν0=ν+p−1\nu_0 = \nu + p - 1 and S0=S𝐚S_0 = S_{\mathbf{a}}, followed by 1/ak∣Σ∼gamma⁡(ν+p2, ν(Σ−1)k,k+Ak−2)1/a_k \mid \Sigma \sim \operatorname{gamma}\bigl(\frac{\nu + p}{2},\, \nu(\Sigma^{-1})_{k,k} + A_k^{-2}\bigr).

The LKJ prior instead sets p(C)∝∣C∣η−1p(C) \propto \lvert C \rvert^{\eta - 1} on correlation matrices, independently of the scales. At η=1\eta = 1 it is uniform jointly, hence not marginally uniform for p>2p > 2.

When to use it. Keep (7.3) when S0S_0 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 Ω=Σ−1\Omega = \Sigma^{-1} 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, Ωi,j=0\Omega_{i,j} = 0 exactly when YiY_i and YjY_j are conditionally independent, so sparsity in Ω\Omega is sparsity in the coefficients (7.10). Restricted to Ω≻0\Omega \succ 0, the prior is flat on each Ωi,i\Omega_{i,i}, with Ωi,j∣λi,j,τ∼𝒩(0,λi,j2τ2)\Omega_{i,j} \mid \lambda_{i,j}, \tau \sim \mathcal{N}(0, \lambda_{i,j}^2\tau^2) for i<ji < j and half-Cauchy λi,j\lambda_{i,j} and τ\tau. Write 𝐒=𝐒𝜽\mathbf{S} = \mathbf{S}_{\boldsymbol{\theta}}, single out the last row and column, and let 𝝎=Ω−p,p\boldsymbol{\omega} = \Omega_{-p,p}, γ=Ωp,p−𝝎TΩ−p,−p−1𝝎\gamma = \Omega_{p,p} - \boldsymbol{\omega}^T\Omega_{-p,-p}^{-1}\boldsymbol{\omega}, and D=diag⁡(λi,p2τ2)D = \operatorname{diag}(\lambda_{i,p}^2\tau^2). Then, given the rest,

γ∼gamma⁡ ⁣(n2+1, 𝐒p,p2),𝝎∼𝒩p−1(−G 𝐒−p,p, G),G=(𝐒p,p Ω−p,−p−1+D−1)−1. \gamma \sim \operatorname{gamma}\!\left(\tfrac{n}{2} + 1,\, \tfrac{\mathbf{S}_{p,p}}{2}\right), \qquad \boldsymbol{\omega} \sim \mathcal{N}_{p-1}\bigl(-G\,\mathbf{S}_{-p,p},\, G\bigr), \qquad G = \bigl(\mathbf{S}_{p,p}\,\Omega_{-p,-p}^{-1} + D^{-1}\bigr)^{-1}. (7.12)

Why? ∣Ω∣=γ ∣Ω−p,−p∣\lvert \Omega \rvert = \gamma\,\lvert \Omega_{-p,-p} \rvert, and the trace (7.6) contributes 2𝐒−p,pT𝝎+𝐒p,p(γ+𝝎TΩ−p,−p−1𝝎)2\mathbf{S}_{-p,p}^T\boldsymbol{\omega} + \mathbf{S}_{p,p}(\gamma + \boldsymbol{\omega}^T\Omega_{-p,-p}^{-1}\boldsymbol{\omega}); now apply (7.2). Because γ>0\gamma > 0, every draw is positive definite. Cycle over columns; inverse-gamma auxiliary variables handle λi,j\lambda_{i,j} and τ\tau.

When to use it. For the four Pima variables an inverse-Wishart is enough. Use the graphical horseshoe when pp is comparable to or larger than nn 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 (𝐨~,𝐲~obs)(\tilde{\mathbf{o}}, \tilde{\mathbf{y}}_{\text{obs}}) be the pattern and values actually observed. Realized MAR requires Pr⁡(𝐎=𝐨~∣𝐲~obs,𝐲mis,ψ)\Pr(\mathbf{O} = \tilde{\mathbf{o}} \mid \tilde{\mathbf{y}}_{\text{obs}}, \mathbf{y}_{\text{mis}}, \psi) to be constant in 𝐲mis\mathbf{y}_{\text{mis}}, for every ψ\psi; everywhere MAR requires this for every pattern and every data set that could have occurred. Under realized MAR,

p(𝜽,Σ,ψ∣𝐲~obs,𝐨~)∝p(ψ)Pr⁡(𝐨~∣𝐲~obs,ψ)×p(𝜽,Σ) ⁣∫ ⁣p(𝐲~obs,𝐲mis∣𝜽,Σ) d𝐲mis, p(\boldsymbol{\theta}, \Sigma, \psi \mid \tilde{\mathbf{y}}_{\text{obs}}, \tilde{\mathbf{o}}) \propto p(\psi)\Pr(\tilde{\mathbf{o}} \mid \tilde{\mathbf{y}}_{\text{obs}}, \psi) \times p(\boldsymbol{\theta}, \Sigma)\!\int\! p(\tilde{\mathbf{y}}_{\text{obs}}, \mathbf{y}_{\text{mis}} \mid \boldsymbol{\theta}, \Sigma)\,d\mathbf{y}_{\text{mis}}, (7.13)

given prior-independent ψ\psi. The mechanism is constant in 𝐲mis\mathbf{y}_{\text{mis}}, so it leaves the integral, and the posterior is evaluated only at 𝐨~\tilde{\mathbf{o}}: 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 3030. If every pretest in our sample was fully observed and exceeded 3030, 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 𝐎\mathbf{O} explicitly. Hoff’s single MAR condition does not draw this distinction.

7.5.4Computational & Symbolic Check

The script simulates (7.11) with p=ν=2p = \nu = 2, testing ρ\rho against the uniform and σ1\sigma_1 against the half-t2t_2 distribution, and then draws 3×33 \times 3 correlation matrices uniformly (LKJ, η=1\eta = 1). For p=2p = 2 the LKJ density of ρ\rho is proportional to (1−ρ2)η−1(1 - \rho^2)^{\eta - 1}; for general pp the exponent becomes η−2+p/2\eta - 2 + p/2, so at p=3p = 3, η=1\eta = 1 the marginal variance is 14\frac14 rather than the uniform’s 13\frac13.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)")
After the change of variables Σ↦(σ1,σ2,ρ)\Sigma \mapsto (\sigma_1, \sigma_2, \rho), each scale is integrated out by this one-dimensional integral.
// 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}]]]`
∫0∞s−(ν+2)e−k/s2 ds=12k−1+ν2Γ(1+ν2) \int_0^\infty s^{-(\nu+2)} e^{-k/s^2}\,ds = \frac{1}{2} k^{-\frac{1+\nu}{2}} \Gamma \left(\frac{1+\nu}{2}\right) Assemble the kernel of ρ\rho: the factor (1−ρ2)−(ν+4)/2(1 - \rho^2)^{-(\nu+4)/2} times both integrated scales, with k=ν/[aj(1−ρ2)]k = \nu/[a_j(1 - \rho^2)]; a1,a2a_1, a_2 enter only as constants.
const rhoKer = await show`(1 - r^2)^(-(nu + 4)/2) * (${sInt} /. k -> nu/(a1*(1 - r^2))) * (${sInt} /. k -> nu/(a2*(1 - r^2)))`
p(ρ∣a1,a2)∝14(1−ρ2)−4+ν2(νa1(1−ρ2))−1+ν2(νa2(1−ρ2))−1+ν2Γ(1+ν2)2 \begin{aligned} &p(\rho \mid a_1, a_2) \propto \\ &\frac{1}{4} \left(1-\rho^2\right)^{-\frac{4+\nu}{2}} \left(\frac{\nu}{a_1 (1-\rho^2)}\right)^{-\frac{1+\nu}{2}} \left(\frac{\nu}{a_2 (1-\rho^2)}\right)^{-\frac{1+\nu}{2}} \Gamma \left(\frac{1+\nu}{2}\right)^2 \end{aligned} Check that the log-ratio of this kernel to (1−ρ2)ν/2−1(1 - \rho^2)^{\nu/2 - 1} has zero derivative in ρ\rho.
await show`Assuming[nu > 0 && a1 > 0 && a2 > 0 && -1 < r < 1,
  FullSimplify[D[Log[${rhoKer} / (1 - r^2)^(nu/2 - 1)], r]]]`
ddρlog⁡ ⁣(p(ρ∣a1,a2)(1−ρ2)ν/2−1)=0 \frac{d}{d\rho}\log\!\left(\frac{p(\rho \mid a_1, a_2)}{(1 - \rho^2)^{\nu/2 - 1}}\right) = 0 Normalize (1−ρ2)η−1(1 - \rho^2)^{\eta - 1}: the LKJ density for p=2p = 2, which is also Huang–Wand with η=ν/2\eta = \nu/2.
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}]]]`
p(ρ∣η)=(1−ρ2)−1+ηΓ(12+η)πΓ(η) p(\rho \mid \eta) = \frac{\left(1-\rho^2\right)^{-1+\eta} \Gamma \left(\frac{1}{2}+\eta\right)}{\sqrt{\pi} \Gamma (\eta)} Instantiate at η=1\eta = 1 (Huang–Wand with ν=2\nu = 2: uniform) and at η=2\eta = 2 (concentrated near zero).
await show`{${rhoDen} /. eta -> 1, ${rhoDen} /. eta -> 2}`
(p(ρ∣η=1),  p(ρ∣η=2))={12,34(1−ρ2)} \bigl(p(\rho \mid \eta = 1),\; p(\rho \mid \eta = 2)\bigr) = \left\{\frac{1}{2},\frac{3}{4} \left(1-\rho^2\right)\right\} Evaluate Var⁡(ρ)\operatorname{Var}(\rho) at η=1\eta = 1 and at the effective exponent η=32\eta = \frac32 that LKJ(1)(1) induces when p=3p = 3.
await show`Table[Integrate[r^2*(${rhoDen} /. eta -> e), {r, -1, 1}], {e, {1, 3/2}}]`
(Var⁡(ρ)p=2,  Var⁡(ρ)p=3)LKJ(1)={13,14} \bigl(\operatorname{Var}(\rho)_{p=2},\; \operatorname{Var}(\rho)_{p=3}\bigr)_{\text{LKJ}(1)} = \left\{\frac{1}{3},\frac{1}{4}\right\}

7.6Symbolic Check in Wolfram Language

Verifies symbolically for a general 3×33 \times 3 covariance matrix Σ\Sigma in wolfram-ws-bridge JavaScript mode that the Schur-complement partial regression vector equals −Ω1,1−1Ω1,23T-\Omega_{1,1}^{-1}\Omega_{1,23}^T, derives the general 2×22 \times 2 conditional slope and conditional variance symbolically in terms of (s1,s2,ρ)(s_1, s_2, \rho), and instantiates them on Hoff’s reading-comprehension covariance.

Compute the symbolic 3×33 \times 3 Schur regression slope vector Σ23,23−1Σ23,1\Sigma_{23,23}^{-1}\Sigma_{23,1}.
// 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}]`
βSchur=Σ23,23−1Σ23,1={Σ13Σ23−Σ12Σ33Σ232−Σ22Σ33,Σ13Σ22−Σ12Σ23−Σ232+Σ22Σ33} \begin{aligned} &\beta_{\text{Schur}} = \Sigma_{23,23}^{-1}\Sigma_{23,1} \\ &= \left\{\frac{\Sigma_{13} \Sigma_{23} -\Sigma_{12} \Sigma_{33}}{\Sigma_{23}^2-\Sigma_{22} \Sigma_{33}},\frac{\Sigma_{13} \Sigma_{22} -\Sigma_{12} \Sigma_{23}}{-\Sigma_{23}^2+\Sigma_{22} \Sigma_{33}}\right\} \end{aligned} Compute the precision-based slope vector −Ω11−1Ω1,23-\Omega_{11}^{-1}\Omega_{1,23} from the inverse covariance Ω=Σ−1\Omega = \Sigma^{-1}.
const betaPrec = await show`FullSimplify[-Inverse[${Sig}][[1, {2, 3}]] / Inverse[${Sig}][[1, 1]]]`
βprec=−Ω11−1Ω1,23={Σ13Σ23−Σ12Σ33Σ232−Σ22Σ33,Σ13Σ22−Σ12Σ23−Σ232+Σ22Σ33} \begin{aligned} &\beta_{\text{prec}} = -\Omega_{11}^{-1}\Omega_{1,23} \\ &= \left\{\frac{\Sigma_{13} \Sigma_{23} -\Sigma_{12} \Sigma_{33}}{\Sigma_{23}^2-\Sigma_{22} \Sigma_{33}},\frac{\Sigma_{13} \Sigma_{22} -\Sigma_{12} \Sigma_{23}}{-\Sigma_{23}^2+\Sigma_{22} \Sigma_{33}}\right\} \end{aligned} Verify that the Schur slope vector equals −Ω11−1Ω1,23-\Omega_{11}^{-1}\Omega_{1,23}: the difference vanishes identically.
await show`FullSimplify[${betaSchur} - ${betaPrec}]`
βSchur−(−Ω11−1Ω1,23)={0,0} \beta_{\text{Schur}} - \bigl(-\Omega_{11}^{-1}\Omega_{1,23}\bigr) = \{0,0\} Derive the symbolic conditional regression slope β2∣1=ρ σ2/σ1\beta_{2\mid 1} = \rho\,\sigma_2/\sigma_1 for a 2×22 \times 2 normal.
// 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]]]`
β2∣1=Σ1,2Σ1,1=ρσ2σ1 \beta_{2 \mid 1} = \frac{\Sigma_{1,2}}{\Sigma_{1,1}} = \frac{\rho \sigma_2}{\sigma_1} Derive the symbolic conditional variance Var⁡(Y2∣Y1)=(1−ρ2)σ22\operatorname{Var}(Y_2 \mid Y_1) = (1 - \rho^2)\sigma_2^2.
const cvarSym = await show`FullSimplify[${covSym}[[2, 2]] - ${covSym}[[1, 2]]^2 / ${covSym}[[1, 1]]]`
Var⁡(Y2∣Y1)=Σ2,2−Σ1,22Σ1,1=−((−1+ρ2)σ22) \begin{aligned} &\operatorname{Var}(Y_2 \mid Y_1) = \Sigma_{2,2} - \frac{\Sigma_{1,2}^2}{\Sigma_{1,1}} \\ &= -\left(\left(-1+\rho^2\right) \sigma_2^2\right) \end{aligned} Instantiate the conditional slope and conditional SD on Hoff’s reading-comprehension covariance.
// 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]}]`
(β2∣1,  SD⁡(Y2∣Y1))reading={0.809453,11.1488} \begin{aligned} &\bigl(\beta_{2\mid 1},\; \operatorname{SD}(Y_2 \mid Y_1)\bigr)_{\text{reading}} \\ &= \{0.809453,11.1488\} \end{aligned}

7.7Exercises

Exercise 7.4. Let Ω=Σ−1\Omega = \Sigma^{-1} be the precision matrix of 𝐘∼𝒩p(𝜽,Σ)\mathbf{Y} \sim \mathcal{N}_p(\boldsymbol{\theta}, \Sigma). Using the block-matrix inversion identity, show that the partial regression vector in (7.10) satisfies 𝜷j∣−j=−Ωj,j−1Ωj,−jT\boldsymbol{\beta}_{j \mid -j} = -\Omega_{j,j}^{-1}\Omega_{j,-j}^T, and deduce that YiY_i and YjY_j are conditionally independent given all remaining variables if and only if Ωi,j=0\Omega_{i,j} = 0.

Symbolic Solution & InstantiationInvert a general symbolic 3×33 \times 3 covariance Σ\Sigma: the precision Ω\Omega is the adjugate over Δ=det⁡Σ\Delta = \det\Sigma.
// 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}]`
Ω=Σ−1=1Δ(Σ22Σ33−Σ232Σ13Σ23−Σ12Σ33Σ12Σ23−Σ13Σ22Σ13Σ23−Σ12Σ33Σ11Σ33−Σ132Σ12Σ13−Σ11Σ23Σ12Σ23−Σ13Σ22Σ12Σ13−Σ11Σ23Σ11Σ22−Σ122),Δ=−Σ132Σ22+2Σ12Σ13Σ23−Σ11Σ232−Σ122Σ33+Σ11Σ22Σ33 \begin{aligned} &\Omega = \Sigma^{-1} = \frac{1}{\Delta}\left( \begin{array}{ccc} \Sigma_{22}\Sigma_{33}-\Sigma_{23}^2 & \Sigma_{13}\Sigma_{23}-\Sigma_{12}\Sigma_{33} & \Sigma_{12}\Sigma_{23}-\Sigma_{13}\Sigma_{22} \\ \Sigma_{13}\Sigma_{23}-\Sigma_{12}\Sigma_{33} & \Sigma_{11}\Sigma_{33}-\Sigma_{13}^2 & \Sigma_{12}\Sigma_{13}-\Sigma_{11}\Sigma_{23} \\ \Sigma_{12}\Sigma_{23}-\Sigma_{13}\Sigma_{22} & \Sigma_{12}\Sigma_{13}-\Sigma_{11}\Sigma_{23} & \Sigma_{11}\Sigma_{22}-\Sigma_{12}^2 \\ \end{array} \right), \\ &\Delta = -\Sigma_{13}^2\Sigma_{22}+2\Sigma_{12}\Sigma_{13}\Sigma_{23}-\Sigma_{11}\Sigma_{23}^2-\Sigma_{12}^2\Sigma_{33}+\Sigma_{11}\Sigma_{22}\Sigma_{33} \end{aligned} Form the covariance-side slope Σ1,23Σ23,23−1\Sigma_{1,23}\Sigma_{23,23}^{-1} from the 2×22 \times 2 block inverse.
const betaCov = await show`${Sig}[[1, {2, 3}]] . Inverse[${Sig}[[{2, 3}, {2, 3}]]]`
Σ1,23Σ23,23−1={Σ12Σ33−Σ13Σ23Σ22Σ33−Σ232,Σ13Σ22−Σ12Σ23Σ22Σ33−Σ232} \Sigma_{1,23}\Sigma_{23,23}^{-1} = \left\{\frac{\Sigma_{12}\Sigma_{33}-\Sigma_{13}\Sigma_{23}}{\Sigma_{22}\Sigma_{33}-\Sigma_{23}^2},\frac{\Sigma_{13}\Sigma_{22}-\Sigma_{12}\Sigma_{23}}{\Sigma_{22}\Sigma_{33}-\Sigma_{23}^2}\right\} Form the precision-side slope −Ω11−1Ω1,23-\Omega_{11}^{-1}\Omega_{1,23}: the common factor 1/Δ1/\Delta cancels.
const betaPrec = await show`-${Om}[[1, {2, 3}]] / ${Om}[[1, 1]]`
−Ω11−1Ω1,23={−Σ13Σ23−Σ12Σ33Σ22Σ33−Σ232,−Σ12Σ23−Σ13Σ22Σ22Σ33−Σ232} -\Omega_{11}^{-1}\Omega_{1,23} = \left\{-\frac{\Sigma_{13}\Sigma_{23}-\Sigma_{12}\Sigma_{33}}{\Sigma_{22}\Sigma_{33}-\Sigma_{23}^2},-\frac{\Sigma_{12}\Sigma_{23}-\Sigma_{13}\Sigma_{22}}{\Sigma_{22}\Sigma_{33}-\Sigma_{23}^2}\right\} Verify Σ1,23Σ23,23−1−(−Ω11−1Ω1,23)=𝟎\Sigma_{1,23}\Sigma_{23,23}^{-1} - (-\Omega_{11}^{-1}\Omega_{1,23}) = \mathbf{0}.
await show`FullSimplify[${betaCov} - ${betaPrec}]`
Σ1,23Σ23,23−1−(−Ω11−1Ω1,23)={0,0} \Sigma_{1,23}\Sigma_{23,23}^{-1} - \bigl(-\Omega_{11}^{-1}\Omega_{1,23}\bigr) = \{0,0\}

Exercise 7.5. Extend the Python script above to create 20%20\% missing entries in column 2 under (a) MCAR (uniform random mask), (b) MAR (missing with higher probability when Yi,1Y_{i,1} is in its bottom quartile), and (c) MNAR (missing whenever Yi,2Y_{i,2} falls below its 20th percentile). Implement Algorithm 7.3 and compare its posterior for 𝜽\boldsymbol{\theta} against complete-case analysis across all three regimes.

Symbolic Solution & InstantiationIntegrate z ϕ(z)z\,\phi(z) over (z0,∞)(z_0, \infty) to derive the inverse Mills ratio bias E[Z∣Z>z0]E[Z \mid Z > z_0] 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}]]]`
𝔼[Z∣Z>z0]=e−z0222πerfc⁡(z02) \begin{aligned} &\mathbb{E}[Z \mid Z > z_0] \\ &= \frac{e^{-\frac{z_0^2}{2}} \sqrt{\frac{2}{\pi}}}{\operatorname{erfc} \left(\frac{z_0}{\sqrt{2}}\right)} \end{aligned} Solve Φ(z)=15\Phi(z) = \tfrac15 for the 20%20\% standard normal quantile z0.20z_{0.20}.
const z20 = await show`z /. FindRoot[1/2*Erfc[-z/Sqrt[2]] == 1/5, {z, -0.84}]`
z0.20:  12erfc⁡ ⁣(−z2)=15  ⟹  z=−0.841621 z_{0.20} : \; \tfrac12\operatorname{erfc}\!\left(-\tfrac{z}{\sqrt{2}}\right) = \tfrac15 \;\Longrightarrow\; z = -0.841621 Evaluate the resulting MNAR upward bias 𝔼[Z∣Z>z0.20]\mathbb{E}[Z \mid Z > z_{0.20}].
await show`N[{${z20}, ${shift} /. z0 -> ${z20}}]`
(z0.20,  𝔼[Z∣Z>z0.20])={−0.841621,0.349952} \bigl(z_{0.20},\; \mathbb{E}[Z \mid Z > z_{0.20}]\bigr) = \{-0.841621,0.349952\}

Exercise 7.6. For p=3p = 3 and S0=I3S_0 = I_3, simulate 10,00010{,}000 draws from Σ∼inverse-Wishart⁡(ν0,S0−1)\Sigma \sim \operatorname{inverse-Wishart}(\nu_0, S_0^{-1}) for ν0∈{4,6,20}\nu_0 \in \{4, 6, 20\} and inspect the implied prior distribution of the off-diagonal correlation ρ1,2=Σ1,2/Σ1,1Σ2,2\rho_{1,2} = \Sigma_{1,2}/\sqrt{\Sigma_{1,1}\Sigma_{2,2}}. Why does ν0=p+1=4\nu_0 = p + 1 = 4 produce a uniform marginal prior on each correlation ρi,j∈(−1,1)\rho_{i,j} \in (-1, 1)?

Symbolic Solution & InstantiationRecord the exponent (ν0−p−1)/2(\nu_0 - p - 1)/2 of (1−r2)(1 - r^2) in the marginal correlation prior under IW⁡(ν0,Ip)\operatorname{IW}(\nu_0, I_p).
// 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`
Exponent of (1−r2) in p(r)=12(−1+ν0−p) \text{Exponent of } (1 - r^2) \text{ in } p(r) = \frac{1}{2} (-1+\nu_0 -p) Integrate (1−r2)(ν0−p−1)/2(1 - r^2)^{(\nu_0 - p - 1)/2} over (−1,1)(-1, 1) to obtain its Beta normalizing constant.
await show`Assuming[nu0 > p - 1, FullSimplify[Integrate[(1 - r^2)^((nu0 - p - 1)/2), {r, -1, 1}]]]`
∫−11(1−r2)(ν0−p−1)/2 dr=πΓ(12(1+ν0−p))Γ(12(2+ν0−p)) \begin{aligned} &\int_{-1}^1 (1 - r^2)^{(\nu_0 - p - 1)/2}\,dr \\ &= \frac{\sqrt{\pi} \Gamma \left(\frac{1}{2} (1+\nu_0 -p)\right)}{\Gamma \left(\frac{1}{2} (2+\nu_0 -p)\right)} \end{aligned} Evaluate the exponent at p=3p = 3 for ν0∈{4,6,20}\nu_0 \in \{4, 6, 20\} (from uniform to concentrated near zero).
await show`Table[${expSym} /. {p -> 3, nu0 -> v}, {v, {4, 6, 20}}]`
(ν0−p−12)p=3,  ν0∈{4, 6, 20}={0,1,8} \left(\frac{\nu_0 - p - 1}{2}\right)_{p=3,\; \nu_0 \in \{4,\, 6,\, 20\}} = \{0,1,8\}