Probability

Bayes' theorem is a picture of a square

A test that is 99% accurate returns a positive result. The chance it is right can easily be under one in five, and the reason is visible the moment the population is drawn as a square rather than described as a formula.
14 min read 6 figures Small cases lie

A disease affects one person in a hundred. A test for it is very good: it catches 99% of those who have it, and it wrongly flags only 5% of those who do not.

Someone tests positive. What is the chance they have the disease?

The answer is 16.7%, and most people — including, in repeated studies, most physicians — put it somewhere above 90%. The gap is not a subtlety. It is the difference between a result that means almost certainly and one that means probably not, and the whole of it is visible in a single square.

Bayes' theorem as two rectanglesA unit square split by how common the condition is (1.0%) and then by how the test behaves. Of everyone who tests positive, the fraction who have it is 16.7%.has itdoes nottests positivetrue, and positive: 0.99%false, and positive: 4.95%so of the positives,16.7% really have it
Fig. 1 Everyone, as a unit square. The narrow strip on the left is the 1% who have it; the wide region on the right is the 99% who do not. The shaded parts are those who test positive — and there are more of them on the right.

Reading the square

The square is the whole population. Split it left and right by who has the disease: a strip of width 0.010.01 against a region of width 0.990.99.

Now split each part vertically, by what the test does to those people.

Of the 1% who have it, 99% test positive — nearly all of that narrow strip is shaded. That is 0.01×0.99=0.00990.01 \times 0.99 = 0.0099 of everyone: the true positives.

Of the 99% who do not, 5% test positive anyway — a thin slice of a very wide region. That is 0.99×0.05=0.04950.99 \times 0.05 = 0.0495 of everyone: the false positives.

Now compare the two shaded areas. The false-positive block is five times larger than the true-positive one, despite coming from a much smaller rate, because it is a small fraction of a huge group and the other is a large fraction of a tiny one.

Someone who tests positive is somewhere in the shaded region. The chance they are in the correct part is

0.00990.0099+0.0495=0.00990.0594=0.167.\frac{0.0099}{0.0099 + 0.0495} = \frac{0.0099}{0.0594} = 0.167.

That is the whole calculation, and it is a ratio of two rectangles.

The theorem is the picture

Written symbolically, what has just been done is

P(D+)=P(+D)P(D)P(+D)P(D)+P(+¬D)P(¬D).P(D \mid +) = \frac{P(+ \mid D)\,P(D)}{P(+ \mid D)\,P(D) + P(+ \mid \neg D)\,P(\neg D)}.

That is Bayes’ theorem, and it is notoriously hard to hold in the head. Every term in it is a side or an area in the square: the numerator is the true-positive rectangle, and the denominator is both shaded rectangles together.

The generator computes both ways and requires them to agree — the four areas must sum to exactly one, and the shaded fraction must equal what the formula returns. The picture and the algebra check each other rather than one being trusted. That is the same discipline that makes a dissection proof honest: two squares holding the same four triangles is a claim about areas, and it is worth nothing unless the areas are computed rather than eyeballed.

The reason the picture is easier is worth naming. The formula asks a reader to track four conditional probabilities that all look alike and mean different things; the square asks them to compare two rectangles. Nothing has been simplified — the same numbers appear — but the bookkeeping has been handed to the geometry.

Natural frequencies do the same work

There is a second presentation with the same effect and no diagram, and it is worth knowing because it can be done out loud.

Instead of percentages, use a concrete population of 10,000 people:

  • 100 have the disease. Of those, 99 test positive.
  • 9,900 do not. Of those, 495 test positive.
  • So 594 people test positive, and 99 of them have it.

9999 out of 594594 is one in six. Presented this way, the question stops being difficult — studies that gave physicians the frequency version rather than the percentage version found comprehension rising from around 15% to around 75%.

That is a striking result about presentation rather than about mathematics. The two versions are arithmetically identical. One of them defeats trained professionals and the other does not, and the difference is whether the quantities are counts of people or fractions of a whole.

The likely reason is that a percentage has already thrown away the denominator. Saying 5% of the healthy group requires the reader to remember how big that group was in order to know what the 5% amounts to, and remembering is exactly what does not happen. Saying 495 people has the group size already multiplied in. The frequency version is not clearer prose; it is prose that has done one of the two multiplications on the reader’s behalf, and that multiplication is the one everybody skips.

This is the same service the square performs, by a different route: an area is a product of two lengths, so drawing the rectangle is the multiplication.

The square works for the same reason as the frequency version: both make the sizes of the two groups visible before the test rates are applied. The percentage version mentions those sizes once, at the start, and then never again — and the base rate is the thing that gets dropped.

Which way the square is cut

The single most common error in this subject has a clean description in terms of the picture: it is reading the square along the wrong axis.

The square is cut twice. The first cut is vertical, by who has the disease, and it is made before the test is mentioned. The second cut is horizontal within each column, by what the test does to that column’s people.

Those two cuts answer two different questions, and both are called “the accuracy of the test”.

Going down a column gives P(+D)P(+ \mid D) — of the people who have it, what fraction test positive. That is 99%, and it is a property of the test, measured in the laboratory.

Going along the shaded row gives P(D+)P(D \mid +) — of the people who test positive, what fraction have it. That is 16.7%, and it is a property of the test and the population together.

The two numbers are computed from the same square and they are not close. Confusing them is base rate neglect, and it is what makes the whole problem hard: the phrase the test is 99% accurate names the first, and the question anyone actually cares about asks for the second.

Bayes' theorem as two rectanglesA unit square split by how common the condition is (0.1%) and then by how the test behaves. Of everyone who tests positive, the fraction who have it is 1.9%.has itdoes nottests positivetrue, and positive: 0.10%false, and positive: 5.00%so of the positives,1.9% really have it
Fig. 2 One in a thousand. The left-hand strip has almost vanished and the false positives dominate completely: a positive result now means a 2% chance, from a test whose column-wise accuracy has not changed at all.

Written as a slogan: the test’s accuracy reads down a column, and the question reads along a row. The square is the only presentation in which those are visibly different operations, which is precisely why the formula’s four terms are so easy to interchange.

What the answer actually depends on

The most useful experiment is to change one number at a time and see which one moves the answer.

The same test, at every base rateA test with 99% sensitivity and 95% specificity, applied to populations in which the condition is more or less common. The chance that a positive result is real is a property of the population as much as of the test.00.20.40.60.8100.20.40.60.81how common the condition ischance a positive is real0.1% → 2%1% → 17%10% → 69%50% → 95%
Fig. 3 The same test — 99% sensitivity, 95% specificity — applied to populations in which the condition is more or less common. The chance a positive is real runs from near zero to near one, with the test unchanged throughout.

The curve is the whole point of the essay. A positive result’s meaning is a property of the population as much as of the test. The identical test, on the identical patient, with the identical result, supports a completely different conclusion depending on how common the condition is where that patient came from.

At one in a thousand, a positive means a 2% chance. At one in a hundred, 17%. At one in ten, 69%. At one in two, 95%.

That is why screening a general population and testing a symptomatic patient are different acts with the same instrument. The symptomatic patient has a much higher prior — that is what a symptom is — and the same positive result means much more.

The curve is also a warning about small samples. Estimating a base rate from a handful of cases gives a number with enormous uncertainty, and the answer’s sensitivity to it means that uncertainty propagates straight through. Where the base rate is itself measured, the sensible thing is to carry its error bar rather than a point value — and the error on a proportion measured from nn observations shrinks only as 1/n1/\sqrt n, which is the same slow rate that governs every sampling estimate and the same square root that makes a Galton board’s shape reliable.

Bayes' theorem as two rectanglesA unit square split by how common the condition is (10.0%) and then by how the test behaves. Of everyone who tests positive, the fraction who have it is 68.7%.has itdoes nottests positivetrue, and positive: 9.90%false, and positive: 4.50%so of the positives,68.7% really have it
Fig. 4 The same test on a population where one in ten is affected. The left-hand strip is now wide enough to compete, and a positive result is right 69% of the time.

Improving the wrong number

Given the disappointing answer, the instinct is to demand a better test. The square says which kind of better.

Sensitivity is already 99%, and the true-positive rectangle can gain at most 1% of its own width — it is nearly as tall as it can be. Perfecting it entirely, to 100%, moves the answer from 16.7% to 16.8%.

The false-positive rate is 5% of a very wide region, and that region is 99 times wider. Cutting it from 5% to 1% shrinks the false-positive block fivefold and moves the answer from 16.7% to 50%. Cutting it to 0.1% gives 91%.

So for a rare condition, specificity is worth far more than sensitivity, and the reason is entirely about which rectangle has room to change. It is a design conclusion that falls out of looking rather than out of calculating, and it explains why screening programmes are built around a cheap sensitive test followed by an expensive specific one: the first test’s job is to shrink the population, and the second operates at a prior the first has raised.

Bayes' theorem as two rectanglesA unit square split by how common the condition is (1.0%) and then by how the test behaves. Of everyone who tests positive, the fraction who have it is 50.0%.has itdoes nottests positivetrue, and positive: 0.99%false, and positive: 0.99%so of the positives,50.0% really have it
Fig. 5 The same population and the same sensitivity, with the false-positive rate cut from 5% to 1%. Nothing about the left strip has changed and the answer has risen from 16.7% to 50%.

Where it is not a medical question

The structure recurs anywhere a rare thing is searched for with an imperfect instrument, and the consequences are usually worse than in medicine because the base rate is lower.

Automated screening for fraud, for terrorism, for doping, for plagiarism: in every case the condition is very rare, so the wide region is very wide, and even an excellent false-positive rate produces far more wrong flags than right ones. A test that is 99.9% specific, applied to a population where one in a million is guilty, produces a thousand false accusations for every true one.

It is worth seeing that this is the same structural fact as the birthday problem, run in the opposite direction. There, a rare per-pair event became likely because there were enormously many pairs. Here, a rare per-person error becomes dominant because there are enormously many people to make it on. In both cases a small rate multiplied by a large population beats a large rate multiplied by a small one, and in both cases the intuition that fails is the one that attends to the rate and not to the multiplier.

The same test, at every base rateA test with 99% sensitivity and 99% specificity, applied to populations in which the condition is more or less common. The chance that a positive result is real is a property of the population as much as of the test.00.20.40.60.8100.20.40.60.81how common the condition ischance a positive is real0.1% → 9%1% → 50%10% → 92%50% → 99%
Fig. 6 The sweep again with the false-positive rate cut to 1%. The curve has shifted bodily left — the same base rate now supports a much stronger conclusion — and the shape is unchanged, because the shape belongs to the arithmetic rather than to the test.

Comparing the two sweeps gives the design rule in one glance: improving specificity slides the curve toward rarer conditions, which is exactly the direction a screening programme needs. Improving sensitivity would raise the curve’s ceiling, which was already close to one and was never the constraint.

The same arithmetic runs in courtrooms, where it has a name — the prosecutor’s fallacy. The chance of this DNA match arising by chance is one in a million is a statement about P(matchinnocent)P(\text{match} \mid \text{innocent}). The chance the defendant is innocent is one in a million is a statement about P(innocentmatch)P(\text{innocent} \mid \text{match}). They are different numbers, related by the square, and the second depends on how many people were in the pool searched. Convictions have been overturned on precisely this confusion. The error is the same one a striking pattern in a picture invites: a number that is genuinely small is offered as evidence for a conclusion it does not by itself support, and the missing ingredient is how many opportunities there were for it to arise.

What the picture cannot show

The square requires the numbers, and the numbers are the hard part. Sensitivity and specificity are measured, with uncertainty; the base rate is often not known at all, and for a novel condition or a screened population it may be the least certain quantity in the calculation. The figure presents three numbers with equal confidence and one of them is usually a guess.

Nor can the picture show what to do when the prior is genuinely unknown. That is the standing objection to the Bayesian method and it is not resolved by any diagram: where a prior comes from, when there is no population to count, is a question about evidence and judgement rather than about area.

The figure is also silent about dependence between tests. Testing twice and getting two positives feels like it should square the improvement, and it does only if the two tests fail independently. Repeating the same test usually reproduces the same error — a sample contaminated once is contaminated on retest — so the second result may carry almost no information. The square drawn for a second test would look identical and would be wrong, and nothing about it would indicate that.

The ladder from here

Rungs above: the odds form of the theorem, where the update is a single multiplication by a likelihood ratio and the arithmetic becomes trivial. Sequential updating, with the posterior of one test as the prior of the next, and the independence condition stated. Sensitivity and specificity as a trade-off along an ROC curve, with the threshold as the parameter. The prosecutor’s fallacy worked through on a real case. Base rate neglect in the psychological literature, and what presentations repair it. Priors, conjugacy, and where the Bayesian and frequentist accounts genuinely differ. And the connection to information — a test’s value measured in bits, which is the right way to compare two tests that trade sensitivity against specificity.

What the square is really for

The general move here is one the whole collection keeps returning to: replace a formula with a quantity that has parts, then compare the parts.

Bayes’ theorem as symbols is four conditional probabilities in a fraction, and the only way through it is care. Bayes’ theorem as a square is two rectangles, and the answer is which is bigger. The same information is present in both. One of them can be checked at a glance and the other cannot.

That is what the dot product as a shadow does for a coordinate rule, what rectangles do for the integral, and what a Galton board does for the binomial distribution. In each case a computation is exchanged for a comparison, and comparisons are what people are good at.

The corollary is worth stating too, because it is the honest limit. The picture makes the calculation easy and does nothing about the inputs. A square drawn from a base rate somebody invented is exactly as wrong as a formula evaluated on it, and considerably more persuasive.