Bayesian Statistics
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).
- Gamma Prior & Poisson Likelihood Gamma Posterior. (Used for rate parameter 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.
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
Read the code, make a small change, then run it and inspect the output. Runtime setup messages stay outside the terminal so the result remains focused on what the program prints.