MathematicsGrade 9–13

Conditional probability with medical tests

A medical test is positive, but how likely is it that you are really ill? 1000 people show why the answer is often surprising.

Loading simulation …

What is it about?

A test for a disease DD is never perfect. Three numbers describe the situation:

  • Prevalence P(D)P(D): share of people with the disease among those tested, e.g. 1 %1\,\%.
  • Sensitivity P(+∣D)P(+ \mid D): share of people with the disease who test positive, e.g. 90 %90\,\%.
  • Specificity P(−∣D‾)P(- \mid \overline{D}): share of healthy people who test negative, e.g. 91 %91\,\%.

After a positive result, however, you want to know something else: how likely am I ill, given a positive test? This is the positive predictive value P(D∣+)P(D \mid +) – the “reversed” conditional probability.

It is easiest to think in natural frequencies. Of 10001000 people, 1010 are ill; 99 of them test positive (true positives), 11 tests negative (false negative). Of the 990990 healthy people, 9 %9\,\% – that is 89.1≈8989.1 \approx 89 – still test positive (false positives), 901901 test negative (true negatives). So 9+89=989 + 89 = 98 people test positive – and only 99 of them are ill:

P(D∣+)=99+89.1≈9.2 %.P(D \mid +) = \frac{9}{9 + 89.1} \approx 9.2\,\%.

With the rounded counts you get almost the same: 998≈9.2 %\frac{9}{98} \approx 9.2\,\%. For whole numbers without rounding, use 10 00010\,000 people: 100100 ill, 9090 of them positive; 99009900 healthy, 891891 of them positive; so 9090+891≈9.2 %\frac{90}{90 + 891} \approx 9.2\,\%.

In general this is Bayes’ theorem:

P(D∣+)=P(D)⋅P(+∣D)P(D)⋅P(+∣D)+P(D‾)⋅P(+∣D‾)=0.01⋅0.90.01⋅0.9+0.99⋅0.09=0.0090.0981≈9.2 %.P(D \mid +) = \frac{P(D) \cdot P(+ \mid D)}{P(D) \cdot P(+ \mid D) + P(\overline{D}) \cdot P(+ \mid \overline{D})} = \frac{0.01 \cdot 0.9}{0.01 \cdot 0.9 + 0.99 \cdot 0.09} = \frac{0.009}{0.0981} \approx 9.2\,\%.

In the reversed tree this value sits directly on the branch “positive → ill”. The reason for the small value: there are so many healthy people that even a small share of false alarms far outnumbers the few true positives. Ignoring the prevalence (the “base rate”) leads to far too high estimates of P(D∣+)P(D \mid +) – the base rate fallacy. The negative predictive value P(D‾∣−)=900.9900.9+1≈99.9 %P(\overline{D} \mid -) = \frac{900.9}{900.9 + 1} \approx 99.9\,\%, on the other hand, is very high.

A second test after a positive first test starts with the group of people who tested positive. Their share of people with the disease – the new prevalence – is the predictive value of the first test, 9.2 %9.2\,\%. After two positive tests (assumed independent) you get 100199≈50.3 %\frac{100}{199} \approx 50.3\,\%.

The numbers in the examples are simplified and only illustrate the idea; real tests have different values depending on the device, the timing and the group of people.

Try it

  1. Watch the process: first the people with the disease turn red, then the test shows its result. People with the disease also carry a dot on their body. Then tap “Only those who tested positive”. How many of those who tested positive really have the disease? Load example
  2. Raise the prevalence slowly to 50 %50\,\%. How does the predictive value change? The link shows the final state with sensitivity and specificity of 90 %90\,\% each. Common disease
  3. Set the specificity to 100 %100\,\%. What happens to the false positives? Specificity 100 %
  4. Lower the sensitivity to 50 %50\,\%. Does the predictive value change a lot – and what happens to the false negatives? Sensitivity 50 %
  5. Switch to the tree and reverse it. Which numbers stay the same, which change? Tree
  6. Do a second test. How much does the predictive value rise? Second test

Tasks

Task 1: Natural frequencies

Prevalence 1 %1\,\%, sensitivity 90 %90\,\%, specificity 91 %91\,\%. Find the four groups for 10001000 people and the positive predictive value. Load task

Show solution

Ill 1010: true positives 99, false negative 11. Healthy 990990: false positives 990⋅0.09=89.1≈89990 \cdot 0.09 = 89.1 \approx 89, true negatives 900.9≈901900.9 \approx 901. P(D∣+)=99+89.1≈9.2 %P(D \mid +) = \frac{9}{9 + 89.1} \approx 9.2\,\%. Show in simulation

Task 2: Rapid test with low prevalence (simplified)

A rapid test has sensitivity 80 %80\,\% and specificity 98 %98\,\%. The disease is currently rare: 0.5 %0.5\,\%. How likely is it that a person who tested positive is ill? Load task

Show solution

Of 10001000: 55 ill, 44 of them positive. 995995 healthy, 995⋅0.02=19.9≈20995 \cdot 0.02 = 19.9 \approx 20 of them positive. P(D∣+)=0.005⋅0.80.005⋅0.8+0.995⋅0.02=0.0040.0239≈16.7 %P(D \mid +) = \frac{0.005 \cdot 0.8}{0.005 \cdot 0.8 + 0.995 \cdot 0.02} = \frac{0.004}{0.0239} \approx 16.7\,\% – only about one in six people who test positive is ill. Show in simulation

Task 3: Mammography screening (simplified example)

Assume that 0.8 %0.8\,\% of the women examined have breast cancer, the sensitivity is 90 %90\,\% and the specificity 93 %93\,\%. Calculate P(D∣+)P(D \mid +) with Bayes’ formula. Load task

Show solution

P(D∣+)=0.008⋅0.90.008⋅0.9+0.992⋅0.07=0.00720.07664≈9.4 %P(D \mid +) = \frac{0.008 \cdot 0.9}{0.008 \cdot 0.9 + 0.992 \cdot 0.07} = \frac{0.0072}{0.07664} \approx 9.4\,\%. In natural frequencies: 7.27.2 true positives against 69.469.4 false positives per 10001000 women (rounded to 77 and 6969 in the simulation). For 10 00010\,000 women: 7272 true positives and 9920⋅0.07=694.4≈6949920 \cdot 0.07 = 694.4 \approx 694 false positives. Show in simulation

Task 4: Second test

Everyone who tested positive in Task 1 takes a second, independent test of the same kind, which is positive again. How likely is it now that the person is ill? Load task

Show solution

New prevalence p2=P(D∣+)=0.0090.0981≈9.17 %p_2 = P(D \mid +) = \frac{0.009}{0.0981} \approx 9.17\,\%. Then p2⋅0.9p2⋅0.9+(1−p2)⋅0.09=100199≈50.3 %\frac{p_2 \cdot 0.9}{p_2 \cdot 0.9 + (1 - p_2) \cdot 0.09} = \frac{100}{199} \approx 50.3\,\%. With frequencies: of the 98.198.1 people who tested positive, 99 are ill; 8.18.1 of them test positive again, and 8.028.02 of the 89.189.1 healthy people. So 8.18.1+8.02≈50.3 %\frac{8.1}{8.1 + 8.02} \approx 50.3\,\%. Show in simulation

Task 5: How good does the test have to be?

Prevalence 1 %1\,\%, sensitivity 90 %90\,\%. What specificity is needed at least so that at least half of the people who test positive are ill? Load task

Show solution

We need false positives ≤\le true positives, i.e. 0.99⋅(1−s)≤0.0090.99 \cdot (1 - s) \le 0.009, so 1−s≤0.009091 - s \le 0.00909 and s≥99.09 %s \ge 99.09\,\%. With s=99.1 %s = 99.1\,\% you get P(D∣+)=0.0090.009+0.00891≈50.3 %P(D \mid +) = \frac{0.009}{0.009 + 0.00891} \approx 50.3\,\%. Show in simulation

Ideas for the classroom

  • Use: conditional probability and Bayes’ theorem (upper secondary). Two-way tables and tree diagrams are covered in more depth in Two-way tables and Venn diagrams, path rules in Multi-stage experiments.
  • Start with an estimate: before revealing it, let students guess how likely a person who tested positive is ill – the guesses are often far above 9 %9\,\%.
  • Natural frequencies: the icon picture and the tree with counts often make the calculation easier to follow than the formula alone; Bayes’ formula can then be read off the tree.
  • For tasks: with “Show results” switched off, counts and predictive values appear as “?”. Prevalence, sensitivity and specificity stay visible.
  • Model/simplifications: prevalence, sensitivity and specificity are fixed numbers; for the second test the tests are assumed independent. The counts in the picture are rounded (always summing to 10001000), the percentages are calculated exactly. It is worth discussing with the class that a positive result is followed up by a doctor in practice; the simulation makes no statement about individual real tests.
  • Common stumbling blocks:
    • Confusing sensitivity P(+∣D)P(+ \mid D) with the predictive value P(D∣+)P(D \mid +) (“the test is 90 %90\,\% reliable, so I am 90 %90\,\% likely to be ill”).
    • Ignoring the prevalence (base rate).
    • Taking the first-stage branches of the reversed tree from the forward tree.
    • Mixing up false positives and false negatives.