Every chapter of Hoff’s course rests on five compact mathematical pillars: iterated expectation and Jensen’s inequality, kernel recognition via Bayes’ rule, change-of-variables calculus with special functions, positive-definite linear algebra, and the ergodic theory of Monte Carlo and Markov chains. While Notation and Conventions catalogues symbols and parameterization conventions and Appendix A and Appendix B serve as quick-reference sheets, this introductory chapter derives each prerequisite from first principles and verifies it symbolically and numerically in the Wolfram Language (wolfram-ws-bridge JavaScript mode).All eleven working examples below are collected in wolfram_prereqs.mjs and were evaluated live against the Wolfram kernel with zero console.log calls—each symbolic derivation and numerical instantiation appears as a KaTeX equation directly beneath its await show call.
0.4Probability, Expectation, and Jensen’s Inequality#
A Bayesian model specifies a joint distribution over observable data and latent unknowns, then extracts marginals by integrating out nuisance variables, , and conditionals by slicing and renormalizing, . Two variables are conditionally independent given when —the structural backbone of exchangeability in Chapter 2, hierarchical modeling in Chapter 8, and graphical copulas in Chapter 12.
Theorem1(Laws of Total Expectation and Total Variance). Let and be random variables on a common probability space.
If , then .
If , then
Proof sketch. Expanding and applying part 1 to both and , add and subtract to separate the average within-group variance from the between-group variance .
Corollary2(Information Reduces Variance on Average). For any square-integrable parameter and data ,, with strict inequality whenever is non-constant. This holds on average over ; a single surprising observation can increase relative to .
The variance decomposition reappears throughout the book: posterior predictive overdispersion in Chapter 3, Rao–Blackwellization in Chapter 4, MSE decomposition in Chapter 5, within/between-school variance in Chapter 8, and nested GLMM predictive variance in Chapter 11.
0.4.1Working Example 1a: Total Variance of a Mixture#
Consider the three-component normal mixture from Chapter 6 with weights , means , and variances . We verify symbolically that splits into within-component and between-component terms, rewrite the between-component variance as a pairwise sum , and instantiate on Hoff’s trimodal target (,,):
Write the density of a single mixture component.
// 1a. Law of total variance on Chapter 6's trimodal normal mixture
const{x,m,v}=Wconstphi=awaitshow`Exp[-(${x} - ${m})^2/(2*${v})]/Sqrt[2*Pi*${v}]`
Compute the first two raw moments of a component by symbolic integration.
Because by symmetry, . Nearly of the variance ( out of ) lives between modes—explaining why a Gibbs sampler trapped in a single mode drastically underestimates posterior uncertainty.
Theorem3(Jensen’s Inequality). If is convex on an interval containing the support of and both and are finite, then . If is strictly convex, equality holds if and only if is almost surely constant. (For concave , the inequality reverses.)
Proof sketch. Choose a supporting line at and take expectations of both sides; the linear term vanishes.
Jensen’s inequality governs every nonlinear reparameterization in the book: log-odds versus probability in Chapter 4, variance versus precision in Chapter 5, and population-averaged rate versus typical-group rate in Chapter 11.
0.4.2Working Example 1b: Two Jensen Gaps for a Gamma Precision#
For (shape , rate ), is strictly convex while is strictly concave. Computing both expectations symbolically exposes the exact Jensen gaps, which we instantiate at the midge precision posterior :
Write the density in shape–rate form.
// 1b. Two Jensen gaps for a Gamma(a, b) precision random variable
const{a,b,x}=Wconstdens=awaitshow`${b}^${a}/Gamma[${a}]*${x}^(${a} - 1)*Exp[-${b}*${x}]`
Integrate against a density to obtain symbolically.
Evaluate both Jensen gaps numerically at the midge precision posterior .
awaitshow`N[${gaps} /. {a -> 5, b -> 3/40}]`
0.5Conditioning, Bayes’ Rule, and Kernel Recognition#
Bayes’ rule turns a generative model and prior into the posterior
Dividing two hypotheses cancels and yields (used in Chapter 2 and Chapter 9). When observations are conditionally independent given , updating sequentially with and then produces the exact same posterior as updating in a single batch with .
Proposition4(Kernel Uniqueness). Suppose a density satisfies as a function of . If , then uniquely. If , no proper posterior exists.
The integrability clause is not a technicality: Chapter 6 shows an improper prior whose full conditionals are all proper while the joint kernel integrates to .
Proposition5(Score Identification). Two strictly positive densities on the same connected open support are identical if and only if their log-gradients (scores) agree everywhere: .
Every full-conditional derivation in Parts II and III works by matching one of three score fingerprints:
Beta():,
Gamma():,
Normal(): (linear coefficient , precision ).
Remark6(What may—and may not—be dropped). A multiplicative factor may be absorbed into only if it does not depend on the variable currently being conditioned on. The marginal likelihood drops out when normalizing within a single model, but it is the exact quantity that drives Bayes factors and model averaging across competing models in Chapter 9.
0.5.1Working Example 2a: Normal Kernel Normalization and Precision Weighting#
Integrating the unnormalized normal kernel yields its log-normalizer , whose first two -derivatives immediately return the mean and variance . Substituting the sum of prior and data precisions reproduces the conjugate normal posterior of Chapter 5:
Integrate the unnormalized normal kernel to find its normalizing constant .
0.5.2Working Example 2b: Score Fingerprints and Marginal Evidence#
We verify all three conjugate score fingerprints simultaneously (Beta–Binomial, Gamma–Poisson, Normal–Normal), and then confirm that dividing the joint density by the recognized posterior recovers the exact marginal evidence —instantiated on the rare-infection example () of Chapter 1:
Write the three log joint kernels : Beta–Binomial, Gamma–Poisson, Normal–Normal.
Integrate out to compute the exact Beta–Binomial marginal likelihood .
constpy=awaitshow`Assuming[a > 0 && b > 0 && n >= y >= 0,
Integrate[${joint}, {t, 0, 1}] /. Gamma[b + n - y]*Gamma[a + y] -> Beta[a + y, b + n - y]*Gamma[a + b + n]]`
Confirm that dividing the joint density by the normalized posterior recovers identically.
awaitshow`Assuming[a > 0 && b > 0 && n >= y >= 0 && 0 < t < 1,
FullSimplify[${joint}/(t^(a + y - 1)*(1 - t)^(b + n - y - 1)/Beta[a + y, b + n - y]) - ${py}]]`
Evaluate the marginal evidence and posterior mean on Chapter 1’s rare-infection dataset ().
awaitshow`N[{${py}, (a + y)/(a + b + n)} /. {a -> 2, b -> 20, n -> 20, y -> 0}]`
0.6Transformations, Special Functions, and Log-Concavity#
Working in Bayesian inference constantly requires switching parameter scales—from probability to log-odds (Chapter 4), from precision to variance (Chapter 5), from centered to non-centered (Chapter 8), and from positive to in Metropolis–Hastings proposals (Chapter 10).
Theorem7(Change of Variables). Let be a diffeomorphism between open subsets of , and let have density on . Then has density
Remark8(What commutes with reparameterization). Quantiles are equivariant under strictly increasing maps (), while strictly decreasing maps send the -quantile to the -quantile. By contrast, modes, HPD intervals, and means are not invariant: the Jacobian factor shifts peaks and tilts density contours (a theme explored in Chapter 3 and Chapter 4).
Three special-function identities underpin almost every closed-form integral in Parts I–III:
Gamma recursion: for , with and .
Beta–Gamma identity:
Gaussian integral: squaring and switching to polar coordinates gives
Proposition9(Log-Concavity and Unimodality). A density is log-concave if is concave on its support. Log-concavity is preserved under products (priors times likelihoods), affine pre-composition (), and marginalization (Prékopa’s theorem). A strictly log-concave density has at most one mode (existence also requires that the supremum be attained in the interior).
Log-concavity guarantees well-behaved posterior geometry in GLMs (Chapter 10) and ordered probit models (Chapter 12), though it is sufficient rather than necessary for unimodality: both the inverse-gamma and Student- densities are unimodal yet not globally log-concave.
0.6.1Working Example 3a: Gamma Precision on Three Scales#
Starting from , we transform to variance and log-precision . Notice how the modes fail to commute () whereas the medians match identically, and how is strictly log-concave for every (while requires and is never globally log-concave). Here is the midge posterior with , and Wolfram’s GammaDistribution uses scale:
Write the density of the precision .
// 3a. Gamma precision on three scales: precision, variance, and log-precision
constpx=awaitshow`b^a/Gamma[a]*x^(a - 1)*Exp[-b*x]`
Apply the 1-D change-of-variables formula to map to variance .
constpv=awaitshow`Assuming[a > 0 && b > 0 && v > 0, FullSimplify[(${px} /. x -> 1/v)*Abs[D[1/v, v]]]]`
Verify that the resulting inverse-gamma density integrates to over .
From Chapter 7 onward, scalar variances become symmetric positive-definite (SPD) covariance matrices , precisions become , and regression projections become idempotent matrices .
Proposition10(Characterizations of Positive-Definite Matrices). For a real symmetric matrix , the following are equivalent: (i) for all ; (ii) all eigenvalues of are strictly positive; (iii) all leading principal minors of are strictly positive; (iv) for a unique lower-triangular Cholesky factor with strictly positive diagonal entries.
Cholesky factorization turns standard normal draws into arbitrary multivariate normals without explicitly inverting large matrices:
Covariance form: if , then .
Precision form: if , then .
Completing the square ((B.2) in Appendix B) expands around using symmetry , immediately giving the multivariate Gaussian integral
Theorem11(Schur Complement Factorization). Partition an SPD matrix and vector into blocks and , with Schur complement and residual . Then
Together, those two identities are the marginal conditional factorization of the multivariate normal density powering missing-data imputation in Chapter 7 and partial correlations in Chapter 12.
Theorem12(Orthogonal Projection and Zellner’s g-Prior Identity). Let have full column rank , and set . Then is symmetric and idempotent (), has , and satisfies . Because its eigenvalues lie in ( ones and zeros), for every ,
This theorem gives the entire closed-form marginal likelihood and formula of Chapter 9 in two lines.
0.7.1Working Example 4a: Vector Completing the Square and Cholesky#
We verify completing the square in and compute the symbolic lower-triangular Cholesky factor of a covariance matrix (note that Wolfram’s CholeskyDecomposition returns the upper factor with , so we transpose it), instantiated on the reading-comprehension prior of Chapter 7:
Solve the linear system symbolically for the quadratic center.
// 4a. Completing the square in R^2 and symbolic Cholesky factorization
constx=[W.x1,W.x2],b=[W.b1,W.b2],A=[[W.a11,W.a12],[W.a12,W.a22]]constm=awaitshow`Simplify[Inverse[${A}] . ${b}]`
Verify the vector completing-the-square identity in by symbolic simplification.
0.7.2Working Example 4b: Schur Complement and Projection Matrix #
First we verify both Schur-complement identities on a general symbolic covariance matrix , then instantiate at ,,—where the regression coefficient on vanishes (), proving despite :
Compute the regression coefficients of on for a general symmetric .
When posterior integrals lack closed forms, Parts I–III replace exact calculus with simulation—first via independent draws (Chapter 4) and then via Markov chains (Chapter 6–Chapter 12).
Theorem13(Strong Law and Central Limit Theorem for i.i.d. Monte Carlo). Let and set . If , then almost surely. If , then
a convergence rate of that is independent of parameter dimension.
When direct sampling from is impossible, we construct a Markov chain with transition kernel that leaves stationary (invariant): , i.e., . A stronger, easily checked sufficient condition is detailed balance (reversibility):
Integrating both sides over immediately yields . The converse fails: a systematic-scan Gibbs sampler (Chapter 6) is generally stationary without being reversible.
Theorem14(Ergodic Theorem for Markov Chains). Let be an invariant probability distribution of a -irreducible Markov chain with transition kernel .
For every -integrable function , time averages converge almost surely: from -almost every starting state (no aperiodicity required).
If in addition the chain is aperiodic, the -step distribution converges in total variation: from -almost every start.
If the chain is Harris recurrent, both conclusions hold from every starting state .
Remark15(Why aperiodicity separates averages from distributions). The deterministic two-state flip
is irreducible with invariant distribution : its ergodic averages converge to , yet oscillates forever and never converges in total variation.
Proposition16(Asymptotic Variance and Effective Sample Size). For a stationary Markov chain with lag- autocorrelations satisfying ,
When negative autocorrelations dominate (antithetic sampling), can exceed . A Markov chain CLT requires stronger mixing—for example, geometric ergodicity together with .
0.8.1Working Example 5a: Exact Finite- Variance Inflation and ESS#
For geometric autocorrelation (), we sum the exact finite- variance inflation factor , take its limit , cross-check against the Toeplitz correlation matrix , and tabulate at —ending with the bivariate normal Gibbs chain of Chapter 6 where collapses draws to roughly effective draws:
Sum the exact finite- variance inflation factor for geometric autocorrelation .
0.8.2Working Example 5b: A Three-State Metropolis Chain#
Finally, consider a three-state target ordered so , with uniform proposal to either of the two other states (probability each) and Metropolis acceptance . We construct the exact transition matrix , verify detailed balance and stationarity symbolically, compute its closed-form spectrum , and evaluate the total-variation distance at :
Build the exact Metropolis transition matrix for ordered target probabilities .
Notice that the four total-variation errors equal exactly—shrinking at every step by the subdominant eigenvalue magnitude , a concrete preview of the Metropolis–Hastings convergence machinery developed in Chapter 10.