Bayesian inference §
Bayesian inference is the task of computing the full posterior distribution of a parameter given observed data. It combines a prior distribution (encoding prior knowledge or indifference) with a likelihood (encoding the data) via Bayes’ theorem. It is the natural framework for sequential updating, decision-making under uncertainty, and quantifying epistemic uncertainty—the uncertainty about the parameter itself, which shrinks as data accumulates, in contrast to aleatoric uncertainty (irreducible randomness in the data-generating process that no amount of data can eliminate).
Authoritative sources
Bayes’ theorem §
Given a prior and a likelihood :
The denominator (marginal likelihood or evidence) normalizes the posterior.
Details
Bayes’ theorem is an application of Conditional probability to the parameter. The key components:
- Prior : encodes beliefs before seeing the data. Can be informative (based on previous studies) or diffuse (weakly informative, e.g., for a location parameter).
- Likelihood : the sampling model, same as in Estimation.
- Posterior : the updated belief. All uncertainty about is captured by this distribution.
- Evidence : the marginal probability of the data. Used for model comparison (Bayes factors).
The posterior mean, median, and mode are all valid point summaries. The posterior credible interval is the Bayesian analogue of the confidence interval: a 95% credible interval contains the true parameter with probability 0.95 (under the posterior).
Visual intuition. The posterior is proportional to the pointwise product of the prior and the likelihood. The diagram below shows a typical case: a broad prior, a narrow likelihood centred away from the prior mean, and the resulting posterior that is pulled toward the likelihood but retains some of the prior’s spread.
Prior selection §
When no strong prior knowledge exists, the choice of prior still matters. Objective priors are constructed from the model structure itself, aiming to encode minimal or “indifference” information.
Details
-
Jeffreys prior. Derived from the Fisher information matrix : . It is invariant under reparameterization and is the most common “default” objective prior. For a Bernoulli model, , giving , i.e., (the Haldane–Jeffreys prior).
-
Reference prior. Defined by Berger and Robert (1984) as the prior that maximizes the expected Kullback–Leibler divergence between the posterior and the prior. It is unique up to a constant and is designed so that the posterior is as “informative” as possible. For a Normal mean with known variance, the reference prior is flat: .
-
Haldane prior. The improper prior for a Bernoulli parameter. It encodes complete indifference (zero prior pseudo-observations) and yields a posterior that places zero mass at the boundaries and .
-
Flat (uniform) prior. on the parameter space. Simple but not invariant under reparameterization: a uniform prior on does not imply a uniform prior on .
The choice of prior affects the posterior, especially with small samples. With large , the likelihood dominates and the posterior becomes prior-insensitive (the Bernstein–von Mises theorem).
Authoritative sources
Conjugate priors §
A prior is conjugate to a likelihood if the posterior belongs to the same parametric family as the prior.
Details
Conjugacy gives closed-form posteriors, enabling exact computation without MCMC. It also makes sequential updating trivial: the posterior after batch 1 becomes the prior for batch 2.
| Likelihood | Prior | Posterior | Sufficient statistic |
|---|---|---|---|
| Bernoulli / Binomial | Beta(α, β) | Beta(α + s, β + n − s) | s (number of successes) |
| Normal (known σ²) | Normal(μ₀, τ₀²) | Normal(μₙ, τₙ²) | x̄ (sample mean) |
| Poisson | Gamma(α, β) | Gamma(α + Σxᵢ, β + n) | Σxᵢ (sum of counts) |
| Gamma (known rate) | Gamma(α, β) | Gamma(α + n, β + Σxᵢ) | Σxᵢ (sum of observations) |
| Exponential (known rate) | Gamma(α, β) | Gamma(α + n, β + Σxᵢ) | Σxᵢ |
| Multinomial | Dirichlet(α₁,…,αₖ) | Dirichlet(α₁+n₁,…,αₖ+nₖ) | (n₁,…,nₖ) (cell counts) |
Example. Flipping a coin: prior (uniform). After 7 heads and 3 tails, the posterior is with mean .
MCMC and posterior computation §
When the posterior has no closed form, Markov Chain Monte Carlo (MCMC) methods approximate it by constructing a Markov chain whose stationary distribution is the target posterior.
Details
Metropolis–Hastings. At each step, given the current state , draw a proposal from a proposal distribution (often a symmetric random walk, e.g., with ). Accept the move with probability
For a symmetric proposal (), this reduces to the ratio of posterior densities. If rejected, the chain stays at . The tuning parameter controls the acceptance rate; an optimal acceptance rate for random-walk MH in one dimension is about 0.44.
Hamiltonian Monte Carlo (HMC) / NUTS. Augments the parameter with a momentum variable and simulates Hamiltonian dynamics using gradients of the log-posterior. This allows large, correlated moves that explore the posterior efficiently, especially in moderate dimensions. The No-U-Turn Sampler (NUTS) adapts the trajectory length automatically.
Variational inference. Approximates the posterior with a simpler family (e.g., a Gaussian) by minimizing the KL divergence . Faster than MCMC but introduces approximation bias.
Convergence diagnostics. Because MCMC samples are autocorrelated, one must verify that the chain has reached stationarity and is mixing well:
- Gelman–Rubin (R-hat): run multiple chains from different starting points; (typically < 1.01) indicates convergence.
- Effective sample size (ESS): the number of independent samples equivalent to the autocorrelated chain. A rule of thumb is ESS > 400 for reliable quantile estimates.
- Trace plots and autocorrelation plots provide visual confirmation.
The choice of method depends on dimensionality and smoothness:
- Low dimension, smooth: HMC/NUTS (as in Stan, PyMC).
- High dimension, sparse: coordinate-wise MCMC or variational methods.
- Very high dimension: variational inference or normalizing flows.
The posterior is a Distribution in its own right: it has a mean, variance, quantiles, and can be used for prediction via the posterior predictive distribution.
Posterior predictive distribution §
To predict a new observation given the data , one integrates over the posterior:
Details
The posterior predictive distribution accounts for both the data-generating uncertainty (aleatoric) and the parameter uncertainty (epistemic). It is wider than the likelihood evaluated at the posterior mean because it averages over the spread of the posterior.
Uses:
- Prediction: sample (e.g., from MCMC), then . The collection approximates the predictive distribution.
- Model checking (posterior predictive checks): generate replicated datasets from the posterior predictive and compare summary statistics (mean, variance, extremes) to the observed data. Large discrepancies indicate model misspecification.
- Bayesian forecasting: in time-series models, the posterior predictive gives a full predictive distribution with credible intervals that widen further into the future as parameter uncertainty accumulates.
For a conjugate model the posterior predictive often has a closed form. For example, with a Bernoulli likelihood and Beta(α, β) prior, after observing successes in trials, the posterior predictive for the next flip is a Beta-Binomial: .
Bayes factors and model comparison §
The Bayes factor comparing models and is
Details
A Bayes factor favors ; favors . It is the ratio of marginal likelihoods and automatically penalizes model complexity (Occam’s factor): a more complex model spreads its prior over more parameter values, reducing the marginal likelihood.
A common qualitative scale (Jeffreys, 1961):
| |log₁₀ BF| | Interpretation |
|---|---|
| 0 – 0.5 | Anecdotal |
| 0.5 – 1 | Substantial |
| 1 – 1.5 | Strong |
| 1.5 – 2 | Very strong |
| > 2 | Decisive |
This connects to Hypothesis testing: the Bayes factor is the Bayesian analogue of the likelihood ratio test, but it integrates over the parameter space rather than maximizing.
Example. Testing vs. with a Normal model. The Bayes factor depends on the prior width under and the sample size. For large , it approximates the BIC (Bayesian Information Criterion) comparison.
Example problem §
Problem. A coin is flipped times, yielding heads. The prior is . (a) Find the posterior distribution. (b) Compute the posterior mean and a 95% credible interval. (c) Compute the Bayes factor for vs. (using the Beta prior as the model).
Solution
(a) The posterior is .
(b) The posterior mean is . The 95% credible interval is approximately (from the Beta(16, 8) quantiles: 2.5th percentile ≈ 0.47, 97.5th percentile ≈ 0.836).
(c) The marginal likelihood under (Beta(2,2) prior) is
Under : .
The Bayes factor , providing anecdotal evidence against (Jeffreys scale: corresponds to ).