Skip to content

Bayes' theorem, explained with one clear example

6 min read

Short answer

Bayes' theorem turns P(B∣A)P(B\mid A) into P(A∣B)P(A\mid B): P(A∣B)=P(B∣A) P(A)P(B).P(A\mid B)=\frac{P(B\mid A)\,P(A)}{P(B)}. In words: start from how common AA is, then update it by how well BB points to AA. The easiest way to apply it is to imagine 10,000 people and count.

Of 981 positive tests, 90 are truly sick and 891 are healthyAll 10,000 people1% sick (100)Only the 981 positive tests90 truly sick (9.2%)891 healthy
Among 981 positive tests, only 90 are from people who are actually sick. Most positives come from the huge healthy group.

The idea in one sentence

"Given that the test is positive, how likely is it that I'm sick?" is a different question from "if I'm sick, how likely is a positive test?" Bayes' theorem converts one into the other, and the missing ingredient is the base rate, how common the condition was in the first place.

Count instead of plug in

Natural frequencies avoid most errors. Pick a round population, split it by the base rate, apply the test's rates to each group, and then look only at the people who tested positive. The answer is the share of those positives who really have the condition.

Worked example

A disease affects 1% of people. A test detects it in 90% of sick people (sensitivity) but also gives a false positive for 9% of healthy people. You test positive. What is the probability you are sick?

Imagine 10,000 people.

  • Sick: 1%⋅10,000=1001\%\cdot10{,}000=100. Of these, 90%90\% test positive: 90.
  • Healthy: 9,9009{,}900. Of these, 9%9\% test positive: 891.

Positives in total: 90+891=98190+891=981. So P(sick∣+)=90981≈9.2%.P(\text{sick}\mid +)=\frac{90}{981}\approx 9.2\%.

With the formula: P(+)=0.9⋅0.01+0.09⋅0.99=0.0981P(+)=0.9\cdot0.01+0.09\cdot0.99=0.0981 and P(sick∣+)=0.9⋅0.010.0981≈0.092P(\text{sick}\mid+)=\dfrac{0.9\cdot0.01}{0.0981}\approx0.092. Same result: a positive test raises the chance from 1% to about 9%, far below 90%.

Try it yourself

5% of items from a factory are defective. An inspector flags 95% of defective items and also 10% of good ones. An item is flagged. What is the probability it is defective?

Show the answer

Take 2,000 items: 100 defective and 1,900 good. Flagged defective: 0.95⋅100=950.95\cdot100=95. Flagged good: 0.10⋅1900=1900.10\cdot1900=190. So P(defective∣flagged)=9595+190=13≈33%P(\text{defective}\mid\text{flagged})=\dfrac{95}{95+190}=\dfrac13\approx33\%.

Keep going with practice

Conditional probability and Bayes' theorem are part of Vidi's Linear Algebra & Probability course, with auto-graded practice like the problem above.