Hexa Scholar

Bayes' theorem and base rates

A sorting machine: a glass hopper holds hundreds of navy marbles and five gold ones, above a gate with one amber lamp and an empty tray.
A screening test as a sorting machine: five gold marbles sit among hundreds of navy ones above a gate and an empty tray.

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. 1 SeeGuess, then sort 10,000 people.
  2. 2 TryPredict, then turn three dials.
  3. 3 ProveBuild the odds form, line by line.
  4. 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 ideas

Each 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.

Rate:

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.

P =

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.

1 See

Guess, then count

Your guess for \(P(D \mid +)\):

    2 Try

    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.

    3 Prove

    Bayes' theorem in odds form

    Theorem

    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\).

    What else follows
    4 Apply

    Problems

    Each problem states its model, and has hints and a full solution. Answers can be decimals or exact fractions.

    Key point To find \(P(D \mid +)\), either count expected people in each branch, or multiply the prior odds by the likelihood ratio and turn the odds \(O\) into \(O/(1 + O)\). Both give the same answer. Results that are independent given \(D\) and given \(D^{c}\) multiply the odds again, and the answer always depends on the base rate of the group.
    Level Intro Prerequisites conditional probability (the lesson on the Monty Hall problem), expected counts (the lesson on expectation and variance) Time ~35 min

    Further reading