Bayes’ Theorem Explained: Formula + Medical Test Example

Quick answer: Bayes’ theorem tells you how to update a probability when you get new evidence: P(A | B) = P(B | A) × P(A) / P(B). Example: a disease affects 1% of people, and a test catches 90% of cases but gives false positives 9% of the time. If you test positive, your chance of having the disease is only about 9%, because false positives from the 99% of healthy people outnumber true positives. The key is to start from the base rate.

A test for a disease is “90% accurate.” You test positive. Are you 90% likely to be sick? Most people, including many doctors in classic studies, say yes. The real answer can be under 10%. Bayes’ theorem explains why, and it is one of the most useful ideas in probability.

The Formula

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

  • \(P(A)\): the prior, how likely \(A\) was before the evidence (the base rate).
  • \(P(B \mid A)\): the likelihood, how likely the evidence is if \(A\) is true.
  • \(P(A \mid B)\): the posterior, the updated probability after seeing \(B\).

The symbol \(\mid\) means “given.” See our guide to calculating probability for the basics.

The Medical Test Example

Here is a hypothetical example. Suppose 1% of people being tested have a disease (the pretest probability). The test detects 90% of real cases (sensitivity) and correctly clears 91% of healthy people (specificity), so it wrongly flags 9% of them (false positive rate). Picture 10,000 people:

Test positiveTest negativeTotal
Have the disease90 (true positives)10 (false negatives)100
Healthy891 (false positives)9,009 (true negatives)9,900
Total9819,01910,000

Of the 981 people who test positive, only 90 are sick:

\[ P(\text{disease} \mid \text{positive}) = \frac{90}{981} \approx 9.17\%. \]

With the formula, step by step:

\[ P(+) = 0.90 \times 0.01 + 0.09 \times 0.99 = 0.009 + 0.0891 = 0.0981, \]

\[ P(\text{disease} \mid +) = \frac{0.90 \times 0.01}{0.0981} = \frac{0.009}{0.0981} \approx 0.0917. \]

The positive result still matters: it raised the chance from 1% to about 9%, roughly nine times higher. It just did not make disease likely.

How Specificity Changes the Answer

PrevalenceSensitivitySpecificityChance of disease after a positive
1%90%91%about 9.2%
1%90%99.9%about 90.1%

So a rare disease does not automatically make a positive result weak. What matters is prevalence, sensitivity and specificity together.

The Base Rate Fallacy

The mistake is ignoring how rare the disease is. When a condition is rare, even a small false-positive rate among the many healthy people produces more false alarms than true cases. This is the base rate fallacy. It is also why doctors often confirm a positive screening result with a further test. After one positive, the 9.17% becomes the new prior. If a second test with the same rates were positive, and its errors were independent of the first test’s errors, the chance would rise to about 50%. In practice, tests can share sources of error, so the second update must use rates that account for the first result.

(This is an illustration of the mathematics, not medical advice. Real test interpretation depends on the specific test and the patient, so ask a clinician.)

Natural Frequencies Make It Easy

Psychologist Gerd Gigerenzer and colleagues showed that people solve these problems far better with counts (“90 out of 981”) than with percentages. Drawing a table of 10,000 people, as above, is the simplest way to apply Bayes’ theorem correctly.

Where Bayes’ Theorem Is Used

  • Spam filters update the chance an email is spam from the words it contains.
  • Medicine interprets test results and screening programs.
  • Machine learning and AI use Bayesian updating and naive Bayes classifiers.
  • Puzzles such as the Monty Hall problem and the boy or girl paradox are Bayes in disguise.

History

Thomas Bayes, an English minister, worked out the idea; his essay was published after his death by Richard Price in 1763. Pierre-Simon Laplace developed it into a general method in 1774 and later.

Common Misconceptions

“P(A | B) equals P(B | A).” No. The chance of a positive test given disease (90%) is very different from the chance of disease given a positive test (9%).

“A 90% accurate test means a positive is 90% reliable.” No. “Accuracy” can mean several things. The chance of disease after a positive depends on the pretest probability, the sensitivity and the specificity together.

Watch: Bayes’ Theorem in Video

If you learn better by watching, these videos are worth your time.

Bayes theorem, the geometry of changing beliefs (3Blue1Brown). A visual explanation built around a classic example.
Bayes’ Theorem, Clearly Explained!!!! (StatQuest with Josh Starmer). A friendly step-by-step walkthrough.

Check Your Understanding

Five quick questions to see how much of this has stuck. Pick an answer and press Submit; you will see a short explanation either way.

Answer each question and press Submit to see your result right away.

1. In the example, what is the chance of disease after one positive test?
Found a bug? Let us know!
2. In the 10,000-person table, how many healthy people test positive?
Found a bug? Let us know!
3. What is P(A) called in Bayes’ theorem?
Found a bug? Let us know!
4. What mistake ignores how rare a condition is?
Found a bug? Let us know!
5. Who published Bayes’ essay after his death in 1763?
Found a bug? Let us know!

Frequently Asked Questions

What is Bayes’ theorem in simple terms?

A rule for updating a probability with new evidence: the posterior equals the likelihood of the evidence times the prior, divided by the overall probability of the evidence.

What is the formula for Bayes’ theorem?

P(A | B) = P(B | A) × P(A) / P(B).

Why can a positive medical test still mean a low chance of disease?

If the disease is rare and the false positive rate is not tiny, false positives from the many healthy people can outnumber the true positives. In the example (1% prevalence, 90% sensitivity, 91% specificity), a positive result means about a 9% chance.

What is the difference between sensitivity and specificity?

Sensitivity is the share of sick people who test positive. Specificity is the share of healthy people who test negative. One minus the specificity is the false positive rate.

What is Bayes’ theorem used for?

Medical testing, spam filtering, machine learning, risk assessment and many probability puzzles.

Keep Exploring

Sources and Further Reading

Related to This Article

What people say about "Bayes’ Theorem Explained: Formula + Medical Test Example - Effortless Math"?

No one replied yet.

Leave a Reply