Introduction

Imagine you test positive for a serious disease. The test is 99% accurate. Should you panic?

Most people say yes. The math says: it depends entirely on how rare the disease is. If only one person in ten thousand has the disease, then even with a 99% accurate test, a positive result still means you are more likely healthy than sick. That sounds impossible — until you see the arithmetic.

This reversal of intuition has a name: the base-rate fallacy. And the formula that fixes it is Bayes' theorem, first stated by the Reverend Thomas Bayes in an essay published posthumously in 1763 and later refined by Pierre-Simon Laplace.

The theorem is not just a medical curiosity. It is the engine behind spam filters, search-and-rescue positioning, machine learning classifiers, and scientific hypothesis testing. Wherever new evidence should change an existing belief, Bayes' theorem is the correct way to do the update.

Try It

Drag the sliders below to set how common the disease is (prevalence) and how accurate the test is (sensitivity and specificity). The demo computes the true positive probability — the chance you actually have the disease given a positive test result — using Bayes' theorem.

<p class="hint">{{hint}}</p>
<div class="controls">
  <label>{{prev_label_pre}} <span id="prev-label">1000</span>{{prev_label_post}}
    <input type="range" id="prev" min="1" max="4" step="1" value="3">
    <span class="range-hint">{{range_hint}}</span>
  </label>
  <label>{{sens_label}} <span id="sens-label">99</span>%
    <input type="range" id="sens" min="50" max="100" step="1" value="99">
  </label>
  <label>{{spec_label}} <span id="spec-label">99</span>%
    <input type="range" id="spec" min="50" max="100" step="1" value="99">
  </label>
</div>
<div class="result-box">
  <div class="result-label">{{result_label}}</div>
  <div class="result-value" id="ppv">—</div>
</div>
<div class="chart-wrap">
  <div class="bar-group">
    <div class="bar tp" id="bar-tp"></div>
    <div class="bar-label">{{bar_tp}}</div>
    <div class="bar-count" id="cnt-tp">—</div>
  </div>
  <div class="bar-group">
    <div class="bar fp" id="bar-fp"></div>
    <div class="bar-label">{{bar_fp}}</div>
    <div class="bar-count" id="cnt-fp">—</div>
  </div>
  <div class="bar-group">
    <div class="bar tn" id="bar-tn"></div>
    <div class="bar-label">{{bar_tn}}</div>
    <div class="bar-count" id="cnt-tn">—</div>
  </div>
  <div class="bar-group">
    <div class="bar fn" id="bar-fn"></div>
    <div class="bar-label">{{bar_fn}}</div>
    <div class="bar-count" id="cnt-fn">—</div>
  </div>
</div>
<p class="formula" id="formula-text"></p>
* { box-sizing: border-box; }
body { font-family: system-ui, sans-serif; color: #222; margin: 0; }
.hint { font-size: .88rem; color: #444; margin: 0 0 .8rem; line-height: 1.5; }
.controls { display: flex; flex-direction: column; gap: .5rem; margin-bottom: .9rem; }
.controls label { font-size: .88rem; display: flex; flex-direction: column; gap: .2rem; color: #333; }
.controls input[type=range] { width: 100%; accent-color: #1d3557; }
.range-hint { font-size: .75rem; color: #888; }
.result-box { background: #1d3557; color: #fff; border-radius: 10px; padding: .6rem 1rem;
              margin-bottom: .9rem; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.result-label { font-size: .85rem; flex: 1 1 160px; }
.result-value { font-size: 2rem; font-weight: 700; min-width: 80px; text-align: right; }
.chart-wrap { display: flex; gap: 1rem; align-items: flex-end; height: 140px; margin-bottom: .6rem; }
.bar-group { flex: 1; display: flex; flex-direction: column; align-items: center; gap: .2rem; height: 100%; justify-content: flex-end; }
.bar { width: 100%; border-radius: 5px 5px 0 0; min-height: 3px; transition: height .35s ease; }
.bar.tp { background: #2a9d5c; }
.bar.fp { background: #e63946; }
.bar.tn { background: #457b9d; }
.bar.fn { background: #f4a261; }
.bar-label { font-size: .7rem; text-align: center; color: #555; line-height: 1.3; }
.bar-count { font-size: .75rem; font-weight: 600; color: #333; }
.formula { font-size: .8rem; color: #555; line-height: 1.5; margin: 0; background: #f4f6f8;
           border-radius: 6px; padding: .5rem .8rem; }
// Code not found

Notice that even a highly accurate test produces mostly false positives when the disease is rare. The prevalence (base rate) dominates. Only when the disease is common enough does a positive result become genuinely alarming. This is the base-rate fallacy in action — our intuition ignores the prior and anchors on the test accuracy alone.

The Real Math

Bayes' theorem is proven — a straightforward consequence of the definition of conditional probability. There is no open question about whether it is true.

The formula is:

P(DiseasePositive)=P(PositiveDisease)×P(Disease)P(Positive)P(\text{Disease} \mid \text{Positive}) = \frac{P(\text{Positive} \mid \text{Disease}) \times P(\text{Disease})}{P(\text{Positive})}

Breaking it down:

  • P(Disease)P(\text{Disease}) is the prior — how likely the disease is before any test result. This is the prevalence.
  • P(PositiveDisease)P(\text{Positive} \mid \text{Disease}) is the sensitivity — how often the test fires positive on someone who truly has the disease.
  • P(Positive)P(\text{Positive}) is the total positive rate — the weighted sum of true positives and false positives over the whole population.
  • P(DiseasePositive)P(\text{Disease} \mid \text{Positive}) is the posterior — the probability you actually have the disease, given a positive result.

The key insight is the denominator. Even if the false positive rate is 1%, a 1-in-10,000 prevalence means roughly 100 false positives for every 1 true positive in a screened population. The posterior probability for a random positive is therefore about 1%.

Status: solved. Bayes' theorem was proven by Thomas Bayes (posthumous essay, 1763) and generalized by Pierre-Simon Laplace (1812). It is now a foundational identity of probability theory, taught in every statistics course and embedded in every field that reasons under uncertainty.

The hard part is not the formula — it is the human part: accepting that our intuitions about probability are systematically wrong, and disciplining ourselves to track the prior. See also how P vs NP shows a similar gap between what seems hard and what is actually provable.

Where It Matters

Bayes' theorem is not confined to medical examples. It is the right rule for any situation where evidence should shift a belief:

  • Medical screening: mass screenings for rare diseases reliably generate more false positives than true positives. Bayesian reasoning tells clinicians when a confirmatory test is warranted and when it is not.
  • Spam filtering: early spam filters (and Naive Bayes classifiers) compute P(spamword)P(\text{spam} \mid \text{word}) from the prior frequency of spam and the likelihood that each word appears in spam versus legitimate mail.
  • Search and rescue: Bayesian search theory (used by the US Coast Guard since the 1970s) updates the probability distribution over a missing vessel's location as each search sector comes back empty.
  • Machine learning: Bayesian classifiers, Gaussian processes, and variational inference all express learning as posterior updating — starting with a prior over model parameters and sharpening it with data.
  • Scientific hypothesis testing: Bayesian hypothesis testing computes the probability a theory is correct given observations, in contrast to the frequentist p-value, which does not give the probability the hypothesis is true.

Understanding Bayes' theorem gives you the correct framework for probabilistic algorithms and any system that must reason under uncertainty.

Conclusion

Bayes' theorem is the rare result that is both mathematically trivial and psychologically revolutionary. The algebra is a one-liner; the implication — that prior probability dominates our judgement far more than we expect — overturns decades of medical protocol, AI design, and everyday decision-making.

A positive test for a rare disease is not a verdict. A single data point is not proof. Every piece of evidence must be weighted against what was already true before it arrived. That discipline, encoded in a formula from 1763, remains one of the most quietly powerful ideas in all of mathematics.

The next time you read a headline about a "99% accurate test" or a study that "proves" a link, ask what the base rate is. The answer might surprise you — and Bayes' theorem will tell you exactly how surprised to be.

Share this article

Pick a channel — or use your device's native share sheet.

Comments

Loading comments...

https://www.kipuhub.com/en/article/bayes-theorem/Content licensed under CC BY-NC 4.0.