Bayes' Theorem
Suppose a diagnostic test for a rare disease is 99% accurate. A patient tests positive. How worried should they be? Intuition trained on the accuracy figure alone screams "very worried." Yet the honest answer depends crucially on how rare the disease actually is. Getting from "accuracy of the test" to "chance you're actually sick" requires inverting a conditional probability. Bayes' theorem is the precise, provable rule for performing that inversion. The idea matters because most evidence in science, medicine, law, and everyday reasoning arrives in the wrong direction. We observe an effect and want to reason back to a cause. We know — this is what a model or an experiment tells us directly. But we want instead. Bayes' theorem is the bridge between these two. It is also the algebraic engine behind an entire philosophy of statistical inference (Bayesian statistics). In this philosophy, unknown parameters are treated as random quantities. They carry prior beliefs that get updated into posterior beliefs upon seeing data. The big picture is deceptively simple. The theorem is a one-line rearrangement of the definition of conditional probability. Its power comes from combining it with the Law of Total Probability to compute a normalizing constant. There is no new axiom here. It only demands the discipline of writing down every piece explicitly. This means the prior probability of each hypothesis, the likelihood of the observed evidence under each hypothesis, and the resulting posterior probability after the evidence is taken into account. This article states the precise definitions of prior, likelihood, and posterior. It proves the theorem rigorously from the axioms of probability. It works through two asymmetric numerical examples (a diagnostic test and an urn/factory problem). It shows exactly what breaks if the partition hypothesis is dropped. Finally, it surveys where the theorem is used today, from spam filters to forensic DNA evidence to the foundations of Independence of Events.
- Bayes' theorem inverts a conditional probability: it converts into .
- It requires a partition of hypotheses (mutually exclusive, exhaustive) with known priors .
- The likelihood measures how probable the observed evidence is under each hypothesis.
- The denominator is exactly the Law of Total Probability applied to ; it normalizes the posterior to sum to 1.
- Base rates dominate: rare hypotheses stay improbable even under fairly strong evidence — this is the resolution of the diagnostic-test paradox.
- Bayes' theorem is a theorem, not an assumption — it follows purely from the definition of conditional probability.
- Key idea: posterior probability is proportional to prior times likelihood, renormalized so all hypotheses' posteriors sum to one.
Where this lives today
Bayes' theorem is the computational core of Bayesian statistics, in which unknown parameters are assigned a prior distribution , data are modeled via a likelihood , and inference proceeds by computing the posterior — an infinite-partition version of the same identity proved above. In medical diagnostics and epidemiology, it is the standard tool for converting test sensitivity/specificity and disease prevalence into predictive values, exactly as in Example 1. In forensic science and law, likelihood ratios (the odds-form corollary) are used to weigh DNA or fingerprint evidence, with careful attention paid to avoiding the prosecutor's fallacy. In machine learning, naive Bayes classifiers apply the theorem (with a simplifying conditional-independence assumption, foreshadowing Independence of Events) to spam filtering, document classification, and sentiment analysis. In engineering, Bayesian filters — including the Kalman filter and particle filters — recursively apply the theorem to update state estimates from noisy sensor readings, underlying GPS navigation and robotics. In cryptography and information theory, Bayesian updating models an adversary's evolving beliefs about a secret key given observed ciphertext, informing security proofs. In cognitive science, "Bayesian brain" models propose that perception itself operates as approximate Bayesian inference, combining sensory likelihoods with learned priors.
Ask the tutor: How does Bayes' theorem generalize when the evidence arrives as a continuous stream of observations rather than a single event?
Let be a probability space. Let (or countably many ) be events forming a partition of : they are pairwise disjoint,
and exhaustive,
with for every . Let be an event with .
- The numbers are called the prior probabilities of the hypotheses — the probabilities assigned before observing .
- The numbers are called the likelihoods of the evidence under hypothesis .
- The numbers are called the posterior probabilities — the updated probabilities of the hypotheses after observing .
Bayes' theorem states:
In the special two-hypothesis case , , this reads
Intuition
Think of the sample space as sliced into disjoint wedges — the possible "causes" or "states of the world." The event — the observed "evidence" — is some region overlapping several wedges. Before you learn that happened, your belief about which wedge you're in is given by the prior areas . Once you learn occurred, you know you are somewhere in the shaded region , and your belief about which wedge you're in should be re-proportioned according to how much of sits inside each wedge — that's exactly . Dividing by the total area of renormalizes these into genuine probabilities. The key perceptual trap the diagnostic-test example exposes is confusing with . A test can be highly reliable ( large) while remains small, purely because sick people are rare — the wedge = "sick" is tiny compared to , so even a fairly complete overlap of with is dwarfed by the small sliver of that leaks into the enormous wedge = "healthy."
Deriving the theorem
Let be a probability space. Let be a finite or countable partition of (pairwise disjoint, ) with for all . Let with . Then for every index ,
We use two facts already established: the definition of conditional probability, and the Law of Total Probability.
Step 1 (definition of conditional probability, applied twice). For any two events with , conditional probability is defined as
Since by hypothesis, apply this with , :
Since by hypothesis, apply the same definition with , :
using (intersection is commutative as a set operation).
Step 2 (substitute). Combining (1) and (2):
This is already a valid inversion formula, but on the right is not yet expressed in terms of the given priors and likelihoods; Step 3 removes this by expanding .
Step 3 (expand the denominator via the Law of Total Probability). Because is a partition of with for every , the Law of Total Probability gives
where the second equality again uses the definition of conditional probability (as in (2), applied to each in place of ). This step is legitimate precisely because the are pairwise disjoint (so the events are pairwise disjoint, allowing countable additivity of to be applied to ) and exhaustive (so no part of is missed).
Step 4 (conclude). Substituting (4) into (3):
This holds for every index , which is exactly the claimed identity.
∎Note the proof technique: direct algebraic derivation from the definitions, using the Law of Total Probability only as a lemma to rewrite the denominator — no circularity, since the Law of Total Probability does not itself depend on Bayes' theorem.
For two complementary hypotheses , with and ,
Apply the theorem's Step 1–2 identity (3) to both and :
The common factor (which is positive and identical in both) cancels upon taking the ratio, giving the stated identity.
∎This corollary says: posterior odds = likelihood ratio × prior odds. It is the form most used in sequential updating, since each new piece of evidence simply multiplies the running odds by a new likelihood ratio.
Worked examples
Example 1 — the diagnostic test (asymmetric numbers, two hypotheses). A disease is present in of a population: , so . A test has sensitivity (true positive rate) and false-positive rate . A random person tests positive. Find . By Bayes' theorem with partition and evidence :
Compute the numerator:
Compute the other joint term:
Sum (this is via the Law of Total Probability):
Therefore
So even with a -sensitive test and only a false-positive rate, a positive result implies only about a 7.2% chance of actually having the disease — because the disease is rare, the false-positive rate applied to the huge healthy population () swamps the true positives (). This is the classic base-rate phenomenon, and it is not a paradox once the denominator is examined term by term. Checking via odds form: prior odds of disease are ; likelihood ratio is ; posterior odds , giving — matching, as it must, confirming internal consistency of the two forms.
Example 2 — three factories, asymmetric priors and likelihoods. A company buys light bulbs from three factories, , supplying , , of stock respectively:
Their defect rates are , , . A bulb is drawn at random and found defective (). Find , the probability it came from the highest-defect-rate factory, and compare to its prior . Compute each joint probability :
By the Law of Total Probability,
By Bayes' theorem,
So observing a defect nearly doubles our belief that the bulb came from factory 3, moving it from a prior share to a posterior share — even though factory 3 supplies the fewest bulbs, its higher defect rate makes it disproportionately likely to be the source once a defect is observed. For completeness,
and indeed , confirming the posteriors form a valid probability distribution over the partition, as guaranteed by the theorem's denominator being exactly .
The theorem requires to be pairwise disjoint and exhaustive with . Suppose instead we only have two overlapping events and (not a partition of , and not complementary), and we naively apply the "Bayes formula"
treating as if they partitioned . This can produce a nonsensical answer.
Concrete construction. Let with each outcome equally likely, . Let
Note (not disjoint) and (not exhaustive) — is not a partition. Compute directly using the true definition of conditional probability:
Now compute what the (misapplied) formula would give. We have , ,
Plugging into the "formula":
This gives , not the correct value . The formula fails because the denominator double-counts the overlap and is not equal to at all: direct computation gives , while the sum above equals . Since do not partition , the Law of Total Probability step (Step 3 of the proof) is invalid, and the entire derivation collapses. This shows the partition hypothesis is not a technicality — without it the "denominator" is simply the wrong number.
Scope, edge cases & common traps
| Situation | What happens | Correct handling |
|---|---|---|
| not a partition | Denominator ; formula invalid (see counterexample) | Choose or verify a genuine partition before applying the theorem |
| Some | Conditioning undefined for that hypothesis; term still contributes 0 to the sum if | Drop hypotheses with zero prior, or restrict to positive-prior atoms |
| undefined (division by zero) | Bayes' theorem does not apply to zero-probability evidence; needs limiting/density arguments (continuous case) | |
| Continuous parameter | Sums become integrals: | Same theorem, densities replace probability masses |
| Confusing with | The "prosecutor's fallacy" — treating likelihood as posterior | Always renormalize by , weighting by the prior |
The mathematician behind it
Origins · 1 minThomas Bayes and how this was discovered
Thomas Bayes was an English Nonconformist minister with a serious sideline in mathematics, elected a Fellow of the Royal Society in 1742 largely on the strength of a defense of Newton's calculus against philosophical attacks. The result now bearing his name appeared only posthumously: his friend Richard Price found the manuscript among Bayes' papers after his death, edited it, and presented it to the Royal Society in 1763 as "An Essay towards solving a Problem in the Doctrine of Chances." Bayes' original essay addressed a specific inverse-probability problem — given the number of successes in Bernoulli trials, what can be inferred about the underlying success probability — using a billiard-table thought experiment to justify a uniform prior. The general algebraic form used throughout probability today, and the modern emphasis on priors and posteriors as a general framework for inference, was substantially developed later by Pierre-Simon Laplace, working independently and more systematically.
Is Bayes' theorem an assumption of Bayesian statistics, or a proven fact?
It is a proven mathematical fact, true in any probability space satisfying the Law of Total Probability hypotheses (a valid partition with positive prior probabilities). What is philosophically distinctive about Bayesian statistics is not the theorem itself — frequentist and Bayesian statisticians agree it is a theorem — but the willingness to assign prior probability distributions to unknown parameters or hypotheses, treating them as random quantities with degrees of belief. The theorem then supplies the mechanically correct way to update those beliefs given data. So the controversy in statistical philosophy is about the interpretation and use of priors, never about whether the algebraic identity holds.
Why does a positive result on an accurate test still leave a low probability of disease?
Because the theorem weighs the likelihood against the prior, and rare diseases have tiny priors. Even a small false-positive rate applied to the enormous healthy population can generate more false positives in absolute terms than the small diseased population generates true positives. Concretely, in Example 1 the false positives contributed to while true positives contributed only — the healthy group is 249 times larger, so its 5% false-positive rate dwarfs the sick group's 97% true-positive rate in absolute counts. This is exactly the base-rate effect Bayes' theorem quantifies precisely.
What happens if two candidate hypotheses overlap instead of being disjoint?
The theorem's denominator is derived from the Law of Total Probability, which strictly requires a partition — pairwise disjoint and exhaustive events. If the "hypotheses" overlap, the sum double-counts the overlapping probability mass and no longer equals , so the formula's output is simply the wrong number, as shown explicitly in the counterexample above. The fix is always to first construct a genuine partition — for instance, by refining the events into disjoint atoms — before applying the theorem.
Does Bayes' theorem work with continuous random variables and probability densities?
Yes, with sums replaced by integrals. If has prior density and data has conditional density , the posterior density is
which is the continuous analogue of the discrete formula, with the denominator again playing the role of a normalizing constant guaranteeing . The derivation is essentially identical, using density-based conditional probability and an integral form of the Law of Total Probability.
How does sequential updating with multiple pieces of evidence work?
The odds-form corollary makes this transparent: each new independent piece of evidence multiplies the running posterior odds by its own likelihood ratio. If evidence updates prior odds to posterior odds , and a second piece of evidence is conditionally independent of given each hypothesis, then . This is exactly how naive Bayes classifiers and sequential Bayesian filters accumulate evidence, and it foreshadows the formal treatment of Independence of Events, since the simple multiplicative update relies on a conditional independence assumption between pieces of evidence.
Can Bayes' theorem give a posterior probability of exactly 0 or 1?
Yes, in degenerate cases. If for some hypothesis — the evidence is literally impossible under that hypothesis — then its posterior becomes exactly , regardless of how strong its prior was: one contradicting observation can eliminate a hypothesis entirely. Conversely if every other hypothesis has while , then . This is the mathematical expression of Sherlock Holmes' principle: once impossible alternatives are excluded, whatever remains, however improbable a priori, must be the truth — provided its likelihood for the evidence is strictly positive.