Technopedia

The technologist’s encyclopedia

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 π(θ)\pi(\theta) and a likelihood p(x∣θ)p(x \mid \theta):

π(θ∣x)=p(x∣θ) π(θ)∫p(x∣θ′) π(θ′) dθ′\pi(\theta \mid x) = \frac{p(x \mid \theta)\, \pi(\theta)}{\int p(x \mid \theta')\, \pi(\theta')\, d\theta'}

The denominator (marginal likelihood or evidence) normalizes the posterior.

Details

Bayes’ theorem is an application of Conditional probability to the parameter. The key components:

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 π(θ) Likelihood p(x|θ) Posterior π(θ|x) posterior ∝ prior × likelihood

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

The choice of prior affects the posterior, especially with small samples. With large nn, the likelihood dominates and the posterior becomes prior-insensitive (the Bernstein–von Mises theorem).

Authoritative sources

Conjugate priors

A prior π(θ)\pi(\theta) is conjugate to a likelihood p(x∣θ)p(x \mid \theta) 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.

LikelihoodPriorPosteriorSufficient statistic
Bernoulli / BinomialBeta(α, β)Beta(α + s, β + n − s)s (number of successes)
Normal (known σ²)Normal(μ₀, τ₀²)Normal(μₙ, τₙ²)x̄ (sample mean)
PoissonGamma(α, β)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ᵢ
MultinomialDirichlet(α₁,…,αₖ)Dirichlet(α₁+n₁,…,αₖ+nₖ)(n₁,…,nₖ) (cell counts)

Example. Flipping a coin: prior θ∼Beta(1,1)\theta \sim \text{Beta}(1, 1) (uniform). After 7 heads and 3 tails, the posterior is Beta(8,4)\text{Beta}(8, 4) with mean 8/12=0.6678/12 = 0.667.

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 θt\theta_t, draw a proposal θ∗∼q(⋅∣θt)\theta^* \sim q(\cdot \mid \theta_t) from a proposal distribution qq (often a symmetric random walk, e.g., θ∗=θt+ϵ\theta^* = \theta_t + \epsilon with ϵ∼N(0,σ2)\epsilon \sim \mathcal{N}(0, \sigma^2)). Accept the move with probability

α=min⁡ ⁣(1,  π(θ∗∣x) q(θt∣θ∗)π(θt∣x) q(θ∗∣θt))\alpha = \min\!\left(1,\; \frac{\pi(\theta^* \mid x)\, q(\theta_t \mid \theta^*)}{\pi(\theta_t \mid x)\, q(\theta^* \mid \theta_t)}\right)

For a symmetric proposal (q(θt∣θ∗)=q(θ∗∣θt)q(\theta_t|\theta^*) = q(\theta^*|\theta_t)), this reduces to the ratio of posterior densities. If rejected, the chain stays at θt\theta_t. The tuning parameter σ\sigma 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 KL(q(θ)∥π(θ∣x))\text{KL}(q(\theta) \| \pi(\theta|x)). 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:

The choice of method depends on dimensionality and smoothness:

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 xnewx_{\text{new}} given the data xx, one integrates over the posterior:

p(xnew∣x)=∫p(xnew∣θ) π(θ∣x) dθp(x_{\text{new}} \mid x) = \int p(x_{\text{new}} \mid \theta)\, \pi(\theta \mid x)\, d\theta
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:

For a conjugate model the posterior predictive often has a closed form. For example, with a Bernoulli likelihood and Beta(α, β) prior, after observing ss successes in nn trials, the posterior predictive for the next flip is a Beta-Binomial: P(xnew=1∣x)=(α+s)/(α+β+n)P(x_{\text{new}}=1 \mid x) = (\alpha+s)/(\alpha+\beta+n).

Bayes factors and model comparison

The Bayes factor comparing models M0M_0 and M1M_1 is

BF10=p(x∣M1)p(x∣M0)=∫p(x∣θ1) π(θ1) dθ1∫p(x∣θ0) π(θ0) dθ0BF_{10} = \frac{p(x \mid M_1)}{p(x \mid M_0)} = \frac{\int p(x \mid \theta_1)\, \pi(\theta_1)\, d\theta_1}{\int p(x \mid \theta_0)\, \pi(\theta_0)\, d\theta_0}
Details

A Bayes factor BF10>1BF_{10} > 1 favors M1M_1; BF10<1BF_{10} < 1 favors M0M_0. 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.5Anecdotal
0.5 – 1Substantial
1 – 1.5Strong
1.5 – 2Very strong
> 2Decisive

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 H0:μ=0H_0: \mu = 0 vs. H1:μ≠0H_1: \mu \neq 0 with a Normal model. The Bayes factor depends on the prior width under H1H_1 and the sample size. For large nn, it approximates the BIC (Bayesian Information Criterion) comparison.

Example problem

Problem. A coin is flipped n=20n = 20 times, yielding s=14s = 14 heads. The prior is θ∼Beta(2,2)\theta \sim \text{Beta}(2, 2). (a) Find the posterior distribution. (b) Compute the posterior mean and a 95% credible interval. (c) Compute the Bayes factor for H0:θ=0.5H_0: \theta = 0.5 vs. H1:θ≠0.5H_1: \theta \neq 0.5 (using the Beta prior as the H1H_1 model).

Solution

(a) The posterior is Beta(2+14,  2+6)=Beta(16,8)\text{Beta}(2 + 14,\; 2 + 6) = \text{Beta}(16, 8).

(b) The posterior mean is 16/(16+8)=2/3≈0.66716/(16+8) = 2/3 \approx 0.667. The 95% credible interval is approximately [0.47,  0.84][0.47,\; 0.84] (from the Beta(16, 8) quantiles: 2.5th percentile ≈ 0.47, 97.5th percentile ≈ 0.836).

(c) The marginal likelihood under H1H_1 (Beta(2,2) prior) is

p(x∣H1)=(2014)B(16,8)B(2,2)=(2014)Γ(16) Γ(8)Γ(24)⋅6≈0.059p(x \mid H_1) = \binom{20}{14} \frac{B(16, 8)}{B(2, 2)} = \binom{20}{14} \frac{\Gamma(16)\,\Gamma(8)}{\Gamma(24)} \cdot 6 \approx 0.059

Under H0:θ=0.5H_0: \theta = 0.5: p(x∣H0)=(2014)(0.5)20≈0.037p(x \mid H_0) = \binom{20}{14}(0.5)^{20} \approx 0.037.

The Bayes factor BF10=p(x∣H1)/p(x∣H0)≈1.6BF_{10} = p(x \mid H_1)/p(x \mid H_0) \approx 1.6, providing anecdotal evidence against H0H_0 (Jeffreys scale: 1<BF<31 < BF < 3 corresponds to log⁡10BF<0.5\log_{10} BF < 0.5).