Why a positive test for a rare disease is usually wrong Image: Asurnipal (CC BY-SA 4.0)

Why a positive test for a rare disease is usually wrong

Take 1,000 people from a population in which 1 in 100 has a certain disease. Ten of them are ill and 990 are healthy. Give all of them a test that catches 95 per cent of the ill and clears 95 per cent of the healthy. Of the ten ill people, the test flags 9.5 on average. Of the 990 healthy people, it wrongly flags 5 per cent, which is 49.5. So 59 people receive a positive result, and only 9.5 of them are ill. The probability that a person with a positive result has the disease is \(9.5 / 59\), about 16 per cent.

Most people, including most doctors when they are asked cold, guess a number near 95 per cent. The mistake has a name, the base rate fallacy, and it is the reason this example opens so many textbooks on probability. The test is good. The disease is rare. The false positives from the large healthy group outnumber the true positives from the small ill group, and no amount of test quality short of perfection changes that arithmetic when the base rate is low.

The rule behind the count

The count on 1,000 people is Bayes' rule in disguise. Write \(D\) for "has the disease" and \(+\) for "tests positive". The three numbers given are the prevalence \(P(D) = 0.01\), the sensitivity \(P(+ \mid D) = 0.95\), and the specificity \(P(- \mid \text{not } D) = 0.95\), so the false positive rate is \(P(+ \mid \text{not } D) = 0.05\). The rule says

\[ P(D \mid +) = \frac{P(+ \mid D)\, P(D)}{P(+)}, \]

and the denominator is the total probability of a positive result, \(P(+) = 0.95 \times 0.01 + 0.05 \times 0.99 = 0.0095 + 0.0495 = 0.059\). So \(P(D \mid +) = 0.0095 / 0.059 = 0.161\). The 9.5 and the 49.5 of the count are the two terms of the denominator, multiplied by 1,000.

Each piece has a name worth learning, because the same four words appear in every machine learning paper that uses probability. \(P(D)\) is the prior, what you believed before the test. \(P(+ \mid D)\) is the likelihood, how probable the evidence is if the hypothesis is true. \(P(+)\) is the evidence, the overall probability of what you saw. \(P(D \mid +)\) is the posterior, what you believe afterwards. Bayes' rule is the one correct way to get from the prior to the posterior, and the whole of probabilistic machine learning is the business of doing it with models instead of tables.

What changes with a second test

Suppose the 59 people with a positive result are tested again with a second test of the same quality, and suppose the two tests err independently, which is the assumption a doctor would question first. The posterior after the first test, 16 per cent, is the prior for the second. Of the 9.5 ill people, 95 per cent test positive again, which is about 9.0. Of the 49.5 healthy, 5 per cent do, which is about 2.5. So 11.5 people are positive twice, and 9.0 of them are ill: the posterior is now \(9.0 / 11.5\), about 78 per cent.

The quickest way to see it is in odds. Before any test the odds of disease are 1 to 99. Each positive result multiplies the odds by the likelihood ratio, \(0.95 / 0.05 = 19\). After one test the odds are 19 to 99, which is 0.19, a probability of 16 per cent. After two they are 361 to 99, which is 3.65, a probability of 78 per cent. A third independent positive would take it to about 99 per cent. This is why screening programmes follow a positive result with a different, more specific test rather than announcing a diagnosis, and why the second test is usually of a different kind, so that its errors are as independent of the first as possible.

The same mistake in other clothes

The arithmetic does not care that the example is medical. A spam filter that flags 99 per cent of spam and 1 per cent of legitimate mail looks superb, but if only 1 message in 1,000 is spam, most of what it flags is legitimate. A security camera system that recognizes faces with 99 per cent accuracy, pointed at a crowd of a million in which ten people are wanted, raises about 10,000 false alarms for every ten true matches. A classifier that reports 99 per cent accuracy on a dataset in which 99 per cent of the examples belong to one class has learned nothing at all, since always answering that class gives the same score. Each of these is the base rate fallacy, and the cure is the same: ask how common the thing is before asking how good the test is.

In machine learning the point has two consequences. Accuracy is a poor measure for a classifier of a rare condition, and the field uses precision (of the flagged cases, how many are real) and recall (of the real cases, how many are flagged) instead. In the example above, the first test has a recall of 95 per cent and a precision of 16 per cent. And the output of a classifier is a probability that should be read as a posterior, combining what the model saw with how common each class is in the data it was trained on, which means a model trained on a dataset with half spam and half legitimate mail will be overconfident about spam when deployed where spam is rare.

A picture to keep

The reason the count on 1,000 people works where the formula does not is that it keeps the two groups visible. Draw ten figures in one colour and 990 in another, shade the ones the test flags, and the 49.5 false positives dwarf the 9.5 true ones on the page. Psychologists who study how people reason about risk, Gerd Gigerenzer among them, found that doctors and patients get the right answer far more often when the numbers are presented as counts of people rather than as percentages. The counts are called natural frequencies, and they are the form in which most practitioners actually think.

Unit 3 of the AI Masterclass works this example with the population drawing, extends it to two tests, and then builds the same reasoning into a Bayesian network with four variables and a spam filter with six words. The article on the spam filter shows the filter.

Learn how machines learn, properly

The AI Masterclass: weekly units, quizzes, a final exam, and a certificate.
About the program