Bayesian Inference Notes
Bayesian Inference Notes
These notes develop Bayesian inference from rst principles, with every central result stated
precisely and proved. Beyond the core (Bayes' theorem, prior/likelihood/posterior, conju-
gacy), we treat the logical foundations (coherence and de Finetti's theorem), suciency,
worked objective priors, hierarchical and empirical Bayes, decision theory, model compari-
son via Bayes factors, the computational toolkit (Monte Carlo, MCMC, Gibbs, the Laplace
approximation), large-sample theory, and a careful comparison with frequentist methods
closing with worked examples and solved exercises.
Contents
1 Motivation and Philosophy 2
1.1 What inference is . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2 A little history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3 Two readings of probability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.4 Why beliefs must obey the probability axioms . . . . . . . . . . . . . . . . . . . . 3
2 Probability Foundations 3
3 Bayes' Theorem 4
3.1 The odds form: evidence as weight . . . . . . . . . . . . . . . . . . . . . . . . . . 5
7 Prior Distributions 7
7.1 A taxonomy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
7.2 Improper priors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
7.3 The Jereys prior, with worked derivations . . . . . . . . . . . . . . . . . . . . . . 7
7.4 The prior predictive (and how to elicit a prior) . . . . . . . . . . . . . . . . . . . 8
7.5 Mixture priors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1
10 The Exponential Family and General Conjugacy 10
11 A Capstone: Bayesian Linear Regression 10
12 Hierarchical Models and Empirical Bayes 12
12.1 Empirical Bayes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
14 Credible Intervals 13
15 The Posterior Predictive Distribution 13
16 Bayesian Model Comparison 14
17 Computational Methods 14
17.1 Monte Carlo integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
17.2 Importance sampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
17.3 Markov chain Monte Carlo (MCMC) . . . . . . . . . . . . . . . . . . . . . . . . . 15
17.4 Gibbs sampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
17.5 The Laplace approximation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Statistical inference is the task of learning about an unknown quantity θ a parameter, a hy-
pothesis, or a future observation from observed data x. Two traditions answer this dierently.
Frequentist. θ is a xed but unknown constant. Probability refers only to the long-run
frequency of outcomes under hypothetical repetitions of the experiment. One never writes
P (θ ∈ A), because θ is not random.
2
The central Bayesian idea is learning as belief updating:
observe x
prior belief −−−−−−→ posterior belief .
| {z } | {z }
before data after data
The engine that performs the update is Bayes' theorem; almost everything that follows elab-
orates that one equation.
The rule is named for the Reverend Thomas Bayes (17011761), whose posthumous 1763 essay
solved a special case (inferring a binomial probability from observed successes). Pierre-Simon
Laplace (17491827) independently rediscovered and vastly generalised the idea, applying it
to astronomy, demography and jurisprudence; for much of the nineteenth century the method
was simply called inverse probability. The twentieth-century frequentist movement (Fisher,
Neyman, Pearson) pushed it aside over concerns about subjective priors, but the Bayesian
programme was rebuilt on rigorous decision-theoretic and axiomatic foundations by Ramsey,
de Finetti, Jereys, Savage and others, and powered by modern computation is now a
dominant framework across statistics and machine learning.
The split above mirrors a deeper disagreement about what probability is.
A reasonable worry is that degree of belief is too woolly to do mathematics with. Two classical
results answer it.
The Dutch-book argument (coherence). Suppose you quote betting odds on events.
If your quoted fair prices for events violate the probability axioms (non-negativity, nor-
malisation, additivity), then a clever opponent can construct a nite set of bets a Dutch
book each of which you regard as fair, but whose net eect is that you lose money with
certainty, regardless of outcome. Conversely, if your prices obey the axioms, no such sure-
loss book exists. Hence: to be coherent (immune to sure loss), your degrees of belief must
be a probability measure.
Cox's theorem reaches the same conclusion from dierent premises: if degrees of plausibility
are real numbers obeying a few qualitative desiderata (consistency, and agreement with Boolean
logic in the certain limits), then they are isomorphic to probabilities and must combine by the
sum and product rules. Either way, rational belief is probability, and updating that belief on
evidence is forced to be Bayes' theorem. This is the philosophical bedrock of everything below.
3
2 Probability Foundations
We isolate the facts on which Bayes' theorem rests. Throughout, (Ω, F, P ) is a probability space
and conditioning events have positive probability.
Proof. Multiply P (A | B) = P (A ∩ B)/P (B) by P (B); symmetrically for the other equality.
Both equal P (A ∩ B).
Denition 2.5 (Expectation and variance) . For a random variable θ with density π , E[θ] =
Var(θ) = E[θ2 ] − (E[θ])2 .
R
θ π(θ) dθ and The law of total expectation and law of total variance
state
E[Y ] = E E[Y | Z] , Var(Y ) = E Var(Y | Z) + Var E[Y | Z] ,
both of which recur when we marginalise nuisance parameters and analyse hierarchical models.
3 Bayes' Theorem
P (A | B) P (B)
Theorem 3.1 (Bayes' theorem, event form). For P (A), P (B) > 0, P (B | A) = .
P (A)
Corollary 3.2 (Extended / hypothesis form) . If {H1 , . . . , Hn } partition the hypothesis space
and D is data,
P (D | Hi )P (Hi )
P (Hi | D) = P .
j P (D | Hj )P (Hj )
Proof. Theorem 3.1 with B = Hi , A = D over P (D), then expand P (D) by Theorem 2.4.
4
Theorem 3.3 (Continuous parametric form) . With prior density π(θ) on Θ and data density
p(x | θ),
p(x | θ)π(θ)
π(θ | x) = Z
p(x | θ′ )π(θ′ ) dθ′
Θ
For two hypotheses H1 , H2 , dividing the two instances of Bayes' theorem cancels the awkward
denominator P (D) entirely:
P (H1 | D) P (D | H1 ) P (H1 )
= × .
P (H2 | D) P (D | H2 ) P (H2 )
| {z } | {z } | {z }
posterior odds Bayes factor prior odds
P (H1 | D) P (H1 ) P (D | H1 )
log = log + log ,
P (H2 | D) P (H2 ) P (D | H2 )
so evidence adds on the log-odds scale. Independent data sets contribute additively, which
is why log-odds is the natural currency of sequential learning.
likelihood prior
z }| { z}|{
p(x | θ) π(θ)
π(θ | x) = R .
| {z } p(x | θ′ )π(θ′ ) dθ′
posterior | {z }
evidence
5
The proportionality shortcut. Because m(x) is free of θ, it is just the constant making
the posterior integrate to 1. To nd the shape,
Exchangeability says the order of observations carries no information a far weaker and
more defensible assumption than independence.
Z 1Yn
p(x1 , . . . , xn ) = θxi (1 − θ)1−xi π(θ) dθ.
0 i=1
Pn
Idea of proof. Let Sn = i=1 Xi . Exchangeability makes
p(x1 , . . . , xn ) depend only on Sn . One
shows the empirical frequency Sn /n converges almost surely to a random limit θ , and that
conditionally on θ the Xi behave as i.i.d. Bernoulli(θ); the distribution π of the limit θ is the
prior. (The general version, due to Hewitt and Savage, replaces Bernoulli(θ) by an arbitrary
sampling distribution indexed by θ .)
Why this matters. de Finetti's theorem says that believing your data are exchangeable is
mathematically equivalent to believing they are i.i.d. from some distribution with an unknown
parameter θ carrying a prior π. The parameter, the likelihood, and the prior are not
arbitrary metaphysical add-ons they are an unavoidable consequence of a symmetry you
already accept. This is the deepest justication for the Bayesian model.
n
Y n
X
L(θ | x) = p(xi | θ), ℓ(θ) = log p(xi | θ).
i=1 i=1
6
6.1 Suciency: when a summary loses nothing
Denition 6.2 (Sucient statistic). A statistic T (x) is sucient for θ if the conditional distri-
bution of x given T (x) does not depend on θ.
Theorem 6.3 (FisherNeyman factorisation) . T (x) is sucient for θ if and only if there exist
functions g, h ≥ 0 with
p(x | θ) = g T (x), θ h(x).
Corollary 6.4 (Suciency in Bayesian terms). If T (x) is sucient then π(θ | x) = π θ | T (x) :
Proof. Using Theorem 6.3, π(θ | x) ∝ p(x | θ)π(θ) = g(T (x), θ)h(x)π(θ) ∝ g(T (x), θ)π(θ) after
dropping the θ-free factor h(x). The right side depends on data only through T (x).
Remark 6.5 (The Likelihood Principle) . Proportional likelihoods carry identical information
about θ. Bayesian inference obeys this automatically, since π(θ | x) depends on data only
through L(θ | x). A practical consequence: the experimenter's stopping rule (stop after n trials
vs. stop after k successes) does not aect Bayesian conclusions, though it famously aects
frequentist p-values.
7 Prior Distributions
The prior π(θ) encodes information available before the current data. Choosing it well is where
modelling judgement enters.
7.1 A taxonomy
Informative priors encode genuine knowledge (a physical constant, a prior study's eect
size). Stronger priors need more data to overturn.
Weakly informative priors are deliberately broad: enough to exclude the absurd, while
letting data dominate (e.g. a N (0, 102 ) prior on a standardised regression coecient).
Non-informative / objective priors aim to let the data speak (at, Jereys, reference
priors).
7
7.3 The Jereys prior, with worked derivations
p
The at prior is not invariant: at in θ is not at in g(θ). Jereys' x is πJ (θ) ∝ I(θ) with
I(θ) = −E ∂θ2 log p(X | θ) .
Fisher information
Proof. Fisher information transforms as I(ϕ) = I(θ)(dθ/dϕ)2 , and densities transform as π (ϕ) =
p p p J
πJ (θ)|dθ/dϕ|. Hence πJ (ϕ) ∝ I(θ) |dθ/dϕ| = I(θ)(dθ/dϕ)2 = I(ϕ).
Normal mean µ, known σ 2 : I(µ) = 1/σ 2 is constant, so πJ (µ) ∝ 1 (the at prior is already
invariant here).
Before any data, the model predicts observables through the prior predictive (a.k.a. marginal)
distribution Z
m(x) = p(x | θ) π(θ) dθ.
Θ
This is invaluable for prior elicitation and checking : simulate θ ∼ π, then x ∼ p(· | θ), and ask
whether the resulting fake data sets look plausible. If a vague prior generates absurd data, it
is not actually vague in a good way. Elicitation in practice means translating expert statements
(the rate is probably between 2 and 6) into hyperparameters (e.g. a Gamma with that central
range).
Z
X wk mk (x)
π(θ | x) = w̃k πk (θ | x), w̃k = P , mk (x) = p(x | θ)πk (θ) dθ,
k j wj mj (x)
so the data re-weight the components by their marginal likelihoods a clean preview of model
comparison (16).
Proof. π(θ | x1 , x2 ) ∝ p(x1 | θ)p(x2 | θ)π(θ). Group as p(x2 | θ) · [p(x1 | θ)π(θ)]; the bracket
is ∝ π(θ | x1 ). Both processing orders normalise the same product, so they give the same
posterior.
8
Yesterday's posterior is today's prior. This coherence is unique to the Bayesian
framework and is exactly what makes streaming/online learning principled: no special
corrections, no double-counting, no dependence on the order data happened to arrive.
Each proof uses only the proportionality shortcut and recognise the kernel.
α+x n x a α
Proof. a+n = a+n n + a+n a with a = α + β. As n → ∞, w → 1 (prior washes out); as a → ∞,
w → 0.
Model. iid
Prior.
P
xi ∼ Poisson(λ), S = xi . λ ∼ Gamma(α, β).
Proof. π(λ | x) ∝ λS e−nλ · λα−1 e−βλ = λ(α+S)−1 e−(β+n)λ , a Gamma kernel. The mean splits as
in Corollary 9.3.
Model. iid
xi ∼ N (µ, σ 2 ), σ 2 known. Prior. µ ∼ N (µ0 , τ02 ).
9
9.4 Inverse-GammaNormal: a variance (known mean)
Model. iid
xi ∼ N (µ, σ 2 ), µ
2
known, σ2 unknown. Prior. σ 2 ∼ Inv-Gamma(α, β), density
∝ (σ 2 )−α−1 e−β/σ .
Theorem 9.6. σ 2 | x ∼ Inv-Gamma α + n2 , β + 12 i (xi − µ)2 .
P
2 2 −n/2 exp(− W ).
P
Proof. Let W = i (xi − µ) . The likelihood is ∝ (σ ) 2σ 2
Multiplying by the prior,
π(σ 2 | x) ∝ (σ 2 )−(α+n/2)−1 exp − β+W/2
σ 2 ,
a heavier-tailed distribution reecting the extra uncertainty from estimating σ2. This is the
Bayesian counterpart of why the frequentist t-distribution (not the normal) governs inference
for a mean with unknown variance.
(σ 2 ) α + n2 , β + 1
(xi − µ)2
P
Normal, known µ Inv-Gamma(α, β) 2
Multinomial (p) Dirichlet(α) α + counts
with natural parameter η(θ) and sucient statistic T (x) (note Theorem 6.3: T is automatically
sucient).
10
Theorem 10.1 (Conjugate prior for an exponential family) .
For an i.i.d. sample, the prior
π(θ | χ, ν) ∝ g(θ)ν ⊤
exp(η(θ) χ) is conjugate, with posterior hyperparameters
n
X
χ 7→ χ + T (xi ), ν 7→ ν + n.
i=1
ν behaves as a prior sample size and χ as prior sucient statistics, to which the data
P
simply add their own count n and statistic i T (xi ). BetaBinomial, GammaPoisson,
NormalNormal, Inverse-GammaNormal, and DirichletMultinomial are all special cases.
Theorem 11.1 (Conjugate posterior for the coecients) . The posterior is Gaussian, β |y∼
N (mn , Vn ), with
−1
Vn = V0−1 + 1
σ2
X⊤ X , mn = Vn V0−1 m0 + 1
σ2
X⊤ y .
Proof. Work with the log-posterior up to constants in β. The two quadratic forms are
Corollary 11.2 (Ridge regression is a MAP estimate). Take the isotropic prior β ∼ N (0, τ 2 Id ).
Then the posterior mode (equivalently the mean, by Gaussian symmetry) is
−1
σ2
mn = X⊤ X + I
τ2 d
X⊤ y,
11
Regularisation is a prior. The familiar penalised estimators are MAP estimates under
explicit priors: a Gaussian prior gives ridge (ℓ2 ) regularisation, and a Laplace (double-
exponential) prior gives the lasso (ℓ1 ), whose MAP estimate is sparse. Choosing a penalty
strength is choosing a prior variance. The Bayesian view additionally supplies the full
posterior and hence honest uncertainty on every coecient not just a point estimate.
Proposition 11.3 (Predictive distribution for a new case) . For a new input x∗ ∈ Rd with
y∗ | β ∼ N (x⊤∗ β, σ 2 ), the posterior predictive is Gaussian,
y∗ | y ∼ N x⊤∗ mn , σ 2 + x⊤∗ Vn x∗ .
J
Y Y
π(θ, ϕ | x) ∝ π(ϕ) π(θj | ϕ) p(xij | θj ).
j=1 i
Partial pooling and borrowing strength. The shared prior pulls each group estimate
toward the overall mean by an amount that depends on how noisy that group is: data-
poor groups are shrunk more, data-rich groups less. This borrowing of strength typically
beats both no-pooling and complete-pooling estimates the celebrated Stein phenomenon,
recovered here automatically.
A fully Bayesian treatment integrates over ϕ. A pragmatic shortcut, empirical Bayes, instead
estimatesϕ from the data typically by maximising the marginal likelihood ϕ̂ = arg maxϕ m(x |
R
ϕ) = arg maxϕ p(x | θ)π(θ | ϕ) dθ and then proceeds as if ϕ = ϕ̂.
Example 12.1 (Gaussian empirical Bayes / shrinkage) . xj | θj ∼ N (θj , σ 2 ) (σ 2 known)
Let
τ2
and θj ∼ N (0, τ 2 ). By Theorem 9.5, E[θj | xj ] =
τ 2 +σ 2
xj =: (1 − B)xj with shrinkage factor
σ2
B= σ 2 +τ 2
. Empirical Bayes estimates B from the spread of the observed xj (since marginally
xj ∼ N (0, σ 2 + τ 2 )), giving the data-driven shrinkage estimator θ̂j = (1 − B̂)xj . The estimates
are pulled toward 0, and the worse the signal-to-noise ratio, the harder the pull.
Remark 12.2. Empirical Bayes ignores uncertainty in ϕ̂ and so tends to produce slightly over-
condent intervals; the fully Bayesian (integrate-out) approach is preferable when feasible, and
modern computation (17) usually makes it feasible.
12
13 Point Estimates and Bayesian Decision Theory
Given a loss L(θ, a), the Bayes action minimises the posterior expected loss ρ(a | x) = E[L(θ, a) |
x]. Three classical losses give the three classical summaries.
Theorem 13.1 (Squared-error ⇒ mean). arg mina E[(θ − a)2 | x] = E[θ | x].
Proof. With µ = E[θ | x], E[(θ − a)2 | x] = Var(θ | x) + (µ − a)2 (the cross term vanishes since
E[θ − µ | x] = 0), minimised uniquely at a = µ.
Theorem 13.2 (Absolute-error ⇒ median). arg mina E[|θ − a| | x] is any posterior median.
Proof.
′ (a) = 2F (a) − 1, where F is the
g(a) = E[|θ − a| | x] is convex with right-derivative g+
posterior CDF. This is ≤ 0 below a median and ≥ 0 above it, so the minimum is attained exactly
−
where F (a ) ≤
1
2 ≤ F (a).
Theorem 13.3 (01 loss ⇒ mode (MAP)). Under Lϵ (θ, a) = 1{|θ − a| > ϵ}, the Bayes action
tends toarg maxθ π(θ | x) as ϵ ↓ 0.
R a+ϵ
Proof. E[Lϵ | x] = 1 − a−ϵ π(θ | x) dθ is minimised by maximising local posterior mass; as ϵ ↓ 0,
1
R a+ϵ
2ϵ a−ϵ π(θ | x) dθ → π(a | x), so the maximiser tends to the mode.
Theorem 13.4 (Bayes rules minimise Bayes risk). The estimator δπ that, for each x, minimises
ρ(a | x) also minimises the Bayes risk r(π, δ).
the posterior expected loss
RR R
Proof. By Fubini, r(π, δ) = L(θ, δ(x))p(x | θ)π(θ) dθ dx = ρ(δ(x) | x) m(x) dx. Since
m(x) ≥ 0, minimising the inner integrand ρ(δ(x) | x) pointwise in x minimises the whole
integral.
A decision rule is admissible if no other rule has risk ≤ its risk for all θ with strict inequality
somewhere. A standard result: Bayes rules with proper priors and nite Bayes risk are admissi-
ble, giving Bayesian estimators an automatic optimality guarantee that frequentist constructions
must earn case by case.
Summary. squared error → mean ; absolute error → median ; 01 loss → mode ; and Bayes
rules minimise Bayes risk and are typically admissible.
14 Credible Intervals
Denition 14.1 (Credible set).
R
100(1 − α)% credible set is any C with C π(θ | x) dθ = 1 − α.
A
The equal-tailed interval removes α/2 from each tail; the HPD (highest posterior density) set is
{θ : π(θ | x) ≥ c} with c chosen to give probability 1 − α.
Proposition 14.2 (HPD is shortest) . For a unimodal posterior, the HPD set has the smallest
length among credible sets of its level.
Proof. Any competitor C of equal probability swaps a high-density piece of the HPD set H
(density ≥ c) for a low-density piece outside (< c). Equal probability forces the swapped masses
equal; since density is larger on the discarded piece, its length is smaller, so |C| ≥ |H|.
13
A 95% credible interval genuinely means: given the data, there is a 95% probability θ lies
inside. This is the statement people think a condence interval makes valid only in the
Bayesian framework (18).
This averages the model over the posterior, propagating parameter uncertainty into the fore-
cast strictly more honest than plugging in θ̂, and it yields wider, better-calibrated predictive
intervals.
Example 15.2 (Laplace's Rule of Succession) . With prior Beta(α, β) and x successes in n
α+x x+1
trials, P (x̃ = 1 | x) = E[θ | x] = α+β+n . Under the uniform prior this is n+2 , never exactly 0
or 1: a built-in guard against overcondence from limited data. (Laplace used it to bound the
probability the sun rises tomorrow.)
Example 15.3 (A predictive that is not just a plug-in) . For the GammaPoisson model the
posterior predictive for a new count is Negative Binomial, not Poisson: integrating Poisson(λ)
against Gamma(α + S, β + n) inates the variance beyond the Poisson's mean-equals-variance,
correctly reecting that λ is still uncertain. Over-dispersion is the visible ngerprint of honest
uncertainty propagation.
p(x | M1 )
Denition 16.1 (Bayes factor). BF12 = , the factor by which the data shift the odds
p(x | M2 )
between the two models:
P (M1 | x) P (M1 )
= BF12 · .
P (M2 | x) P (M2 )
| {z } | {z }
posterior odds prior odds
A caution: marginal likelihoods can be sensitive to the within-model priors πk (unlike posteriors,
the dependence does not vanish as n → ∞), so model comparison demands carefully justied
priors.
14
Remark 16.2 (Lindley's paradox) . For a point null M2 : θ = θ0 against a diuse alternative
M1 , it is possible for the same data to reject the null at the frequentist 5% level while the
Bayes factor favours the null. The resolution is that a very diuse alternative spreads its prior
predictive mass thinly, so even a signicant deviation is better explained by the sharp null than
by an alternative that predicted almost nothing in particular. The paradox is a vivid reminder
that p-values and posterior model probabilities answer dierent questions.
17 Computational Methods
R
Outside conjugate models the evidence m(x) = R p(x | θ) π(θ) dθ is an intractable integral, and
so is any posterior expectation E[f (θ) | x] = f (θ)π(θ | x) dθ. Modern Bayesian practice
replaces exact integration with computation.
If we can draw θ(1) , . . . , θ(M ) ∼ π(θ | x), then by the law of large numbers
M
d] = 1
X a.s.
E[f f (θ(m) ) −−−→ E[f (θ) | x],
M
m=1
with Monte Carlo error O(M −1/2 ) independent of the dimension of θ the property that makes
sampling so powerful in high dimensions.
When we cannot sample π(θ | x) but can evaluate it up to a constant, draw θ(m) ∼ q from a
tractable proposal and reweight:
(m) )
p(x | θ(m) )π(θ(m) )
P
wm f (θ
mP
E[f (θ) | x] ≈ , wm = .
m wm q(θ(m) )
The self-normalised form cancels the unknown m(x). Eciency hinges on q resembling the
posterior; heavy-tailed q guards against rare huge weights.
The dominant general tool builds a Markov chain whose stationary distribution is the posterior,
then runs it and treats the (correlated) states as samples.
Theorem 17.1 (MetropolisHastings has the right stationary law) . Let the target be π ∗ (θ) ∝
p(x | θ)π(θ). From state θ, propose θ′ ∼ q(θ′
| θ) and accept it with probability
n π ∗ (θ′ ) q(θ | θ′ ) o
α(θ, θ′ ) = min 1, ∗ ,
π (θ) q(θ′ | θ)
otherwise stay at θ. The resulting chain has π∗ as a stationary distribution.
Proof. It suces to verify detailed balance : π ∗ (θ)P (θ → θ′ ) = π ∗ (θ′ )P (θ′ → θ) for θ ̸= θ′ , where
′ ′ ′
the transition density is P (θ → θ ) = q(θ | θ)α(θ, θ ). Compute
∗ ′ )q(θ|θ ′ )
n o
π ∗ (θ)q(θ′ | θ)α(θ, θ′ ) = π ∗ (θ)q(θ′ | θ) min 1, ππ∗(θ = min π ∗ (θ)q(θ′ | θ), π ∗ (θ′ )q(θ | θ′ ) .
′
(θ)q(θ |θ)
Note the unknown normaliser m(x) cancels in the ratio, so only the unnormalised posterior is
needed.
15
Remark 17.2. Stationarity plus irreducibility and aperiodicity of the chain yields convergence
of the time-average to the posterior expectation (an ergodic theorem). In practice one discards
an initial burn-in, monitors convergence (e.g. the R̂ statistic across several chains), and accounts
for autocorrelation via the eective sample size.
When the full conditionals π(θj | θ−j , x) are available in closed form (as they are in conjugate
hierarchical models), Gibbs sampling cycles through them:
Sketch. Take the proposal for the j -th update to be the full conditional q = π(θj′ | θ−j , x).
∗
Substituting into the acceptance ratio, the joint factors as π (θ) = π(θj | θ−j , x) π(θ−j | x), and
the θ−j factors and the proposal terms cancel, leaving the ratio equal to 1.
For a smooth, sharply peaked posterior, a second-order Taylor expansion of log π ∗ (θ) about its
mode θ̂ gives a Gaussian approximation
−1
Σ = − ∇2 log π ∗ (θ̂)
π(θ | x) ≈ N θ̂, Σ , ,
and a closed-form estimate of the evidence m(x) ≈ π ∗ (θ̂) (2π)d/2 |Σ|1/2 . It is fast and underlies
the BIC, but degrades for skewed or multimodal posteriors, where MCMC or variational infer-
ence (which ts the closest tractable distribution by minimising KullbackLeibler divergence) is
preferred.
16
The condence-interval subtlety. A 95% CI [L(X), U (X)] satises P (L(X) ≤ θ ≤
U (X)) = 0.95 over the random data X with θ xed. After observing data and computing
[2.1, 3.8], the truth either is or is not inside; the 95% is a property of the procedure's
long-run coverage, not of this interval. Only a credible interval licenses there is a 95%
probability θ ∈ [2.1, 3.8].
Honest caveats. prior sensitivity with little data; the appearance of subjectivity; compu-
tational cost outside conjugate models; and the communication risk that audiences misread
credible intervals.
19 Large-Sample Theory
Theorem 19.1 (Posterior consistency, informal) . Under regularity conditions, if the data are
generated by θ0 and the prior assigns positive probability to every neighbourhood of θ0 , then the
posterior concentrates: for any neighbourhood U of θ0 , P (θ ∈ U | x1:n ) → 1 almost surely as
n → ∞. The truth is eventually learned regardless of the (non-dogmatic) prior.
Theorem 19.2 (Bernsteinvon Mises, informal) . Under regularity conditions, the posterior is
asymptotically Gaussian and prior-free:
where In is the observed Fisher information. Consequently Bayesian credible intervals and fre-
quentist condence intervals coincide to leading order.
With abundant data and a reasonable prior, the two paradigms agree numerically: the
likelihood overwhelms the prior, and the posterior centres on the MLE with the classical
variance. The frameworks therefore diverge most and the Bayesian machinery earns its
keep precisely when data are scarce or genuine prior information exists.
(0.99)(0.01) 0.0099
P (D | +) = = ≈ 0.167.
(0.99)(0.01) + (0.05)(0.99) 0.0594
17
A positive test implies only a ≈ 17% disease probability: with a rare disease the prior dominates,
and ignoring base rates yields badly wrong intuition.
Example 20.2 (Coin bias BetaBinomial). Prior Beta(2, 2), data x = 15 heads in n = 20.
Posterior Beta(17, 7) (Theorem 9.2); posterior mean 17 24 ≈ 0.708, between prior mean 0.5 and
20
MLE 0.75 with data weight 24 ≈ 0.833. A 95% equal-tailed credible interval is ≈ [0.51, 0.87]:
given the data, a 95% probability the bias lies there.
Example 20.3 (Arrival rate GammaPoisson) . Prior Gamma(3, 1), data x = (5, 2, 7, 6),
S = 20, n = 4. Posterior Gamma(23, 5) (Theorem 9.4); mean 4.6, variance 0.92. The sample
4
mean 5 shrinks prior mean 3 with weight
toward
5 , and 0.8(5) + 0.2(3) = 4.6. A new-count
forecast uses the Negative-Binomial posterior predictive, wider than a plug-in Poisson.
Example 20.4 (Two-school comparison hierarchical shrinkage) . Two schools report mean
test gains x1 = 8 (σ = 4) x2 = 2 (σ = 4) on small classes. A no-pooling estimate trusts
and
each number; a hierarchical model with θj ∼ N (µ, τ 2 ) shrinks both toward the common mean
x̄ = 5, by more when τ is small (schools are similar) and less when τ is large. The hierarchical
estimates say 6.5 and 3.5 for moderate τ are more reliable predictors of next year's gains
than the raw, noisy class averages.
Example 20.5 (Bayesian A/B testing the probability one variant is better) . An online
experiment shows variant A to nA = 200 users with xA = 30 conversions, and variant B to
nB = 180 users with xB = 36 conversions. Put independent uniform priors θA , θB ∼ Beta(1, 1).
By Theorem 9.2,
Z 1Z 1
P (θB > θA | data) = 1{θB > θA } π(θA )π(θB ) dθA dθB ,
0 0
easily estimated by Monte Carlo: draw many pairs from the two posteriors and report the
fraction with θB > θA (here ≈ 0.91). One can equally report P (θB /θA > 1.1 | data) the
probability B beats A by at least 10% or the posterior of the dierence θB − θA for a full
picture. This is exactly the question a product team asks, answered directly; the frequentist test
answers a dierent, more circuitous one.
1 1
Solution. With H2 = two-headed, P (H2 ) = P (F ) = 2, P (heads | H2 ) = 1, P (heads | F ) = 2.
1· 12 1/2
By Bayes, P (H2 | heads) = 1· 12 + 21 · 12
= 3/4 = 32 .
Exercise 2. For a Beta(α, β) prior and x successes in n trials, give the posterior variance and
its rate in n.
′ ′
Solution. Posterior Beta(a′ , b′ ) with a′ = α + x, b′ = β + n − x. Its variance is (a′ +b′ )2a(ab ′ +b′ +1) .
′ ′ 3
Since a + b = α + β + n, the denominator grows like n while the numerator grows like n , so
2
the variance is O(1/n) posterior uncertainty shrinks at the usual root-n rate.
18
2)
Solution. See the proof of Theorem 9.6: multiply the likelihood ∝ (σ 2 )−n/2 e−W/(2σ by the
∝ (σ 2 )−α−1 e −β/σ 2 Inv-Gamma(α + n2 , β + W
prior and collect exponents to recognise
2 ) with
(xi − µ)2 .
P
W =
Exercise 4. Show the BetaBinomial posterior predictive for k successes in m new trials is the
BetaBinomial distribution.
m
R1
Solution. Integrate the binomial pmf against the Beta(a′ , b′ ) posterior: P (k | x) = k
0 θ (1 −
k
′ ′
θa −1 (1−θ)b −1 m B(a′ +k, b′ +m−k) ′ ′
θ)m−k
B(a′ ,b′ ) dθ = k B(a′ ,b′ ) , which is exactly the BetaBinomial(m, a , b ) pmf.
Exercise 5. Using Theorem 17.1, explain why the unknown normalising constant m(x) never
needs to be computed in MetropolisHastings.
Solution. The acceptance ratio depends on the target only through π ∗ (θ′ )/π ∗ (θ). Writing
∗
π = π̃/m(x) with π̃ = p(x | θ)π(θ) the unnormalised posterior, the factor m(x) cancels, so only
π̃ the easy part is required.
Exercise 6. In Bayesian linear regression with prior β ∼ N (0, τ 2 I), show that as τ 2 → ∞ the
posterior mean tends to the ordinary least-squares estimator β̂OLS = (X X)
⊤ −1 X⊤ y .
⊤ σ 2 −1 ⊤ 2 σ2
Solution. By Corollary 11.2, mn = (X X + 2 I) X y . As τ → ∞ the term 2 I → 0, so
τ τ
mn → (X⊤ X)−1 X⊤ y = β̂OLS . A vague prior recovers the frequentist estimate, consistent with
Bernsteinvon Mises.
Exercise 7. A coin is ipped until the rst head, which occurs on trial k (a Geometric likelihood,
p(k | θ) = (1 − θ)k−1 θ). Show Beta is still conjugate and nd the posterior.
22 Common Misconceptions
1. The likelihood is the probability of θ. No it is the probability of the data read as a
function of θ, and does not integrate to 1 over θ (6).
2. The prior is just an arbitrary fudge. A prior is an explicit, auditable assumption; frequentist
procedures also encode assumptions, only less visibly. With ample data the prior washes out
(Bernsteinvon Mises, Thm. 19.2); with little data, being forced to state assumptions is a
feature, not a bug.
3. A 95% condence interval has a 95% chance of containing θ. False for condence intervals;
true only for credible intervals (14).
4. Flat priors are always non-informative. A prior at in θ is informative in g(θ); non-
informative is not reparameterisation-invariant, which is why Jereys priors exist (7).
5. A bigger Bayes factor always means a better model. Bayes factors depend on within-model
priors and can behave counter-intuitively (Lindley's paradox); they answer which model
predicted these data better, not which model is true.
6. MCMC gives independent samples from the posterior. The draws are correlated ; eective
sample size, burn-in, and convergence diagnostics matter (17).
7. The MAP estimate is the best summary. The mode ignores the shape of the posterior and
is not invariant under reparameterisation; the mean or median, plus an interval, is usually
more informative (13).
19
23 Summary
Bayes' theorem is the unique coherent rule for updating beliefs:
p(x | θ)π(θ)
π(θ | x) = R ∝ p(x | θ) π(θ) .
p(x | θ′ )π(θ′ ) dθ′ | {z } |{z}
likelihood prior
Foundations. Coherence (Dutch-book) and Cox's theorem force rational belief to be prob-
ability; de Finetti's theorem (5) shows exchangeability is equivalent to the model-plus-prior
structure.
Mechanics. prior, likelihood, evidence, posterior; suciency (6) compresses data without
loss; conjugacy (9) and the exponential-family rule (Thm. 10.1) give closed-form updates
whose means are weighted averages of prior and data.
Structure and decisions. hierarchical models and empirical Bayes (12) borrow strength
across groups; decision theory (13) identies mean/median/mode as Bayes estimators and
guarantees admissibility; credible intervals make direct probability statements; the posterior
predictive forecasts honestly.
Comparison and computation. Bayes factors (16) compare models with a built-in Occam
penalty; MCMC, Gibbs, importance sampling, and the Laplace approximation (17) make
all of it computable.
Relation to frequentism. The two agree asymptotically (Bernsteinvon Mises), and the
Bayesian approach is most valuable when data are scarce or prior knowledge is real, at the
cost of prior sensitivity and computation.
20