Chapter 2

Belief, Probability, and Exchangeability

Before computing posteriors, we must answer two foundational questions: Why should degrees of rational belief obey the mathematical axioms of probability? And why do Bayesian statisticians write down conditionally i.i.d. sampling models Y1,…,Yn∣θ∼i.i.d.p(y∣θ)Y_1, \dots, Y_n \mid \theta \stackrel{\text{i.i.d.}}{\sim} p(y \mid \theta) with a prior p(θ)p(\theta)? Chapter 2 of HoffPeter 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 answers the first through belief axioms and the second through Bruno de Finetti’s representation theorem.

2.1Belief Functions and the Axioms of Probability

Let F,G,HF, G, H be statements about the world, and let Be⁡(F∣H)\operatorname{Be}(F \mid H) quantify a rational agent’s degree of belief in FF conditional on knowing HH (operationalized through betting preferences). Rationality demands three qualitative properties:Edwin T. Jaynes. Probability Theory: The Logic of Science. Cambridge University Press, Cambridge, 2003; and Leonard J. Savage. The Foundations of Statistics. Dover Publications, New York, second edition, 1972

  • B1 (Boundedness): Be⁡(not H∣H)≤Be⁡(F∣H)≤Be⁡(H∣H)\operatorname{Be}(\text{not } H \mid H) \le \operatorname{Be}(F \mid H) \le \operatorname{Be}(H \mid H).
  • B2 (Monotonicity under disjunction): Be⁡(F or G∣H)≥max⁡{Be⁡(F∣H), Be⁡(G∣H)}\operatorname{Be}(F \text{ or } G \mid H) \ge \max\{\operatorname{Be}(F \mid H),\, \operatorname{Be}(G \mid H)\}.
  • B3 (Sequential composition): Be⁡(F and G∣H)\operatorname{Be}(F \text{ and } G \mid H) is determined by Be⁡(G∣H)\operatorname{Be}(G \mid H) and Be⁡(F∣G and H)\operatorname{Be}(F \mid G \text{ and } H).

Compare these directly against Hoff’s axioms of conditional probability:Kolmogorov’s 1933 measure-theoretic axioms start from unconditional probabilities Pr⁡(F)\Pr(F) and define Pr⁡(F∣H)=Pr⁡(F∩H)/Pr⁡(H)\Pr(F \mid H) = \Pr(F \cap H)/\Pr(H). Following de Finetti and Cox, Hoff takes conditional probability Pr⁡(F∣H)\Pr(F \mid H) as primitive—reflecting the fact that every belief is held conditional on background information HH.

  • P1: 0=Pr⁡(not H∣H)≤Pr⁡(F∣H)≤Pr⁡(H∣H)=10 = \Pr(\text{not } H \mid H) \le \Pr(F \mid H) \le \Pr(H \mid H) = 1.
  • P2: Pr⁡(F∪G∣H)=Pr⁡(F∣H)+Pr⁡(G∣H)\Pr(F \cup G \mid H) = \Pr(F \mid H) + \Pr(G \mid H) whenever F∩G=∅F \cap G = \emptyset.
  • P3: Pr⁡(F∩G∣H)=Pr⁡(G∣H) Pr⁡(F∣G∩H)\Pr(F \cap G \mid H) = \Pr(G \mid H)\,\Pr(F \mid G \cap H).

Every probability function satisfies B1–B3. Conversely, under mild regularity conditions (strict monotonicity and smoothness of the combination functions), Cox’s theoremRichard T. Cox. Probability, Frequency and Reasonable Expectation. American Journal of Physics, 14:1–13, 1946; and Richard T. Cox. The Algebra of Probable Inference. The Johns Hopkins Press, Baltimore, 1961 shows that any consistent real-valued belief calculus is isomorphic to a probability function obeying P1–P3. Complementarily, de Finetti’s Dutch-book argument reaches the same conclusion operationally: an agent whose betting odds violate P1–P3 can be offered a finite portfolio of bets that guarantees a strict monetary loss regardless of which event actually occurs.

2.2Partitions, Bayes’ Rule, and Bayes Factors

Definition 2.1 (Partition). A collection of events {H1,…,HK}\{H_1, \dots, H_K\} is a partition of HH if the events are pairwise disjoint (Hi∩Hj=∅H_i \cap H_j = \emptyset for i≠ji \neq j) and exhaustive (⋃k=1KHk=H\bigcup_{k=1}^K H_k = H).

If {H1,…,HK}\{H_1, \dots, H_K\} partitions the set of possible hypotheses with Pr⁡(H)=1\Pr(H) = 1, and EE is an observed event, axioms P1–P3 immediately yield three workhorse identities:

Total probability:∑k=1KPr⁡(Hk)=1,Marginal probability:Pr⁡(E)=∑k=1KPr⁡(E∣Hk)Pr⁡(Hk),Bayes’ rule:Pr⁡(Hj∣E)=Pr⁡(E∣Hj)Pr⁡(Hj)∑k=1KPr⁡(E∣Hk)Pr⁡(Hk). \begin{aligned} \text{Total probability:} &\quad \sum_{k=1}^K \Pr(H_k) = 1, \\ \text{Marginal probability:} &\quad \Pr(E) = \sum_{k=1}^K \Pr(E \mid H_k)\Pr(H_k), \\ \text{Bayes’ rule:} &\quad \Pr(H_j \mid E) = \frac{\Pr(E \mid H_j)\Pr(H_j)}{\sum_{k=1}^K \Pr(E \mid H_k)\Pr(H_k)}. \end{aligned} (2.1)

Dividing Pr⁡(Hi∣E)\Pr(H_i \mid E) by Pr⁡(Hj∣E)\Pr(H_j \mid E) cancels the normalizing constant Pr⁡(E)\Pr(E) and isolates how the data EE shift the relative odds of two competing hypotheses:

Pr⁡(Hi∣E)Pr⁡(Hj∣E)⏟posterior odds=Pr⁡(E∣Hi)Pr⁡(E∣Hj)⏟Bayes factor×Pr⁡(Hi)Pr⁡(Hj)⏟prior odds. \underbrace{\frac{\Pr(H_i \mid E)}{\Pr(H_j \mid E)}}_{\text{posterior odds}} = \underbrace{\frac{\Pr(E \mid H_i)}{\Pr(E \mid H_j)}}_{\text{Bayes factor}} \times \underbrace{\frac{\Pr(H_i)}{\Pr(H_j)}}_{\text{prior odds}}. (2.2)

The ratio BF⁡ij=Pr⁡(E∣Hi)/Pr⁡(E∣Hj)\operatorname{BF}_{ij} = \Pr(E \mid H_i) / \Pr(E \mid H_j) is the Bayes factor: for simple (point) hypotheses, it depends solely on the sampling model and not on the prior odds Pr⁡(Hi)/Pr⁡(Hj)\Pr(H_i)/\Pr(H_j).For composite hypotheses that contain free parameters (as in model selection in Chapter 9), Pr⁡(E∣Hi)=∫p(E∣θi,Hi) p(θi∣Hi) dθi\Pr(E \mid H_i) = \int p(E \mid \theta_i, H_i)\,p(\theta_i \mid H_i)\,d\theta_i, so the Bayes factor does depend on the within-model priors p(θi∣Hi)p(\theta_i \mid H_i)!

Example 2.2 (Worked Discrete Bayes Update: Rare-Disease Screening). Suppose a rare infection has population prevalence Pr⁡(H1)=0.01\Pr(H_1) = 0.01 (so Pr⁡(H0)=0.99\Pr(H_0) = 0.99, prior odds 1:991 : 99). A diagnostic test has sensitivity Pr⁡(E∣H1)=0.95\Pr(E \mid H_1) = 0.95 and false-positive rate Pr⁡(E∣H0)=0.05\Pr(E \mid H_0) = 0.05.

The Bayes factor for a positive test EE is BF⁡10=0.95/0.05=19\operatorname{BF}_{10} = 0.95 / 0.05 = 19. Multiplying by the prior odds gives posterior odds 19×(1/99)=19/9919 \times (1/99) = 19/99, and hence

Pr⁡(H1∣E)=0.95×0.010.95×0.01+0.05×0.99=0.00950.0590≈0.161. \Pr(H_1 \mid E) = \frac{0.95 \times 0.01}{0.95 \times 0.01 + 0.05 \times 0.99} = \frac{0.0095}{0.0590} \approx 0.161.

Even with a 95%-accurate test, a positive screen raises the probability of infection only to 16.1%16.1\% because false positives from the 99%99\% healthy majority outnumber true positives roughly 55 to 11.

2.3Conditional Independence

Definition 2.3 (Conditional Independence). Two events FF and GG are **conditionally independent given HH** if

Pr⁡(F∩G∣H)=Pr⁡(F∣H) Pr⁡(G∣H). \Pr(F \cap G \mid H) = \Pr(F \mid H)\,\Pr(G \mid H).

Equivalently (when Pr⁡(G∣H)>0\Pr(G \mid H) > 0), Pr⁡(F∣H∩G)=Pr⁡(F∣H)\Pr(F \mid H \cap G) = \Pr(F \mid H): once HH is known, learning GG does not alter beliefs about FF.

For random variables Y1,…,YnY_1, \dots, Y_n and a parameter θ\theta, conditional independence given θ\theta means the joint density factors into a product: p(y1,…,yn∣θ)=∏i=1npYi(yi∣θ)p(y_1, \dots, y_n \mid \theta) = \prod_{i=1}^n p_{Y_i}(y_i \mid \theta). When all marginal densities coincide, we write Y1,…,Yn∣θ∼i.i.d.p(y∣θ)Y_1, \dots, Y_n \mid \theta \stackrel{\text{i.i.d.}}{\sim} p(y \mid \theta).

2.4Random Variables and Distribution Summaries

In Bayesian inference, a random variable is simply any unknown numerical quantity—both future data YY and fixed but unknown parameters θ\theta.

  • Discrete variables have countable support 𝒴\mathcal{Y} and a mass function (which Hoff uniformly calls a pdf) p(y)=Pr⁡(Y=y)∈[0,1]p(y) = \Pr(Y = y) \in [0, 1] with ∑y∈𝒴p(y)=1\sum_{y \in \mathcal{Y}} p(y) = 1 (e.g., Binomial and Poisson).
  • Continuous variables (more precisely, those with an absolutely continuous cumulative distribution function) satisfy F(y)=Pr⁡(Y≤y)=∫−∞yp(t) dtF(y) = \Pr(Y \le y) = \int_{-\infty}^y p(t)\,dt; note that p(y)p(y) is a density (it can exceed 11 and is not Pr⁡(Y=y)\Pr(Y = y)), while Pr⁡(Y∈A)=∫Ap(y) dy\Pr(Y \in A) = \int_A p(y)\,dy.

Summarizing a distribution requires distinguishing mean E[Y]E[Y], median F−1(0.5)F^{-1}(0.5), and mode arg⁡max⁡yp(y)\arg\max_y p(y). For symmetric densities such as the normal, all three coincide; for skewed distributions such as the lognormal (household income), they diverge sharply.

Figure 2.1: Left: a symmetric normal⁡(10.75,0.82)\operatorname{normal}(10.75, 0.8^2) density where mean, median, and mode coincide. Right: exponentiating YY yields a right-skewed lognormal income distribution where mode<median<mean\text{mode} < \text{median} < \text{mean} (24.6k<46.6k<64.2k24.6\text{k} < 46.6\text{k} < 64.2\text{k}).Two panels comparing a symmetric Normal(10.75, 0.8^2) density where mean, median, and mode coincide against its exponentiated right-skewed lognormal density where mode 24.6k < median 46.6k < mean 64.2k

The variance Var⁡[Y]=E[(Y−E[Y])2]=E[Y2]−E[Y]2\operatorname{Var}[Y] = E[(Y - E[Y])^2] = E[Y^2] - E[Y]^2 measures average squared spread around the mean, while the α\alpha-quantile yα=F−1(α)y_\alpha = F^{-1}(\alpha) yields order-based spread intervals such as the interquartile range (y0.25,y0.75)(y_{0.25}, y_{0.75}) and the 95% interval (y0.025,y0.975)(y_{0.025}, y_{0.975}) that remain well-defined even when moments do not exist.Why is the mean E[Y]E[Y] so prominent? Under squared-error loss (Y−y^)2(Y - \hat{y})^2, the optimal single-number guess is y^=E[Y]\hat{y} = E[Y] (differentiate E[(Y−c)2]=Var⁡[Y]+(E[Y]−c)2E[(Y - c)^2] = \operatorname{Var}[Y] + (E[Y] - c)^2 with respect to cc). Under absolute-error loss ∣Y−y^∣\lvert Y - \hat{y} \rvert, the optimal guess is the median.

2.4.1Joint, Marginal, and Conditional Densities

For any two random variables (discrete, continuous, or mixed—such as continuous parameter θ\theta and discrete count YY), the joint density factors in both orders:

p(y,θ)=p(θ) p(y∣θ)=p(y) p(θ∣y). p(y, \theta) = p(\theta)\,p(y \mid \theta) = p(y)\,p(\theta \mid y). (2.3)

Crucially, knowing {p(θ), p(y∣θ)}\{p(\theta),\, p(y \mid \theta)\} completely determines the joint density, whereas knowing only the marginals {p(θ), p(y)}\{p(\theta),\, p(y)\} does not. Treating yy as fixed after observation, the normalizing constant p(y)=∫Θp(y∣θ)p(θ) dθp(y) = \int_\Theta p(y \mid \theta)p(\theta)\,d\theta does not depend on θ\theta, yielding the single most useful proportionality in Bayesian computation:

p(θ∣y)∝p(θ) p(y∣θ). p(\theta \mid y) \propto p(\theta)\,p(y \mid \theta). (2.4)

2.5Exchangeability and de Finetti’s Theorem

Why do Bayesians assume observations are conditionally i.i.d. given θ\theta, rather than marginally independent? Suppose Y1,…,Y10∈{0,1}Y_1, \dots, Y_{10} \in \{0, 1\} record whether 10 survey respondents report being happy. If the YiY_i were marginally independent, observing Y1=⋯=Y9=1Y_1 = \dots = Y_9 = 1 would tell us nothing about Y10Y_{10}—statistical learning would be impossible! Instead, observations are marginally dependent (earlier observations teach us about the population) yet symmetric in their indices (the label “respondent 3” carries no special information).

Definition 2.4 (Exchangeability). Random variables Y1,…,YnY_1, \dots, Y_n are exchangeable if their joint density is invariant under every permutation π\pi of {1,…,n}\{1, \dots, n\}:

p(y1,…,yn)=p(yπ(1),…,yπ(n)). p(y_1, \dots, y_n) = p(y_{\pi(1)}, \dots, y_{\pi(n)}). (2.5)

Proposition 2.5 (Conditionally i.i.d. implies exchangeability). If θ∼p(θ)\theta \sim p(\theta) and Y1,…,Yn∣θ∼i.i.d.p(y∣θ)Y_1, \dots, Y_n \mid \theta \stackrel{\text{i.i.d.}}{\sim} p(y \mid \theta), then marginally (integrating out θ\theta), Y1,…,YnY_1, \dots, Y_n are exchangeable. Moreover, if YiY_i has finite variance, then Cov⁡(Y1,Y2)=Var⁡(E[Y1∣θ])≥0\operatorname{Cov}(Y_1, Y_2) = \operatorname{Var}\bigl(E[Y_1 \mid \theta]\bigr) \ge 0.

Proof. For any permutation π\pi of {1,…,n}\{1, \dots, n\},

p(y1,…,yn)=∫Θ(∏i=1np(yi∣θ))p(θ) dθ=∫Θ(∏i=1np(yπ(i)∣θ))p(θ) dθ=p(yπ(1),…,yπ(n)), p(y_1, \dots, y_n) = \int_{\Theta} \left(\prod_{i=1}^n p(y_i \mid \theta)\right) p(\theta)\,d\theta = \int_{\Theta} \left(\prod_{i=1}^n p(y_{\pi(i)} \mid \theta)\right) p(\theta)\,d\theta = p(y_{\pi(1)}, \dots, y_{\pi(n)}),

because multiplication of real numbers is commutative. For the covariance, the law of total covariance gives

Cov⁡(Y1,Y2)=E[Cov⁡(Y1,Y2∣θ)]+Cov⁡(E[Y1∣θ],E[Y2∣θ])=0+Var⁡(E[Y1∣θ])≥0. \operatorname{Cov}(Y_1, Y_2) = E[\operatorname{Cov}(Y_1, Y_2 \mid \theta)] + \operatorname{Cov}(E[Y_1 \mid \theta], E[Y_2 \mid \theta]) = 0 + \operatorname{Var}(E[Y_1 \mid \theta]) \ge 0.

□

Notice what that non-negative covariance immediately implies: finite exchangeability alone does not imply a conditionally i.i.d. mixture! For example, if (Y1,Y2)(Y_1, Y_2) takes values (1,0)(1, 0) and (0,1)(0, 1) with probability 1/21/2 each (sampling 2 balls without replacement from an urn with 1 red and 1 blue ball), then (Y1,Y2)(Y_1, Y_2) is exchangeable, yet Cov⁡(Y1,Y2)=−1/4<0\operatorname{Cov}(Y_1, Y_2) = -1/4 < 0—making any representation of the form (2.6) impossible. What is needed is infinite extendability: that Y1,…,YnY_1, \dots, Y_n can be viewed as the first nn terms of an arbitrarily long exchangeable sequence.

Theorem 2.6 (de Finetti’s Representation Theorem). Let {Y1,Y2,… }\{Y_1, Y_2, \dots\} be an infinite sequence of random variables taking values in 𝒴\mathcal{Y} (a Polish space). If for every n≥1n \ge 1 the finite joint distribution of (Y1,…,Yn)(Y_1, \dots, Y_n) is exchangeable, then there exists a random probability distribution FF on 𝒴\mathcal{Y} (drawn from a prior measure Π\Pi over distributions) such that for all nn, conditionally on FF, Y1,…,Yn∼i.i.d.FY_1, \dots, Y_n \stackrel{\text{i.i.d.}}{\sim} F:

p(y1,…,yn)=∫(∏i=1np(yi∣F))dΠ(F). p(y_1, \dots, y_n) = \int \left(\prod_{i=1}^n p(y_i \mid F)\right) d\Pi(F). (2.6)

In the binary case 𝒴={0,1}\mathcal{Y} = \{0, 1\}, FF is completely characterized by a single scalar θ=lim⁡N→∞1N∑i=1NYi∈[0,1]\theta = \lim_{N \to \infty} \frac{1}{N}\sum_{i=1}^N Y_i \in [0, 1], and (2.6) reduces to

p(y1,…,yn)=∫01θ∑yi(1−θ)n−∑yi dΠ(θ). p(y_1, \dots, y_n) = \int_0^1 \theta^{\sum y_i}(1 - \theta)^{n - \sum y_i}\,d\Pi(\theta). Bruno de Finetti. La prévision : ses lois logiques, ses sources subjectives. Annales de l’Institut Henri Poincaré, 7(1):1–68, 1937

Remark 2.7 (Parametric models vs. de Finetti’s theorem). For binary data, the random distribution FF is a one-parameter Bernoulli⁡(θ)\operatorname{Bernoulli}(\theta) distribution with no extra assumptions. For general real-valued data, however, Theorem 2.6 produces a random nonparametric distribution FF; restricting FF to a finite-dimensional parametric family (such as normal⁡(θ,σ2)\operatorname{normal}(\theta, \sigma^2) or Poisson⁡(θ)\operatorname{Poisson}(\theta)) is an additional modeling approximation that must later be verified via model checking (Chapter 4).

Why is binary de Finetti true? Imagine fixing nn and extending the exchangeable sequence to a huge length N≫nN \gg n with total count SN=∑i=1NYiS_N = \sum_{i=1}^N Y_i. By exchangeability, conditional on SN=kS_N = k, all (Nk)\binom{N}{k} binary sequences are equally likely, so (Y1,…,Yn)∣SN=k(Y_1, \dots, Y_n) \mid S_N = k is a simple random sample without replacement from kk ones and N−kN - k zeros. As N→∞N \to \infty, sampling without replacement converges to sampling with replacement at rate θ=k/N\theta = k/N—which is Bernoulli⁡(θ)\operatorname{Bernoulli}(\theta) i.i.d.!

Even when the population size NN is genuinely finite (so infinite extendability does not literally hold), Diaconis and FreedmanPersi Diaconis and David Freedman. Finite Exchangeable Sequences. The Annals of Probability, 8(4):745–764, 1980 proved that the total-variation distance between an nn-sample from an NN-exchangeable sequence and a conditionally i.i.d. mixture is bounded by 2cn/N2cn / N when 𝒴\mathcal{Y} has cc finite states, and by n(n−1)/Nn(n-1)/N for arbitrary measurable spaces. Whenever n≪Nn \ll N, conditionally i.i.d. modeling is an extraordinarily accurate approximation.

2.6Key Takeaways & Python Check

Table 2.1: Summary of the foundational concepts of Chapter 2.
ConceptCore IdeaRole in Bayesian Inference
Belief axioms ↔\leftrightarrow ProbabilityCoherent betting preferences obey P1–P3Justifies probability as the calculus of uncertainty
Bayes factorPr⁡(E∣Hi)/Pr⁡(E∣Hj)\Pr(E \mid H_i) / \Pr(E \mid H_j)Isolates evidential support (depends on within-model priors for composite HiH_i)
Proportionalityp(θ∣y)∝p(θ) p(y∣θ)p(\theta \mid y) \propto p(\theta)\,p(y \mid \theta)Lets us identify posteriors by kernel shape alone
Exchangeabilityp(y1,…,yn)=p(yπ(1),…,yπ(n))p(y_1, \dots, y_n) = p(y_{\pi(1)}, \dots, y_{\pi(n)})Observable symmetry justifying conditionally i.i.d. models + priors
import numpy as np
from scipy import stats

# Verify Diaconis-Freedman: hypergeometric (without replacement) vs. binomial (i.i.d.)
n, theta = 10, 0.30
k = np.arange(n + 1)
binom_pmf = stats.binom.pmf(k, n, theta)
for N in [20, 100, 1000]:
    hyper_pmf = stats.hypergeom.pmf(k, M=N, n=int(N * theta), N=n)
    tv_dist = 0.5 * np.sum(np.abs(hyper_pmf - binom_pmf))
    print(f"N={N:4d}: TV distance = {tv_dist:.4f} (bound 2*2*n/N = {4*n/N:.4f})")

2.7Modern Developments: Predictive and Anytime-Valid Inference

2.7.1Martingale Posteriors

A martingale posterior starts from predictive distributions for observables and obtains a distribution for θ\theta without first writing down a prior and a likelihood.Beyond Hoff (2009). This material is not in Hoff’s book; it follows Fong, Holmes, and Walker, who develop the predictive reading of de Finetti’s theorem, itself much older.Edwin Fong, Chris Holmes, and Stephen G Walker. Martingale posterior distributions. Journal of the Royal Statistical Society Series B: Statistical Methodology, 85(5):1357–1391, 2023. doi: 10.1093/jrsssb/qkad005 In Theorem 2.6, the FF in (2.6) is the limit of the empirical distribution of an infinite sequence: given all the observables, nothing about θ\theta would be unknown. So simulate the missing ones. Given a one-step predictive PNP_N based on y1:Ny_{1:N}, predictive resampling draws

YN+1∼PN,N=n,n+1,…,θ∞=θ(F∞),F∞=lim⁡N→∞PN, Y_{N+1} \sim P_N, \quad N = n, n+1, \dots, \qquad \theta_\infty = \theta(F_\infty), \quad F_\infty = \lim_{N \to \infty} P_N, (2.7)

and the law of θ∞\theta_\infty given y1:ny_{1:n} is the martingale posterior. The name reflects the coherence condition E[PN+1(A)∣y1:N]=PN(A)E[P_{N+1}(A) \mid y_{1:N}] = P_N(A) for every event AA: each PN(A)P_N(A) is a martingale in [0,1][0, 1], so it converges almost surely, and imagined data do not shift beliefs on average.

Why it recovers Bayes: for binary data, take the Pólya-urn predictive PN(1)=(a+∑i≤Nyi)/(a+b+N)P_N(1) = (a + \sum_{i \le N} y_i)/(a + b + N). This is the predictive of the beta⁡(a,b)\operatorname{beta}(a, b) model (Chapter 3), so given y1:ny_{1:n} the simulated sequence is exchangeable and its limiting frequency has exactly the posterior law beta⁡(a+∑yi, b+n−∑yi)\operatorname{beta}\bigl(a + \sum y_i,\, b + n - \sum y_i\bigr). Other predictives yield posteriors with no explicit prior.

When to use it. Use it when predictions are easier to specify than priors, or when the parametric restriction in Remark 2.7 is unwelcome; the forward simulations are independent and parallel, but truncated at a finite NN. With a trusted parametric model and prior, Hoff’s route is direct and exact.

2.7.2Bayes Factors as e-Values and Anytime-Valid Testing

For a simple null hypothesis, the Bayes factor of (2.2) is also an e-value, a nonnegative statistic with null expectation at most one.Beyond Hoff (2009). This material is not in Hoff’s book; it follows Grünwald, de Heide, and Koolen and the survey of Ramdas et al. The maximal inequality it rests on is classical (Ville, 1939).Peter Grünwald, Rianne de Heide, and Wouter Koolen. Safe testing. Journal of the Royal Statistical Society Series B: Statistical Methodology, 86(5):1091–1128, 2024. doi: 10.1093/jrsssb/qkae011; and Aaditya Ramdas, Peter Grünwald, Vladimir Vovk, and Glenn Shafer. Game-Theoretic Statistics and Safe Anytime-Valid Inference. Statistical Science, 38(4):576–601, 2023. doi: 10.1214/23-STS894 Let H0H_0 specify a joint density p0p_0, let m1(y1:t)=∫p(y1:t∣θ) p(θ∣H1) dθm_1(y_{1:t}) = \int p(y_{1:t} \mid \theta)\,p(\theta \mid H_1)\,d\theta with a proper prior fixed in advance, and set BF⁡t=m1(y1:t)/p0(y1:t)\operatorname{BF}_t = m_1(y_{1:t})/p_0(y_{1:t}). Then for every fixed tt and every α∈(0,1)\alpha \in (0, 1),

E0[BF⁡t]≤1,Pr⁡0(sup⁡t≥1BF⁡t≥1α)≤α, E_{0}[\operatorname{BF}_t] \le 1, \qquad \Pr_{0}\Bigl(\sup_{t \ge 1} \operatorname{BF}_t \ge \tfrac{1}{\alpha}\Bigr) \le \alpha, (2.8)

with equality in the first relation when p0>0p_0 > 0 wherever m1>0m_1 > 0.

Why it holds: under H0H_0, E0[BF⁡t+1∣y1:t]=BF⁡t∫m1(y∣y1:t)p0(y∣y1:t) p0(y∣y1:t) dy≤BF⁡tE_0[\operatorname{BF}_{t+1} \mid y_{1:t}] = \operatorname{BF}_t \int \frac{m_1(y \mid y_{1:t})}{p_0(y \mid y_{1:t})}\,p_0(y \mid y_{1:t})\,dy \le \operatorname{BF}_t, so BF⁡t\operatorname{BF}_t is a nonnegative supermartingale started at 11, and Ville’s inequality bounds its supremum. In Example 2.2, a positive test has BF⁡10=19\operatorname{BF}_{10} = 19 and a negative one 1/191/19, so E0[BF⁡]=0.05⋅19+0.95/19=1E_0[\operatorname{BF}] = 0.05 \cdot 19 + 0.95/19 = 1; note that 19<2019 < 20 does not reject at level α=0.05\alpha = 0.05.

When H0H_0 is composite, averaging over a prior on it protects only on average: the expectation can exceed one at particular null values. Choosing the null mixture by reverse information projection—the mixture (or limit of mixtures) pWp_W minimizing KL⁡(m1 ∥ pW)\operatorname{KL}(m_1 \,\Vert\, p_W)—restores the e-value property when that minimum is finite, but at a fixed sample size; unrestricted optional stopping needs a further argument.

When to use it. Use (2.8) to monitor data continuously with a frequentist guarantee. The threshold 1/α1/\alpha is conservative compared with a fixed-nn test, and unlike Hoff’s posterior odds it ignores Pr⁡(H0)\Pr(H_0).

2.7.3Computational & Symbolic Check

The Python block runs the Pólya urn forward to recover its beta posterior and checks E0[BF⁡10]=1E_0[\operatorname{BF}_{10}] = 1 together with the bound (2.8); the Wolfram sequence proves both identities.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
from scipy.special import betaln

rng = np.random.default_rng(42)
a, b, n, s, S, M = 1, 1, 10, 7, 20_000, 2_000
ones = np.full(S, float(a + s))
for N in range(n, n + M):                         # Polya-urn predictive resampling
    ones += rng.random(S) < ones / (a + b + N)
post = stats.beta(a + s, b + n - s)
theta = ones / (a + b + n + M)
print(f"mean {theta.mean():.3f} vs {post.mean():.3f}, sd {theta.std():.3f} vs {post.std():.3f}")

y, th0 = np.arange(n + 1), 0.3                    # E_0[BF_10] summed over y = 0..n
bf = np.exp(betaln(a + y, b + n - y) - betaln(a, b) - y * np.log(th0) - (n - y) * np.log1p(-th0))
print("E_0[BF] =", np.sum(stats.binom.pmf(y, n, th0) * bf))
t, c = np.arange(1, 1001), np.cumsum(rng.random((2000, 1000)) < 0.5, axis=1)
log_bf = betaln(1 + c, 1 + t - c) + t * np.log(2)
print("Pr_0(sup BF >= 20) =", np.mean(log_bf.max(axis=1) >= np.log(20)), "<= 0.05")
One urn step: averaging the next predictive over YN+1Y_{N+1} returns the current one, with AA ones-weight and TT total weight.
// Chapter 2 (modern): Polya-urn martingale, beta moments & the e-value identity
await show`Simplify[(A/T)*(A + 1)/(T + 1) + (1 - A/T)*A/(T + 1) - A/T]`
E[PN+1(1)∣y1:N]−PN(1)=0 E[P_{N+1}(1) \mid y_{1:N}] - P_N(1) = 0 Multiply urn predictives for rr successive ones: the result is a ratio of rising factorials.
const urnMom = await show`Product[(a + j)/(a + b + j), {j, 0, r - 1}]`
Pr⁡(r successive ones)=(a)r(a+b)r \Pr(r \text{ successive ones}) = \frac{(a)_r}{(a+b)_r} These equal all the moments of beta⁡(a,b)\operatorname{beta}(a, b), and moments determine a law on [0,1][0, 1], so the limiting frequency is exactly beta.
await show`Assuming[a > 0 && b > 0 && r >= 0 && Element[r, Integers], FullSimplify[
  Integrate[th^(a + r - 1)*(1 - th)^(b - 1)/Beta[a, b], {th, 0, 1}] / (${urnMom})]]`
∫01θrBeta⁡(θ∣a,b) dθPr⁡(r successive ones)=1 \frac{\int_0^1 \theta^r \operatorname{Beta}(\theta \mid a, b)\,d\theta}{\Pr(r \text{ successive ones})} = 1 E-value identity for every nn: p0p_0 cancels, leaving ∑ym1(y)\sum_y m_1(y); sum inside the θ\theta-integral first.
await show`Assuming[a > 0 && b > 0 && 0 < th < 1 && n >= 1 && Element[n, Integers],
  Integrate[FullSimplify[Sum[Binomial[n, y]*th^y*(1 - th)^(n - y), {y, 0, n}]]
    * th^(a - 1)*(1 - th)^(b - 1)/Beta[a, b], {th, 0, 1}]]`
𝔼0[BF⁡10]=∫01∑y=0n(ny)θy(1−θ)n−y p(θ∣H1) dθ=1 \mathbb{E}_0[\operatorname{BF}_{10}] = \int_0^1 \sum_{y=0}^n \binom{n}{y}\theta^y(1-\theta)^{n-y}\,p(\theta \mid H_1)\,d\theta = 1 Write the Bayes factor of a beta⁡(2,3)\operatorname{beta}(2, 3) alternative against a symbolic point null θ0\theta_0; B(2,3)=112B(2, 3) = \tfrac{1}{12}.
const bf10 = await show`Beta[2 + y, 3 + n - y] / (Beta[2, 3]*th0^y*(1 - th0)^(n - y))`
BF⁡10(y)=B(2+y, 3+n−y)B(2,3) θ0y(1−θ0)n−y=12 B(2+y, 3+n−y) θ0−y(1−θ0)y−n \operatorname{BF}_{10}(y) = \frac{B(2+y,\,3+n-y)}{B(2,3)\,\theta_0^{y}(1-\theta_0)^{n-y}} = 12\,B(2+y,\,3+n-y)\,\theta_0^{-y}(1-\theta_0)^{y-n} Check by exact summation over y=0,…,ny = 0, \dots, n that its null expectation is 11 for n=5,10,20n = 5, 10, 20.
await show`Table[Simplify[Sum[Binomial[n, y]*th0^y*(1 - th0)^(n - y)*(${bf10}), {y, 0, n}]], {n, {5, 10, 20}}]`
(𝔼0[BF⁡10])n∈{5, 10, 20}={1,1,1} \bigl(\mathbb{E}_0[\operatorname{BF}_{10}]\bigr)_{n \in \{5,\,10,\,20\}} = \{1,1,1\}

2.8Symbolic Check in Wolfram Language

This wolfram-ws-bridge JavaScript-mode sequence derives Bayes’ rule, the Bayes factor s/fs/f, the negative finite-urn covariance Cov⁡(Y1,Y2)\operatorname{Cov}(Y_1, Y_2), and the exact finite-population hypergeometric sample-sum variance symbolically, then instantiates the screening example and exact Diaconis–Freedman total-variation distances.

Apply Bayes’ rule symbolically to express Pr⁡(H1∣E)\Pr(H_1 \mid E) in terms of sensitivity ss, false-positive rate ff, and prior p0p_0.
// Chapter 2: Symbolic Bayes' rule, Bayes factor, and finite-population covariance & variance
const post = await show`Simplify[(s * p0) / (s * p0 + f * (1 - p0))]`
Pr⁡(H1∣E)=s p0s p0+f(1−p0)=p0sf−fp0+p0s \Pr(H_1 \mid E) = \frac{s\,p_0}{s\,p_0 + f(1 - p_0)} = \frac{p_0 s}{f-f p_0 +p_0 s} Divide posterior odds by prior odds to verify that the Bayes factor equals the likelihood ratio s/fs/f.
await show`Simplify[((${post} / (1 - ${post})) / (p0 / (1 - p0)))]`
BF⁡10=posterior oddsprior odds=sf \operatorname{BF}_{10} = \frac{\text{posterior odds}}{\text{prior odds}} = \frac{s}{f} Derive the exact covariance Cov⁡(Y1,Y2)<0\operatorname{Cov}(Y_1, Y_2) < 0 of two without-replacement draws from a finite population.
// Finite-population without-replacement covariance Cov(Y1, Y2) < 0 and sample-sum variance
const covF = await show`FullSimplify[(kRed/nPop)*((kRed - 1)/(nPop - 1)) - (kRed/nPop)^2]`
Cov⁡(Y1,Y2)=K(K−N)(−1+N)N2 \operatorname{Cov}(Y_1, Y_2) = \frac{K (K -N)}{(-1+N) N^2} Combine marginal variances and pairwise covariances to obtain the hypergeometric sample-sum variance.
const varHyper = await show`FullSimplify[n*(kRed/nPop)*(1 - kRed/nPop) + n*(n - 1)*(${covF})]`
Var⁡ ⁣(∑i=1nYi)=Kn(K−N)(n−N)(−1+N)N2 \operatorname{Var}\!\left(\sum_{i=1}^n Y_i\right) = \frac{K n (K -N) (n-N)}{(-1+N) N^2} Take N→∞N \to \infty at fixed proportion θ=K/N\theta = K/N to confirm that finite-population covariance vanishes.
await show`Limit[${covF} /. kRed -> th * nPop, nPop -> Infinity]`
lim⁡N→∞Cov⁡(Y1,Y2)=0 \lim_{N \to \infty} \operatorname{Cov}(Y_1, Y_2) = 0 Instantiate Bayes’ rule as an exact fraction for the screening test (p0=0.01,s=0.95,f=0.05p_0 = 0.01, s = 0.95, f = 0.05).
// Instantiate screening example (p0 = 1/100, s = 95/100, f = 5/100) & Diaconis-Freedman TV (N = 20, 100, 1000)
const pExact = await show`${post} /. {p0 -> 1/100, s -> 95/100, f -> 5/100}`
Pr⁡(H1∣E)∣p0=0.01,  s=0.95,  f=0.05=19118 \Pr(H_1 \mid E)\big|_{p_0=0.01,\; s=0.95,\; f=0.05} = \frac{19}{118} Convert the exact screening posterior probability 19/11819/118 to decimal form.
await show`N[${pExact}]`
Pr⁡(H1∣E)∣decimal=0.161017 \Pr(H_1 \mid E)\big|_{\text{decimal}} = 0.161017 Compute the exact total-variation distance between hypergeometric and binomial draws as NN grows.
await show`N[Table[1/2 * Sum[Abs[
  Binomial[3*nPop/10, k]*Binomial[7*nPop/10, 10 - k]/Binomial[nPop, 10]
  - Binomial[10, k]*(3/10)^k*(7/10)^(10 - k)], {k, 0, 10}], {nPop, {20, 100, 1000}}]]`
(dTV(Hypergeom,Binom))N∈{20, 100, 1000}={0.15871,0.0255493,0.00244915} \begin{aligned} &\bigl(d_{\text{TV}}(\text{Hypergeom}, \text{Binom})\bigr)_{N \in \{20,\,100,\,1000\}} \\ &= \{0.15871,0.0255493,0.00244915\} \end{aligned}

2.9Exercises

Exercise 2.8. Suppose a bookmaker offers even-money odds corresponding to subjective probabilities q(F)=0.6q(F) = 0.6 and q(not F)=0.6q(\text{not } F) = 0.6 (violating P1–P2 because q(F)+q(not F)=1.2>1q(F) + q(\text{not } F) = 1.2 > 1). Construct a pair of bets against this bookmaker that guarantees you a positive profit whether FF occurs or not.

Symbolic Solution & InstantiationSimplify the bookmaker’s guaranteed profit when selling one unit each of FF and FcF^c at prices qF+qFc>1q_F + q_{F^c} > 1.
// Ex 2.1: Dutch book guaranteed profit when qF + qNotF > 1 (both outcomes F and not-F)
const profitF = await show`Simplify[(qF + qNotF) - 1]`
Dutch-book profit=(qF−1)+qFc=−1+qF+qFc \text{Dutch-book profit} = (q_F - 1) + q_{F^c} = -1+q_F +q_{F^c} Instantiate the guaranteed Dutch-book profit when qF=qFc=0.6q_F = q_{F^c} = 0.6.
await show`N[${profitF} /. {qF -> 6/10, qNotF -> 6/10}]`
Profit∣qF=0.6,  qFc=0.6=0.2 \text{Profit}\big|_{q_F=0.6,\; q_{F^c}=0.6} = 0.2

Exercise 2.9. Consider drawing n=2n = 2 balls without replacement from an urn containing KK red balls and N−KN - K blue balls, where Yi=1Y_i = 1 if draw ii is red. Verify directly that (Y1,Y2)(Y_1, Y_2) is exchangeable and compute Cov⁡(Y1,Y2)\operatorname{Cov}(Y_1, Y_2) as a function of KK and NN. Show that Cov⁡(Y1,Y2)<0\operatorname{Cov}(Y_1, Y_2) < 0 for every finite N≥2N \ge 2 with 0<K<N0 < K < N, and verify that Cov⁡(Y1,Y2)→0\operatorname{Cov}(Y_1, Y_2) \to 0 as N→∞N \to \infty with K/N→θK/N \to \theta.

Symbolic Solution & InstantiationCompute Pr⁡(Y1=1,Y2=0)\Pr(Y_1 = 1, Y_2 = 0) symbolically for two draws without replacement from an urn of KK reds in NN.
// Ex 2.2: Exchangeability & negative covariance of n = 2 draws without replacement
const p10 = await show`FullSimplify[(kRed/nPop)*((nPop - kRed)/(nPop - 1))]`
Pr⁡(Y1=1,Y2=0)=K(−K+N)(−1+N)N \Pr(Y_1 = 1, Y_2 = 0) = \frac{K (-K +N)}{(-1+N) N} Compute Pr⁡(Y1=0,Y2=1)\Pr(Y_1 = 0, Y_2 = 1) for the reversed draw order: the same expression.
const p01 = await show`FullSimplify[((nPop - kRed)/nPop)*(kRed/(nPop - 1))]`
Pr⁡(Y1=0,Y2=1)=K(−K+N)(−1+N)N \Pr(Y_1 = 0, Y_2 = 1) = \frac{K (-K +N)}{(-1+N) N} Compute Cov⁡(Y1,Y2)\operatorname{Cov}(Y_1, Y_2) symbolically, showing it is strictly negative for 0<K<N0 < K < N.
const covF = await show`FullSimplify[(kRed/nPop)*((kRed - 1)/(nPop - 1)) - (kRed/nPop)^2]`
Cov⁡(Y1,Y2)=K(K−N)(−1+N)N2 \operatorname{Cov}(Y_1, Y_2) = \frac{K (K -N)}{(-1+N) N^2} Check exchangeability symmetry, the N→∞N \to \infty i.i.d. limit, and the concrete value at (K,N)=(3,10)(K, N) = (3, 10).
await show`{Simplify[${p10} - ${p01}], Limit[${covF} /. kRed -> th*nPop, nPop -> Infinity], N[${covF} /. {kRed -> 3, nPop -> 10}]}`
(P(1,0)−P(0,1),  lim⁡N→∞Cov⁡,  Cov⁡∣K=3,N=10)={0,0,−0.0233333} \begin{aligned} &\bigl(P(1,0)-P(0,1),\; \lim_{N\to\infty}\operatorname{Cov},\; \operatorname{Cov}|_{K=3,N=10}\bigr) \\ &= \{0,0,-0.0233333\} \end{aligned}

Exercise 2.10. Give an example of two events FF and GG that are conditionally independent given HH and given not H\text{not } H, yet marginally dependent. Explain how this mirrors the behavior of observations Y1,Y2Y_1, Y_2 in a Bayesian model with unknown parameter θ\theta.

Symbolic Solution & InstantiationFactor Pr⁡(F∩G)−Pr⁡(F)Pr⁡(G)\Pr(F \cap G) - \Pr(F)\Pr(G) to show conditional independence given HH still yields marginal dependence.
// Ex 2.3: Conditional independence given H and not-H still implies marginal dependence
const margDiff = await show`Factor[(h*p1*q1 + (1 - h)*p0*q0) - (h*p1 + (1 - h)*p0)*(h*q1 + (1 - h)*q0)]`
Pr⁡(F∩G)−Pr⁡(F)Pr⁡(G)=−((−1+h)h(p0−p1)(q0−q1)) \Pr(F \cap G) - \Pr(F)\Pr(G) = -((-1+h) h (p_0 -p_1) (q_0 -q_1)) Evaluate the marginal dependence gap at h=1/2h = 1/2, p1=q1=3/4p_1 = q_1 = 3/4, and p0=q0=1/4p_0 = q_0 = 1/4.
await show`${margDiff} /. {h -> 1/2, p1 -> 3/4, q1 -> 3/4, p0 -> 1/4, q0 -> 1/4}`
[Pr⁡(F∩G)−Pr⁡(F)Pr⁡(G)]h=1/2,  p1=q1=3/4,  p0=q0=1/4=116 \bigl[\Pr(F \cap G) - \Pr(F)\Pr(G)\bigr]_{h=1/2,\; p_1=q_1=3/4,\; p_0=q_0=1/4} = \frac{1}{16}