Bayes Theorem

⚡ Key Takeaways

Bayes' Theorem relates the conditional probability P(A∣B)P(A\mid B) to its "reverse" P(B∣A)P(B\mid A) via P(A∣B)=P(B∣A) P(A)P(B)P(A\mid B) = \dfrac{P(B\mid A)\,P(A)}{P(B)}. In words: it tells you how to update your belief in a hypothesis after seeing evidence. It applies anywhere uncertainty is quantified — medical diagnosis, machine learning, forensics, signal processing, and scientific inference. Named for Thomas Bayes (c. 1701–1761), published posthumously in 1763.

💡 The Core Insight

Evidence does not tell you P(hypothesis∣evidence)P(\text{hypothesis} \mid \text{evidence}) directly — it gives you P(evidence∣hypothesis)P(\text{evidence} \mid \text{hypothesis}). Bayes' Theorem is the bridge that flips this direction, and the flip requires you to bring in the prior P(hypothesis)P(\text{hypothesis}) — your belief before the evidence. The posterior is proportional to likelihood times prior. Forgetting the prior (the base rate) is the single most common error in probabilistic reasoning.

Formal Statement

DefinitionConditional Probability

For events AA and BB in a probability space with P(B)>0P(B) > 0, the conditional probability of AA given BB is

1
P(A∣B)=P(A∩B)P(B).\quad P(A\mid B) = \frac{P(A \cap B)}{P(B)}.

Derivation hint: This is the definition; it renormalizes the probability of the joint event A∩BA\cap B to the reduced sample space in which BB is known to have occurred. Here P(A∩B)P(A\cap B) is the probability that both AA and BB occur, and P(B)P(B) is the (positive) probability of the conditioning event.

TheoremBayes' Theorem

Let AA and BB be events with P(A)>0P(A) > 0 and P(B)>0P(B) > 0. Then

2
P(A∣B)=P(B∣A) P(A)P(B).\quad P(A\mid B) = \frac{P(B\mid A)\,P(A)}{P(B)}.

Derivation hint: Apply Equation [1] twice — once for P(A∣B)P(A\mid B), once for P(B∣A)P(B\mid A) — and note both share the symmetric joint term P(A∩B)=P(B∩A)P(A\cap B) = P(B\cap A). The terms are named:

  • P(A∣B)P(A\mid B) — the posterior: belief in AA after observing BB.
  • P(B∣A)P(B\mid A) — the likelihood: probability of evidence BB if AA holds.
  • P(A)P(A) — the prior: belief in AA before observing BB.
  • P(B)P(B) — the evidence (or marginal likelihood): total probability of observing BB.
DefinitionLaw of Total Probability and Expanded Form

If {A1,A2,…,An}\{A_1, A_2, \dots, A_n\} is a partition of the sample space (mutually exclusive, exhaustive, each with positive probability), the denominator can be expanded:

3
P(B)=∑i=1nP(B∣Ai) P(Ai).\quad P(B) = \sum_{i=1}^{n} P(B\mid A_i)\,P(A_i).

Derivation hint: Write B=⋃i(B∩Ai)B = \bigcup_i (B\cap A_i) as a disjoint union over the partition, use countable additivity, then apply Equation [1] to each term. Substituting into Equation [2] gives the form used in practice:

4
P(Ak∣B)=P(B∣Ak) P(Ak)∑i=1nP(B∣Ai) P(Ai).\quad P(A_k\mid B) = \frac{P(B\mid A_k)\,P(A_k)}{\displaystyle\sum_{i=1}^{n} P(B\mid A_i)\,P(A_i)}.

Derivation hint: Substitute Equation [3] into the denominator of Equation [2] with A=AkA = A_k. For the common binary case (AA and its complement AcA^c):

5
P(A∣B)=P(B∣A) P(A)P(B∣A) P(A)+P(B∣Ac) P(Ac).\quad P(A\mid B) = \frac{P(B\mid A)\,P(A)}{P(B\mid A)\,P(A) + P(B\mid A^c)\,P(A^c)}.

Derivation hint: Equation [4] with the two-element partition {A,Ac}\{A, A^c\}.

DefinitionOdds Form

Dividing the posterior for AA by that for AcA^c, the evidence P(B)P(B) cancels, yielding the elegant odds form:

6
P(A∣B)P(Ac∣B)⏟posterior odds=P(B∣A)P(B∣Ac)⏟likelihood ratio×P(A)P(Ac)⏟prior odds.\quad \underbrace{\frac{P(A\mid B)}{P(A^c\mid B)}}_{\text{posterior odds}} = \underbrace{\frac{P(B\mid A)}{P(B\mid A^c)}}_{\text{likelihood ratio}} \times \underbrace{\frac{P(A)}{P(A^c)}}_{\text{prior odds}}.

Derivation hint: Take the ratio of Equation [2] for AA and for AcA^c; the common denominator P(B)P(B) divides out. The likelihood ratio (or Bayes factor) is the multiplicative strength of the evidence — how many times more often BB occurs under AA than under AcA^c.

Why It Holds / Derivation

ProofDerivation of Bayes' Theorem

We derive Equation [2] from the definition of conditional probability.

Step 1. By Equation [1], the conditional probability of AA given BB is

P(A∣B)=P(A∩B)P(B).P(A\mid B) = \frac{P(A\cap B)}{P(B)}.

Step 2. By the same definition, swapping the roles of AA and BB,

P(B∣A)=P(B∩A)P(A).P(B\mid A) = \frac{P(B\cap A)}{P(A)}.

Step 3. The intersection is symmetric: A∩B=B∩AA\cap B = B\cap A, so P(A∩B)=P(B∩A)P(A\cap B) = P(B\cap A). Solving Step 2 for this joint probability:

P(A∩B)=P(B∣A) P(A).P(A\cap B) = P(B\mid A)\,P(A).

This is the multiplication rule.

Step 4. Substitute the result of Step 3 into Step 1:

P(A∣B)=P(B∣A) P(A)P(B).P(A\mid B) = \frac{P(B\mid A)\,P(A)}{P(B)}.

This is Equation [2]. ■\blacksquare The entire content of the theorem is the symmetry of the joint probability viewed through two different conditionings. The expanded forms [4]–[6] are obtained by rewriting P(B)P(B) using the law of total probability or by taking ratios.

∎
mathematician · Thomas Bayes | c. 1701–1761

Thomas Bayes was an English Presbyterian minister and mathematician, a Fellow of the Royal Society. He never published his theorem in his lifetime; it appeared in "An Essay towards solving a Problem in the Doctrine of Chances", communicated to the Royal Society in 1763 by his friend Richard Price, two years after Bayes' death. Bayes' original problem was inverse: given a number of successes and failures in independent trials with unknown success probability pp, what can be said about pp? He effectively solved a special case of inference for a binomial parameter using a uniform prior. The general formulation and its systematic use in inference are largely due to Pierre-Simon Laplace, who rediscovered and vastly extended the idea independently. Much of what we call "Bayesian" is really Laplacian.

Building Intuition

🧠 Intuition

Think of probability as area. The whole sample space is a unit square. Event AA carves out a region; event BB carves out another; they overlap in A∩BA\cap B. When you learn that BB happened, you erase everything outside BB — your world shrinks to the BB region. The question "how likely is AA now?" becomes: what fraction of the surviving BB-region also belongs to AA? That fraction is P(A∩B)/P(B)P(A\cap B)/P(B) — exactly Equation [1]. Bayes' Theorem is just the observation that you can compute that overlap two ways. You might naturally know "of all the AA-cases, what fraction are also BB" (the likelihood) plus "how big is AA to begin with" (the prior). Bayes assembles these into the overlap and divides by the size of BB to flip the conditioning. The crucial intuition is base rates: even if BB almost always accompanies AA (high likelihood), if AA is itself tiny (low prior), then most of region BB may come from the complement AcA^c. A big slice of a rare event can be dwarfed by a tiny slice of a common one.

Figure
Updating belief: prior region, evidence narrows the world, posterior is the surviving overlap
Sample space Ω (unit square) A prior P(A) B (evidence) A∩B observe B World now = B only A∩B A^c ∩ B P(A|B) = area(A∩B) / area(B)

Worked Examples

ExampleMedical Test with a Rare Disease

Given: A disease affects 1 in 1000 people, so the prior is P(D)=0.001P(D) = 0.001. A test has:

  • Sensitivity (true positive rate): P(+∣D)=0.99P(+\mid D) = 0.99
  • False positive rate: P(+∣Dc)=0.05P(+\mid D^c) = 0.05 (so specificity =0.95= 0.95).

A randomly screened person tests positive. Find P(D∣+)P(D\mid +).

Step 1 — Prior of no disease: P(Dc)=1−0.001=0.999P(D^c) = 1 - 0.001 = 0.999.

Step 2 — Evidence (total probability of a positive), Equation [3]:

P(+)=P(+∣D)P(D)+P(+∣Dc)P(Dc)P(+) = P(+\mid D)P(D) + P(+\mid D^c)P(D^c)
=(0.99)(0.001)+(0.05)(0.999)=0.00099+0.04995=0.05094.= (0.99)(0.001) + (0.05)(0.999) = 0.00099 + 0.04995 = 0.05094.

Step 3 — Bayes, Equation [5]:

P(D∣+)=(0.99)(0.001)0.05094=0.000990.05094≈0.01943.P(D\mid +) = \frac{(0.99)(0.001)}{0.05094} = \frac{0.00099}{0.05094} \approx 0.01943.
P(D∣+)≈0.0194  =  1.94%\boxed{P(D\mid +) \approx 0.0194 \;=\; 1.94\%}

Despite a "99% accurate" test, a positive result means only about a 2% chance of actually having the disease — because false positives from the huge healthy population (0.04995) swamp the true positives (0.00099). This is the base-rate fallacy.

ExampleTwo Factories and a Defective Part — Odds Form

Given: A warehouse stocks bolts from two suppliers. Supplier 1 made 70% of the bolts with a 2% defect rate; Supplier 2 made 30% with an 8% defect rate. A randomly chosen bolt is defective. Find the probability it came from Supplier 2. Let S2S_2 = "from Supplier 2", S1=S2cS_1 = S_2^c = "from Supplier 1", BB = "defective".

Step 1 — Priors and likelihoods:

P(S2)=0.30,P(S1)=0.70,P(S_2) = 0.30,\quad P(S_1) = 0.70,
P(B∣S2)=0.08,P(B∣S1)=0.02.P(B\mid S_2) = 0.08,\quad P(B\mid S_1) = 0.02.

Step 2 — Prior odds (in favor of S2S_2):

P(S2)P(S1)=0.300.70=37.\frac{P(S_2)}{P(S_1)} = \frac{0.30}{0.70} = \frac{3}{7}.

Step 3 — Likelihood ratio (Equation [6]):

P(B∣S2)P(B∣S1)=0.080.02=4.\frac{P(B\mid S_2)}{P(B\mid S_1)} = \frac{0.08}{0.02} = 4.

Step 4 — Posterior odds:

P(S2∣B)P(S1∣B)=4×37=127.\frac{P(S_2\mid B)}{P(S_1\mid B)} = 4 \times \frac{3}{7} = \frac{12}{7}.

Step 5 — Convert odds to probability: odds 12:712{:}7 give

P(S2∣B)=1212+7=1219.P(S_2\mid B) = \frac{12}{12+7} = \frac{12}{19}.
P(S2∣B)=1219≈0.632  =  63.2%\boxed{P(S_2\mid B) = \tfrac{12}{19} \approx 0.632 \;=\; 63.2\%}

Though Supplier 2 makes only 30% of bolts, its higher defect rate makes it the more likely source of any given defective bolt.

Common Misconceptions

⚠️ The Prosecutor's Fallacy

Do not confuse the likelihood P(B∣A)P(B\mid A) with the posterior P(A∣B)P(A\mid B) — they are generally very different. In a courtroom, "the probability of this DNA match if the defendant is innocent is one in a million" (P(match∣innocent)=10−6P(\text{match}\mid \text{innocent}) = 10^{-6}) is not the same as "the probability the defendant is innocent given the match." With a database of millions of people, many innocent matches can occur. Equating these two reversed conditionals is the prosecutor's fallacy, and it has led to real wrongful convictions. Bayes' Theorem [2] shows the conversion requires the prior P(A)P(A) — which the fallacy silently ignores.

CounterexampleHigh Accuracy ≠ High Posterior

A common belief: "If a test is 99% accurate and I test positive, I'm 99% likely to have the condition." The medical example above is a direct counterexample: with P(+∣D)=0.99P(+\mid D) = 0.99 and a low base rate P(D)=0.001P(D) = 0.001, the posterior is only 1.94%. The same "99% accurate" test gives very different posteriors depending entirely on the prior:

Prior P(D)P(D)Posterior P(D∣+)P(D\mid +)
0.0011.9%
0.0116.7%
0.1068.7%
0.5095.2%

Accuracy is a property of the test; the posterior is a property of the test plus the population. There is no posterior without a prior.

Connections

connection

Bayes' Theorem sits at the hub of probability and inference:

  • It is an immediate corollary of Conditional Probability and the Law of Total Probability.
  • It generalizes from events to densities, giving the foundation of Bayesian Inference, where one updates a Prior Distribution into a Posterior Distribution using a Likelihood Function.
  • In its repeated/sequential form it is the engine of Bayesian Updating and recursive estimators like the Kalman Filter and Hidden Markov Models.
  • The Naive Bayes Classifier applies it with a conditional-independence assumption for classification.
  • It contrasts philosophically with Frequentist Inference and connects to Maximum Likelihood Estimation (the MAP estimate reduces to the MLE under a flat prior).
  • The odds form links it to Information Theory via the log-likelihood ratio as evidence in bits.

Real-World Applications

🔬 Where this appears

Historical Development

⏳ History
- 1763 — Richard Price posthumously presents Bayes' Essay towards solving a Problem in the Doctrine of Chances to the Royal Society, containing the first version of the theorem for inferring a binomial parameter.
- 1774 — Pierre-Simon Laplace, independently, formulates the general principle of inverse probability and applies it broadly (population statistics, astronomy, jurisprudence).
- 1812 — Laplace's Théorie analytique des probabilités systematizes "inverse probability," the dominant inferential framework of the 19th century.
- 1920s–1930s — R. A. Fisher, Jerzy Neyman, and Egon Pearson develop frequentist methods (significance tests, confidence intervals), pushing Bayesian methods to the margins amid criticism of subjective priors.
- 1939–1961 — Harold Jeffreys revives objective Bayesianism in Theory of Probability, introducing non-informative ("Jeffreys") priors.
- 1950s–1960s — Bruno de Finetti and L. J. Savage ground subjective probability and Bayesianism in axioms of rational decision-making (coherence, exchangeability).
- 1953 / 1970 — The Metropolis and Hastings algorithms (MCMC) are developed, eventually making high-dimensional posteriors computable.
- 1980s–1990s — Cheap computing and the Gibbs sampler (Geman & Geman, 1984; Gelfand & Smith, 1990) trigger a Bayesian renaissance across statistics and machine learning.
- 2000s–present — Probabilistic programming (Stan, PyMC), Bayesian deep learning, and Bayesian optimization make the theorem a standard workhorse of modern data science.

Subtleties & Limits

open-problem · The Problem of the Prior

Bayes' Theorem is mathematically uncontroversial, but its use in inference raises deep, partly unresolved issues:

  • Choosing the prior. Where does P(A)P(A) come from when no frequency data exist? "Objective" or "non-informative" priors (uniform, Jeffreys, reference priors) attempt to encode ignorance, but a prior uniform in one parameterization is non-uniform in another — there is no universally canonical ignorance prior. For continuous infinite-dimensional spaces, ignorance can even be incoherent.
  • Improper priors. Common non-informative priors (e.g. p(μ)∝1p(\mu)\propto 1 over all reals) do not integrate to 1; they sometimes yield proper posteriors and sometimes yield paradoxes or nonexistent posteriors.
  • Sensitivity and robustness. With small data, conclusions can depend heavily on the prior; quantifying and bounding this sensitivity (robust Bayes) is an active area.
  • Computation. Exact posteriors are intractable for most realistic models; MCMC and variational methods give approximations whose convergence and error are not always guaranteed.
  • Calibration vs. coherence. Bayesian updates are internally coherent but need not be well-calibrated against reality if the model or prior is misspecified — the theorem cannot rescue a wrong model.

These are not flaws in the theorem (an exact identity) but open questions about how to deploy it as a theory of inference.

See Also

Conditional Probability · Law of Total Probability · Bayesian Inference · Prior Distribution · Posterior Distribution · Likelihood Function · Naive Bayes Classifier · Maximum Likelihood Estimation · Frequentist Inference · Markov Chain Monte Carlo