Bayes' theorem and base rates
The question
One person in 100 has a condition. A test flags 90% of them and 5% of everyone else. If a person tests positive, how likely is it that they have it?
Stage 1 asks for your guess before the page counts anything.
- 1 SeeGuess, then sort 10,000 people.
- 2 TryPredict, then turn three dials.
- 3 ProveBuild the odds form, line by line.
- 4 ApplyTests, retests and trading backtests.
Before you start · 3 quick checks on conditional probability, an expected count and independent events, about 3 min
Two ideas before you start
2 ideasEach rate divides by a different group
Figure: twenty people as squares, six with D (three of them test positive) and fourteen without (one tests positive); the group the chosen rate divides by is highlighted. It needs JavaScript.
P(D) = 6 has D / 20 everyone = 3/10 = 0.3
In this small group of 20, filled squares test positive. Sensitivity divides by the people with D; P(D | +) divides by the people who test positive. Same people, different groups, different numbers.
Exact definition
A test and a condition. A person is picked at random from a population. Let \(D\) be the event that the person has a condition, and \(+\) and \(-\) the events that a test on the person is positive or negative. \(D^{c}\) is the event that the person does not have the condition.
The prevalence is \(P(D)\), the share of the population with the condition. The sensitivity is \(P(+ \mid D)\), the share of people with the condition who test positive. The specificity is \(P(- \mid D^{c})\), the share of people without the condition who test negative; one minus the specificity, \(P(+ \mid D^{c})\), is the false-positive rate. The question this page asks is \(P(D \mid +)\), the share of people who test positive who have the condition. Conditional probability is defined in the lesson on conditional probability and the Monty Hall problem: \(P(A \mid B) = P(A \cap B)/P(B)\) when \(P(B) \gt 0\).
Odds compare yes with no
Figure: a probability k out of n drawn as k filled squares among n; the odds compare the filled squares with the outlined ones. It needs JavaScript.
odds = P/(1 − P) = 1/5 ÷ 4/5 = 1/4
Odds of 1 to 4 mean one yes for every four no, the same as a probability of 1/5. Stage 3 shows that a test result multiplies the odds by a fixed factor, which is why odds are worth having.
Exact definition
Odds. For an event with probability \(P\), where \(0 \lt P \lt 1\), the odds are \(O = P/(1 - P)\), the probability that it happens divided by the probability that it does not. Odds of \(a/b\) are read "\(a\) to \(b\)". Going back, \(P = O/(1 + O)\). Odds take every positive value, with no upper bound, and they rise when \(P\) rises.
Fine print: expected counts, and what a rate belongs to
The grids on this page draw a population of 10,000 people with every rate holding exactly. These are the expected counts: in a real group of 10,000 the counts would vary around them, but the probabilities for one person picked at random are the same.
The sensitivity and the specificity describe the test. The prevalence describes the group being tested, so the same test can have a different \(P(D \mid +)\) in a different group. The numbers on this page are made up for the exercise and describe no real test or condition.
Guess, then count
- Read the setup and pick one range for \(P(D \mid +)\). Your pick is locked.
- The grid then sorts the 10,000 people by test result, and the page explains your pick.
- Then move the specificity and watch the false positives. Answer again clears everything.
Your guess for \(P(D \mid +)\):
Now change the specificity. The prevalence stays 1% and the sensitivity 90%.
Change the group, repeat the test
Two predictions first. The explorer below them opens once both are answered.
The explorer opens when you have answered the two questions above.
Explorer: prevalence, sensitivity, specificity
Set the three rates in whole percents. The grid draws 10,000 people with the rates holding exactly.
Goals
Bayes' theorem in odds form
Assumptions. A person is picked at random from a population. Let \(D\) be the event that the person has the condition and \(+\) the event that the person tests positive. Write \(p = P(D)\) for the prevalence, \(s = P(+ \mid D)\) for the sensitivity and \(f = P(+ \mid D^{c})\) for the false-positive rate, which is one minus the specificity. Assume \(0 \lt p \lt 1\) and \(0 \lt f \lt s \le 1\): the test is positive more often for people with the condition than for people without it.
Conclusion. \(P(+) \gt 0\), and
\[\begin{aligned} \frac{P(D \mid +)}{P(D^{c} \mid +)} &= \frac{s}{f} \cdot \frac{p}{1 - p}, \\ P(D \mid +) &= \frac{sp}{sp + f(1 - p)} \gt p. \end{aligned}\]In words: the posterior odds equal the likelihood ratio \(s/f\) times the prior odds, and a positive result raises the probability of the condition, though it can stay far below \(s\).
Facts the proof uses.
- the multiplication rule \(P(A \cap B) = P(B \mid A)\,P(A)\) when \(P(A) \gt 0\);
- the law of total probability for the two cases \(D\) and \(D^{c}\);
- the definition \(P(A \mid B) = P(A \cap B)/P(B)\) when \(P(B) \gt 0\). The lesson on conditional probability and the Monty Hall problem covers all three.
Each option is one statement about the \(p\), \(s\) and \(f\) of the theorem. Pick the one that is true in every case the theorem allows: every \(p\) with \(0 \lt p \lt 1\) and every \(f\), \(s\) with \(0 \lt f \lt s \le 1\).
Problems
Each problem states its model, and has hints and a full solution. Answers can be decimals or exact fractions.
Further reading
- J. K. Blitzstein and J. Hwang, Introduction to Probability, 2nd ed. (CRC Press, 2019), ch. 2, "Conditional Probability," on Bayes' rule and its odds form.
- S. Ross, A First Course in Probability, 10th ed. (Pearson, 2019), ch. 3, "Conditional Probability and Independence."
- G. Gigerenzer, Calculated Risks: How to Know When Numbers Deceive You (Simon & Schuster, 2002), on natural frequencies and test results.