Frequentist statistics interprets probability strictly as the long-run expected frequency of repeatable events. Bayesian statistics interprets probability fundamentally differently: as a degree of belief or a quantification of uncertainty. The Bayesian paradigm provides a rigorous mathematical framework for evaluating and updating our state of knowledge as new data becomes available.
The Foundation: Bayes’ Theorem
The core operating principle of Bayesian inference is Bayes’ Theorem, a mathematical identity derived from the definition of conditional probability:
Where:
(Posterior): The probability of the hypothesis after observing data . This represents the updated state of belief.
(Likelihood): The probability of observing the data assuming the hypothesis is true. This quantifies the evidence generated by the data.
(Prior): The initial degree of belief in the hypothesis before observing the data .
(Evidence or Marginal Likelihood): The total probability of observing the data across all possible hypotheses. It acts as a normalizing constant to ensure the posterior is a valid probability distribution: .
Because the denominator does not depend on , Bayes’ theorem is often written as a proportionality:
Frequentist vs. Bayesian Comparison
The differences between the two schools of thought run deep, impacting how inference is conducted and interpreted.
Parameters: In frequentist statistics, parameters (like the true mean of a population) are fixed but unknown constants. In Bayesian statistics, parameters are treated as random variables described by probability distributions.
Data: Frequentists view the observed data as one possible realization from an infinite sequence of hypothetical repetitions. Bayesians treat the observed data as fixed and use it to calculate the probability of the parameter taking on various values.
Confidence Intervals vs. Credible Intervals: A frequentist 95% confidence interval means that if the experiment were repeated infinitely, 95% of the constructed intervals would contain the fixed parameter. A Bayesian 95% credible interval directly means there is a 95% probability that the parameter lies within that interval, given the observed data and prior belief.
The Role and Selection of Priors
The choice of the prior distribution is a critical and sometimes criticized aspect of Bayesian analysis. Priors encode expert knowledge and initial assumptions.
Informative vs. Uninformative Priors
An informative prior asserts specific, strong beliefs about the parameter space. For example, if measuring human height, a prior tightly clustered around meters is highly informative.
An uninformative (or diffuse) prior spreads probability mass across the parameter space, attempting to let the data “speak for itself.” A uniform distribution is a common example, though true non-informativeness is mathematically subtle.
Conjugate Priors
A prior is conjugate to a specific likelihood function if the resulting posterior distribution belongs to the same probability family as the prior. Conjugacy provides immense mathematical convenience because the posterior can be derived algebraically without complex numerical integration.
Examples of natural conjugate pairs include:
Beta Prior & Binomial Likelihood Beta Posterior. (Used for probabilities and proportions).
Normal Prior & Normal Likelihood (known variance) Normal Posterior. (Used for continuous mean estimation).
Consider the Beta-Binomial model. If the prior for the probability of success is and the newly observed data contains successes and failures, the posterior is simply:
Jeffreys Prior
When seeking an uninformative prior, a flat uniform distribution can be problematic because it is not invariant under parameter transformations (e.g., a uniform prior on the standard deviation is not uniform on the variance ).
The Jeffreys Prior solves this by deriving the prior directly from the Fisher Information of the likelihood function:
This guarantees that the prior remains uninformative regardless of how the parameter is parameterized mathematically.
Computational Bayesian Inference: MCMC and Gibbs Sampling
Historically, the difficulty of computing the normalizing constant analytically restricted Bayesian methods to conjugate models. The advent of modern computing and Markov Chain Monte Carlo (MCMC) algorithms revolutionized Bayesian statistics, allowing inference on virtually any model.
Markov Chain Monte Carlo
MCMC algorithms do not attempt to calculate the posterior distribution analytically. Instead, they draw a vast number of correlated samples directly from the posterior space. By analyzing these samples (e.g., taking the mean, variance, or percentiles of the samples), we can estimate the properties of the posterior distribution.
The algorithm constructs a Markov Chain—a sequence of states where the next state depends only on the current state—designed such that its stationary distribution is exactly the target posterior distribution.
Gibbs Sampling
A specialized and highly effective MCMC algorithm for multi-dimensional parameter spaces is Gibbs Sampling. Instead of trying to update all parameters simultaneously, Gibbs sampling updates one parameter at a time by sampling from its conditional distribution, keeping all other parameters fixed at their current values.
Let . A Gibbs step involves:
Sample from
Sample from
Sample from
This iterative process vastly simplifies the sampling problem because the one-dimensional conditional distributions are often well-known and easy to sample from, even when the joint multidimensional posterior is impossibly complex.
The Medical Test Paradox
You are a doctor administering a test for a rare genetic marker present in 0.1% (p=0.001) of the population. The test's sensitivity (true positive rate) is 99% (P(Positive|Marker) = 0.99). The test's specificity (true negative rate) is 98%, meaning the false positive rate is 2% (P(Positive|No Marker) = 0.02). A patient receives a positive test result. The patient immediately asks: 'What is the probability I actually have the marker?'
Calculate the Posterior probability that the patient has the genetic marker given the positive result.
Answer: ~4.7%
Using Bayes' Theorem: P(H|D) = [P(D|H) * P(H)] / P(D). P(H) = 0.001. P(D|H) = 0.99. P(D) is the total probability of a positive test: [P(Positive|Marker) * P(Marker)] + [P(Positive|No Marker) * P(No Marker)] = [0.99 * 0.001] + [0.02 * 0.999] = 0.00099 + 0.01998 = 0.02097. Finally, P(H|D) = 0.00099 / 0.02097 ≈ 0.0472 or 4.7%.
The Medical Test Paradox
You are a doctor administering a test for a rare genetic marker present in 0.1% (p=0.001) of the population. The test's sensitivity (true positive rate) is 99% (P(Positive|Marker) = 0.99). The test's specificity (true negative rate) is 98%, meaning the false positive rate is 2% (P(Positive|No Marker) = 0.02). A patient receives a positive test result. The patient immediately asks: 'What is the probability I actually have the marker?'
Calculate the Posterior probability that the patient has the genetic marker given the positive result.
Implementation: Bayesian Continuous Updating
Below is an illustration utilizing the Beta-Conjugate prior for a binomial likelihood, perfectly modeling the continuous updating of beliefs about a coin’s hidden fairness parameter. Observe how the posterior from one experiment becomes the prior for the next.
Interactive Lab
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import beta
# True underlying probability (unknown to the model)
true_p = 0.75
# Experiment configurations
# Series of observations: (heads observed, tails observed)
batches = [(0, 0), (2, 0), (5, 2), (20, 5), (70, 25)]
# Initial belief: Beta(1, 1) represents a Uniform distribution
alpha_prior, beta_prior = 1, 1
x = np.linspace(0, 1, 200)
print(f"{'Data (H, T)':<15} | {'Alpha':<6} | {'Beta':<6} | {'Posterior Mean':<15}")
print("-" * 50)
# Iterative Bayesian updating
for heads, tails in batches:
# Update rule: add standard sufficient statistics directly to parameters
alpha_post = alpha_prior + heads
beta_post = beta_prior + tails
post_mean = alpha_post / (alpha_post + beta_post)
print(f"{str((heads, tails)):<15} | {alpha_post:<6} | {beta_post:<6} | {post_mean:.4f}")
# The current posterior becomes the prior for the next batch of data!
alpha_prior, beta_prior = alpha_post, beta_post
print("
As N grows, the Posterior Mean converges to the true underlying parameter (0.75).")
python
1import numpy as np
2import matplotlib.pyplot as plt
3from scipy.stats import beta
4
5# True underlying probability (unknown to the model)
6true_p =0.75
7
8# Experiment configurations
9# Series of observations: (heads observed, tails observed)
33As N grows, the Posterior Mean converges to the true underlying parameter (0.75).")
34
Exercises
Knowledge Check
In the context of Bayesian statistics, what is the defining characteristic of a Conjugate Prior?
Answer: It guarantees the resulting posterior distribution is within the same probability distribution family as the prior.
A conjugate prior is an algebraic convenience. When combined with a specific likelihood function, it yields a posterior distribution of the same family (e.g., Beta prior + Binomial Likelihood = Beta posterior).
In the context of Bayesian statistics, what is the defining characteristic of a Conjugate Prior?
Knowledge Check
How does Gibbs Sampling simplify the process of evaluating a complex, high-dimensional posterior distribution?
Answer: By breaking the multi-dimensional sampling problem into a sequence of simpler one-dimensional conditional probability samples.
Gibbs Sampling iterates through each variable, sampling its value conditionally based on the current values of all other variables. This means you only ever sample from one-dimensional distributions rather than the full joint distribution directly.
How does Gibbs Sampling simplify the process of evaluating a complex, high-dimensional posterior distribution?
Knowledge Check
Which interpretation correctly identifies a key difference between frequentist Confidence Intervals and Bayesian Credible Intervals?
Answer: A Credible Interval states there is a 95% probability the fixed, unknown parameter lies within it; a Confidence Interval states that 95% of constructed intervals contain the true parameter.
A Bayesian credible interval directly gives the probability map of the parameter itself (since parameters are random variables). The frequentist confidence interval evaluates the reliability of the interval generation procedure upon repeated sampling, not the probability of the parameter falling in the specific current interval.
Which interpretation correctly identifies a key difference between frequentist Confidence Intervals and Bayesian Credible Intervals?