Bayes' Theorem: Updating Beliefs with Evidence
Your ability to do good science depends on your ability to update your beliefs in the face of evidence.
The Problem of Inverse Probability
Suppose you test positive for a rare disease. The test is 99% accurate. Should you panic?The intuitive answer is “yes” — but as we’ll see, the correct answer depends critically on how rare the disease is.
This is a question of inverse probability: given an observed effect (positive test), what is the probability of the underlying cause (having the disease)? For centuries, this kind of reasoning was considered impossible or meaningless. It took a Presbyterian minister named Thomas Bayes to crack the problem.
Bayes’ Theorem
Bayes’ theorem relates the conditional probability of a hypothesis given evidence to the reverse:
(1)
where:
- is the posterior — our updated belief after seeing evidence
- is the likelihood — how probable the evidence is if the hypothesis is true
- is the prior — our belief before seeing evidence
- is the marginal likelihood — the total probability of the evidence
A Simple Example
Consider a medical test for a disease that affects 1 in 1,000 peopleThis base rate is crucial. Many real-world errors in reasoning come from ignoring it — a phenomenon called base rate neglect.:
- Prevalence:
- Sensitivity: (true positive rate)
- Specificity: (true negative rate)
What is ?
First, compute the marginal probability of testing positive:
(2)
(3)
Then apply Equation 1:
(4)
The result is shocking: despite the test being 99% accurate, a positive result only means a 2% chance of actually having the disease. This counterintuitive result arises because the false positives from the large healthy population (5%) vastly outnumber the true positives from the tiny sick population (0.1%).
Visualizing the Update
The shift from prior to posterior is best seen visually. Figure 1 shows how the distribution concentrates around the true value as evidence accumulates:
The following table tracks how our belief updates through each piece of evidence:
| Stage | P(disease) | Odds |
|---|---|---|
| Prior (before test) | 0.001 | 1 : 999 |
| After positive test | 0.0194 | 1 : 50.5 |
| After second positive test | 0.284 | 1 : 2.5 |
| After third positive test | 0.867 | 6.5 : 1 |
This is why doctors order confirmatory tests. A single positive is weak evidence; multiple independent positives compound into strong evidence.
The Odds Form
Bayes’ theorem has an elegant equivalent in odds form that makes sequential updating trivial:
(5)
where the likelihood ratio and .
This is the form used in practice The odds form avoids computing the marginal probability entirely — the likelihood ratio handles it implicitly. because it factors out and lets us chain updates:
(6)
Figure 2 illustrates the likelihood ratio concept: when the evidence is much more likely under the hypothesis than under the alternative, the LR is large and the update is strong.
Implementation
The code is straightforward. Here’s a Python implementation that handles both single and sequential updates:
class BayesUpdater:
"""Bayesian belief updater using the odds form."""
def __init__(self, prior: float):
self.odds = prior / (1 - prior)
self.history = [prior]
def update(self, lr: float) -> float:
"""Update belief with a new likelihood ratio."""
self.odds *= lr
p = self.odds / (1 + self.odds)
self.history.append(p)
return p
@property
def probability(self) -> float:
return self.odds / (1 + self.odds)
# Medical diagnosis example
belief = BayesUpdater(prior=0.001)
# First positive test (LR = sensitivity / (1 - specificity))
belief.update(lr=0.99 / 0.05) # P ≈ 0.0194
print(f"After 1st positive: {belief.probability:.4f}")
# Second independent positive test
belief.update(lr=0.99 / 0.05) # P ≈ 0.284
print(f"After 2nd positive: {belief.probability:.4f}")
# Third independent positive test
belief.update(lr=0.99 / 0.05) # P ≈ 0.867
print(f"After 3rd positive: {belief.probability:.4f}")Output:
After 1st positive: 0.0194
After 2nd positive: 0.2841
After 3rd positive: 0.8673Visualizing the sequence: Figure 3 shows how the probability climbs with each independent positive test — starting from near zero and crossing 50% after just three tests.
Applications
Spam Filtering
Email spam filters were one of the first killer apps of Bayesian reasoning. Paul Graham’s 2002 essay A Plan for Spam [2] showed that a simple Bayesian classifier could achieve >99.5% accuracy.
The idea: each word has a spam probability. Given the words in an email, combine them using Bayes’ theorem:
(7)
where and is the prior spam rate.
Modern spam filters (Gmail, etc.) use more sophisticated models, but the core insight remains Bayesian.
A/B Testing
In product development, Bayesian A/B testing provides a principled way to decide whether variant A or variant B is better:
(8)
Unlike frequentist hypothesis testing, this directly answers the question product managers actually care about: “what is the probability that B is better?”
Bayesian Neural Networks
Deep learning has embraced Bayesian ideas. Instead of learning a single weight vector , a Bayesian neural network learns a distribution over weights , enabling principled uncertainty estimates Uncertainty quantification is critical for safety-sensitive applications like autonomous driving and medical diagnosis..
Figure 4 compares traditional and Bayesian approaches to neural network weights:
(9)
The Philosophy of Priors
The choice of prior is the most controversial aspect of Bayesian reasoning. Critics argue it introduces subjectivity; proponents counter that all reasoning involves assumptions, and Bayes just makes them explicit.
There are several schools of thought:
- Objective Bayes: use “uninformative” priors (Jeffreys, maximum entropy) that let the data speak
- Subjective Bayes: encode genuine prior knowledge — this is a feature, not a bug
- Empirical Bayes: estimate the prior from the data itself Empirical Bayes is widely used in genomics and other fields with many similar hypotheses — see Efron’s work on large-scale inference [3].
The pragmatic view: the prior matters most with little data. With enough evidence, all reasonable priors converge This is a consequence of the “washing out of priors” — Bayesian posteriors are asymptotically dominated by the likelihood..
Conclusion
Bayes’ theorem is not just a formula — it is a framework for rational thought. It tells us how to update our beliefs when new evidence arrives, how much weight to give that evidence, and when to be skeptical of our own intuitions.
From spam filters to medical diagnosis, from A/B testing to artificial intelligence, Bayesian reasoning is everywhere — often hiding in plain sight. The next time you encounter surprising evidence, ask yourself: what is the likelihood ratio, and what was my prior?
Bibliography
- [1] E. T. Jaynes, Probability Theory: The Logic of Science. Cambridge University Press, 2003.
- [2] P. Graham, “A Plan for Spam,” 2002, [Online]. Available: http://www.paulgraham.com/spam.html
- [3] B. Efron, Large-Scale Inference: Empirical Bayes Methods for Estimation, Testing, and Prediction. Cambridge University Press, 2010.