Bayesian Inference: An Introduction
Suppose a coin is tossed ten times and lands heads eight times. What is the probability that the coin is fair? A classical statistician refuses to answer this question as posed. On that view, probability describes long-run frequencies of repeatable events. "The coin is fair" is a fixed fact, not a random variable. So it has no probability at all. A Bayesian statistician answers directly. The unknown bias is treated as a random quantity with a probability distribution. This distribution gets updated by data. This article develops that second viewpoint rigorously. It shows how a prior distribution on an unknown parameter combines with a likelihood through Bayes' rule. Together they produce a posterior distribution. It also compares this machinery, both philosophically and mathematically, to the frequentist estimation theory built around Maximum Likelihood Estimation. The idea matters because it resolves a genuine ambiguity in what "inference" is for. Frequentist procedures — point estimators, confidence intervals, -values — are evaluated by their behavior under hypothetical repetition of the data-generating experiment. They hold the unknown parameter fixed. Bayesian procedures instead update a degree of belief about the parameter. They treat the observed data as fixed and the parameter as the random object of interest. These are different mathematical objects answering different questions. Confusing them is one of the most common errors in applied statistics. One example is reading a 95% confidence interval as "95% probability the parameter lies here." The big picture is a single equation. Given a prior density encoding what is believed about a parameter before seeing data, and a likelihood describing how probable the observed data would be under each value of , Bayes' rule produces a posterior density . This single line of algebra, iterated over an entire course, generates estimation, credible intervals, model comparison, and prediction. All of this comes from one coherent probabilistic calculus. It does not rely on a toolbox of separately-justified procedures. This article gives the formal definition of prior, likelihood, and posterior. It states and proves the fundamental theorem. This theorem shows the posterior is a genuine probability distribution obtained by conditioning. It works two fully asymmetric numerical examples: a Beta–Bernoulli update and a Normal–Normal update with unequal variances. It shows via counterexample why an improper prior can produce a non-existent posterior. It closes with a comparison table separating Bayesian from frequentist claims. It also includes real applications in statistics, machine learning, and law.
- A prior encodes belief about parameter before data; the likelihood is the probability (or density) of the observed data as a function of .
- Bayes' rule turns these into a posterior , a full probability distribution over given the data.
- The posterior is not a heuristic: it is literally the conditional distribution of given in the joint model , so its validity follows from ordinary conditional probability once is given a distribution.
- Bayesian point estimates (posterior mean/median/mode) and credible intervals answer "what do I believe about given this data?", unlike frequentist confidence intervals which answer "how would this procedure behave over repeated sampling?".
- Conjugate priors (Beta–Bernoulli, Normal–Normal, Gamma–Poisson) make posteriors computable in closed form and reveal the update as a weighted combination of prior belief and data.
- Key idea: treating the unknown parameter itself as random converts inference into ordinary conditioning, replacing the frequentist's repeated-sampling guarantees with a single, internally consistent probability statement about given the data actually observed.
Where this lives today
Bayesian inference underlies modern hierarchical models in medicine and social science, where partial pooling across groups (patients, schools, hospitals) is naturally expressed by placing a prior on group-level parameters that itself has hyperparameters. In machine learning, Bayesian methods appear as regularization: a Gaussian prior on regression weights combined with a Gaussian likelihood yields ridge regression as the posterior mode, while a Laplace prior yields the LASSO — turning penalized optimization into a special case of MAP estimation, echoing the corollary above. Spam filters and early Bayesian classifiers apply Bayes' rule directly to word-frequency likelihoods and class priors. In forensic and legal statistics, likelihood ratios update prior odds of guilt into posterior odds given DNA or other evidence, a direct application of Bayes' rule in odds form. A/B testing in industry increasingly uses posterior probabilities that one variant beats another, replacing -values with direct probability statements decision-makers find easier to interpret. In physics and cosmology, Bayesian model comparison via marginal likelihoods (Bayes factors) is standard for comparing competing cosmological models against the same data, and Markov chain Monte Carlo methods — built to sample posteriors that have no closed conjugate form — are now central computational tools across Statistical Inference broadly, extending the Beta–Bernoulli and Normal–Normal calculations above to essentially arbitrary models.
:::quiz[A 95% Bayesian credible interval [a,b] for θ given observed data x formally asserts which statement?]
- P(a ≤ θ ≤ b) = 0.95 over repeated sampling of X with θ fixed
- P(θ ∈ [a,b] | X = x) = 0.95, a posterior probability given the observed data ✓
- 95% of all possible datasets would produce an interval containing the true θ
- The MLE lies in [a,b] with probability 0.95
Ask the tutor: Can you show how to derive the Normal–Normal posterior formula by completing the square in the exponent, step by step?
A Bayesian statistical model consists of: 1. A parameter space and a random variable (or vector) taking values in , with a specified prior distribution having density or mass function . 2. A family of conditional distributions for data given , with density/mass function , defined for in a sample space . Given an observed value , the likelihood function is
regarded as a function of for the fixed observed . The posterior distribution of given is the conditional density/mass function
(with the integral replaced by a sum if is discrete), defined for every with . The normalizing constant is called the marginal likelihood or prior predictive density of . A prior is called proper if integrates (or sums) to over ; it is called improper if , in which case is not itself a probability density but the formula for may still define a valid posterior provided .
Intuition
Think of the prior as a landscape of belief spread over all possible parameter values before any data arrives — flat if you are ignorant, peaked if you have strong prior information. The likelihood, as a function of for the fixed observed data, is a second landscape: it is tall wherever the observed data would have been probable, and near zero wherever the data would have been a surprise. Bayes' rule multiplies these two landscapes together, point by point in , and then rescales the product so that it integrates to . The posterior is literally the shape you get by pinching the prior toward the region where the likelihood is large, in proportion to how much data-evidence exists there. This is exactly the same operation as computing a conditional probability of an event given : restrict attention to the world where happened, and renormalize. Here is "the data equal ," and ranges over all possible values of ; the posterior is the conditional law of given in the joint distribution built from prior times likelihood. Two forces determine how much the posterior moves from the prior toward the likelihood: how much data has been collected (more data sharpens and relocates the likelihood), and how informative the prior was to begin with (a very peaked, confident prior resists being moved).
Contrast with frequentist estimation
A frequentist estimator, such as the maximum likelihood estimator , treats as a fixed unknown constant and studies the sampling distribution of over hypothetical repetitions of the experiment. It never assigns a probability distribution to itself. The Bayesian instead builds a full distribution , of which the MLE and the posterior mode coincide exactly when the prior is flat (constant) — a fact proved below — showing the two frameworks are not opposed so much as nested, with the frequentist point estimate emerging as a limiting Bayesian case.
Let be a random variable with prior density on , and let have conditional density on , jointly measurable in . Suppose: (i) is a proper density, i.e. ; (ii) for the observed value , the marginal satisfies . Then: 1. The pair has a well-defined joint density , and has marginal density . 2. For every with , the conditional density of given exists and equals
3. is a genuine probability density on : it is nonnegative and integrates to .
We use the definition of joint and conditional densities directly; this is a rigorous instance of conditioning, not an ad hoc rule.
Step 1 (joint density). Define for . This is nonnegative since both factors are nonnegative densities. We check it integrates to over the product space, using Tonelli's theorem (all integrands are nonnegative, so order of integration is free):
where the inner integral is because is a probability density for each fixed , and the outer integral is by hypothesis (i). Hence is a legitimate joint density for the pair , meaning we may define the joint law of to have this density — this is precisely the standard construction "prior times conditional likelihood equals joint," justified because Tonelli guarantees total mass .
Step 2 (marginal of ). By definition of a marginal density from a joint density,
which is exactly the in the statement, and is itself a valid density for since by Step 1.
Step 3 (conditional density). For real-valued random vectors with a jointly defined density and marginal , the conditional density of given is defined, whenever , by
This is precisely the density-level analogue of the elementary conditional probability formula : for any Borel set , one can verify directly that
computes, via the disintegration of the joint law, the conditional probability in the limiting sense that underlies conditional densities. Substituting gives exactly
which is the claimed formula. Since hypothesis (ii) guarantees for the observed , this conditional density is well-defined and finite-valued (as a function of , up to the pointwise value of , which is finite for a.e. since it is integrable).
Step 4 (posterior is a probability density). Nonnegativity of is immediate since it is a ratio of nonnegative quantities with positive denominator. For total mass,
using the definition of from Step 2. Hence is nonnegative and integrates to , i.e. it is a genuine probability density on .
∎Let be constant on a bounded (a proper "flat" prior), and suppose has a unique maximizer . Then the posterior mode
equals .
By Bayes' rule for statistical models, and posterior propriety, . As a function of (with fixed), the factor is a positive constant not depending on , so maximizing over is equivalent to maximizing over . By uniqueness of the maximizer of , the two arg-maxes coincide.
∎Worked examples
Example 1 — Beta–Bernoulli update with asymmetric numbers. A quality-control engineer wants to estimate the defect probability of a manufacturing line. She encodes mild prior belief that defects are somewhat uncommon using a prior:
The prior mean is . She then inspects items independently, each defective with probability , and observes defects. The likelihood is Binomial in form (as a function of , up to a combinatorial constant that does not depend on ):
By Bayes' rule,
This unnormalized kernel is exactly the kernel of a density (parameters: exponent of is , exponent of is ), so
The normalizing constant is automatically , and we did not need to compute directly because we recognized the conjugate form — this is the payoff of conjugacy. The posterior mean is
Compare this to the MLE, , and to the prior mean . The posterior mean sits strictly between the prior mean and the MLE — a general feature of conjugate Beta–Bernoulli updating, since
a weighted average of the prior mean and the MLE , with weights and . Numerically,
confirming the closed form. As grows with fixed, the weight on the MLE tends to : the data eventually dominates the prior, regardless of its exact shape, as long as the prior places positive density near the true . A 95% equal-tailed credible interval is obtained from the quantiles of ; numerically this distribution has approximately as its 2.5% and 97.5% quantiles (computed from the Beta CDF), giving the Bayesian statement: "given the data and the stated prior, there is a 95% posterior probability that lies in ." This is a direct probability statement about , unlike a frequentist confidence interval.
Example 2 — Normal–Normal update with unequal, asymmetric variances. An analyst measures the true (unknown) mean return of an asset. Prior belief, from a separate model, is
A single noisy observation of the return is available, modeled as
reflecting that the measurement is more precise than the prior (). Suppose is observed. The likelihood as a function of is
Multiplying by the prior density and completing the square in the exponent (standard conjugate Normal–Normal algebra) gives a Normal posterior
with
So . Sanity checks: the posterior variance is smaller than both and — combining two independent pieces of information can only sharpen belief, never dilute it, since precisions () add. The posterior mean lies between the prior mean and the data value , and — because the data is three times more precise than the prior ( vs. , a ratio of the total precision ) — it lies closer to than to ; indeed divides in the ratio , exactly matching the precision ratio, since
A 95% credible interval is .
The theorem requires for the observed ; when this hypothesis fails the "posterior" formula is meaningless as a probability. Consider estimating a Normal mean with a single observation , but now use the improper uniform prior on the whole real line,
This particular case is actually benign — the reader should check that where is the standard normal density, since the Gaussian likelihood integrates over just as it does over , so a proper posterior still exists even from this improper flat prior. The genuine failure appears when the tails of the likelihood in do not decay fast enough. Take instead the (deliberately pathological, but formally admissible as a "likelihood") model
replaced, more cleanly, by the following standard example: let be a rate parameter with the improper prior
often used to express "scale invariance," and suppose we observe successes from a single waiting time truncated so that only is informative in a degenerate limiting sense — more directly: suppose the data model is with density , and we use prior . Then
which is finite for every — so this particular combination is in fact fine (a proper -type posterior in results). To see a genuine breakdown, push the prior further: take on together with the same exponential likelihood. Now
and this integral diverges at (the integrand behaves like near , which is not integrable) for every . Hence for all observed data, hypothesis (ii) of the theorem fails everywhere, and
is identically (or undefined, ) rather than a probability density: no posterior exists, no matter what data is observed. This shows that properness of the marginal — not just of the model components individually — is an essential, non-removable hypothesis: improper priors are sometimes safe (as in the first sub-case above) and sometimes fatal (as here), and the difference can only be settled by explicitly checking convergence of case by case.
Scope, edge cases & common traps
| Situation | What actually holds | Common error |
|---|---|---|
| Proper prior, regular likelihood | Posterior always exists and is proper (theorem above) | — |
| Improper prior | Posterior may or may not be proper; must verify directly | Assuming "flat prior" is always harmless |
| Flat proper prior on bounded | Posterior mode = MLE (corollary above) | Believing MAP always equals MLE for any prior |
| Credible interval vs. confidence interval | Credible interval: , a statement about | Confidence interval reinterpreted as "95% probability is in this fixed interval" |
| Large- behavior | Under regularity, posterior concentrates near the true and often resembles (Bernstein–von Mises phenomenon) | Believing Bayesian and frequentist answers always differ substantially in large samples |
| Choice of prior | Genuinely changes finite-sample answers; different analysts, same data, different posteriors | Treating the posterior as an objective, prior-free fact |
The mathematician behind it
Origins · 1 minThomas Bayes and how this was discovered
Thomas Bayes was a Nonconformist minister who pursued mathematics as a private interest, becoming a Fellow of the Royal Society in 1742 largely on the strength of earlier work defending Newton's calculus. He is remembered almost entirely for one posthumously published essay addressing a single narrow question: given the number of successes in a sequence of independent trials with unknown success probability, what can be inferred about that probability? The manuscript containing what is now called Bayes' theorem was found among his papers after his death and communicated to the Royal Society in 1763 by his friend Richard Price, who edited and published it. Bayes' own treatment was geometric and tentative, restricted to a uniform prior on the unknown probability, and it was Pierre-Simon Laplace, working independently and more generally a few years later, who developed the theorem into the systematic tool of "inverse probability" that dominated statistical practice through the nineteenth century before the frequentist reaction of Fisher, Neyman, and Pearson in the twentieth.
Is a Bayesian posterior just a subjective opinion with no mathematical content?
No. Once a prior distribution and a likelihood are specified, the posterior is derived by an exact, non-optional application of the definition of conditional probability density, as proved in the central theorem above. The subjectivity, such as it is, lies entirely in the choice of prior (and, equally, in the choice of likelihood/model, which frequentist methods must also make). Given those choices, the computation of is as rigorous as any other conditional probability calculation, with no room for interpretation in the arithmetic itself. What is genuinely subjective is which prior honestly represents a given analyst's or field's background knowledge, and reasonable analysts can disagree about that input while agreeing completely on the mathematics that follows from it.
Do different priors always lead to very different conclusions?
Not in general. As sample size grows, under mild regularity conditions (a phenomenon called the Bernstein–von Mises theorem), the posterior distribution becomes increasingly concentrated around the true parameter value and increasingly insensitive to the prior, converging in shape to a Normal distribution centered at the MLE with variance given by the inverse Fisher information — matching frequentist asymptotics. With small samples, however, the prior can dominate, and different analysts with different (defensible) priors can reach substantially different posteriors from the same data, which is precisely why prior specification is treated as a modeling decision requiring justification, not a free parameter to be tuned for convenience.
What does it mean for a prior to be "conjugate," and why does it matter?
A prior family is conjugate to a likelihood family if multiplying a prior from that family by the likelihood yields a posterior in the same family, only with updated parameters — as seen with Beta priors under Binomial/Bernoulli likelihoods, and Normal priors under Normal likelihoods with known variance. Conjugacy matters practically because it allows closed-form posterior computation without integration or simulation, since the normalizing constant is automatically known from the conjugate family's own definition. Historically, conjugate families were essential before computational methods like Markov chain Monte Carlo made it feasible to work with arbitrary, non-conjugate posteriors numerically; conjugate models remain valuable today as building blocks, sanity checks, and fast approximations.
Can Bayesian and frequentist point estimates ever be numerically identical?
Yes, in several important cases. Under a flat proper prior, the posterior mode equals the MLE exactly, as proved in the corollary above. Under a Normal prior and Normal likelihood, the posterior mean is a precision-weighted average of the prior mean and the MLE (the sample mean), which converges to the MLE as either the sample size grows or the prior variance grows without bound (an increasingly flat, uninformative prior). More generally, whenever the prior is "uninformative" relative to the amount of data, Bayesian and frequentist point estimates tend to agree closely, even though the interpretation of the resulting number — a posterior mode versus a likelihood maximizer — remains conceptually distinct.
Why does the article insist an improper prior sometimes gives a valid posterior and sometimes does not?
Because propriety of the posterior is a statement about the marginal likelihood , not about the prior in isolation. An improper prior (one that does not integrate to a finite number over the whole parameter space) can still combine with a sufficiently fast-decaying likelihood to produce a finite , as happened with the flat prior on a Normal mean in the counterexample discussion. But if the likelihood does not decay quickly enough relative to how the improper prior blows up, can diverge for every observed value of the data, and then the "posterior" formula is not a probability density at all. This is exactly why the central theorem lists as an explicit, separately checkable hypothesis rather than assuming it follows automatically from properness of the prior.
How does Bayesian inference handle prediction of future data, as opposed to just estimating θ?
By integrating the likelihood of new data over the posterior distribution of , rather than plugging in a single point estimate. The posterior predictive distribution for a new observation given data is , which automatically accounts for remaining uncertainty about rather than treating as if it were known exactly. This tends to produce wider, more honest predictive intervals than "plug-in" frequentist prediction using alone, particularly with small sample sizes where the posterior for is still spread out.
Is one framework simply "correct" and the other "wrong"?
No; they are different mathematical formalizations of the word "inference," each internally consistent given its own definitions, and each with different strengths. Frequentist methods give procedures with guaranteed long-run error-rate control across repeated experiments, independent of any prior belief, which is valuable when reproducibility across many studies is the priority. Bayesian methods give direct, interpretable probability statements about the unknown parameter given the one dataset actually in hand, and integrate prior information coherently, which is valuable when genuine prior knowledge exists or when decisions must be made from a single dataset. Competent modern statistical practice uses both, chosen according to the scientific question rather than treated as rival ideologies.