ENFR

PPV / NPV calculator: why your positive test might be wrong

A playground: three sliders, 1,000 patients, and a question every doctor eventually faces.

Sensitivity (Se)

Of 100 people who have the disease, how many the test catches. At 99%: one sick person per hundred slips through.

Specificity (Sp)

Of 100 healthy people, how many it correctly clears. At 99%: one false alarm per hundred healthy.

Prevalence

How common the disease is among the people being tested. Not in the test's documentation - because it's not about the test. And it changes everything below.

The situation

You are the doctor. A patient from a low-risk group takes a screening test. You know the test: it catches 99 sick out of 100 (Se = 99%) and clears 99 healthy out of 100 (Sp = 99%). You also know the disease is rare: about 1 person in 1,000. The result comes back positive. The question you have to answer, before you say a word to the patient: how likely is it that they are actually sick?

In a statistics course this reads like one more topic to memorise. In a clinic it is not: patients act on a test result, and some of those decisions cannot be undone. People - pregnant women among them - have been told they were gravely ill on a positive whose real certainty was barely better than a coin flip. One documented case: The counsellors who were 100% sure

How to use

Below are 1,000 dots - one per person tested. The sliders set how common the disease is and how good the test is; the dots show who the test flags. Start with the presets, then push the sliders to the edges.

sick, caught (TP) healthy, false alarm (FP) sick, missed (FN) healthy, cleared (TN)
Everything on this page in reference form: strict definitions, Bayes derived four ways, where Se, Sp and prevalence actually come from, and typical values for real tests. PPV / NPV cheat sheet

The same result laid out as a table - the 2×2 that every one of these problems collapses to:

Disease +Disease −Total
Test +
Test −
Total1000

The 2×2 table

Every result lands in one of four boxes. Columns are the truth (has the disease or not), rows are what the test said.

TP - has the disease and tests positive: correctly caught.
FP - healthy but tests positive: a false alarm.
FN - has the disease but tests negative: missed.
TN - healthy and tests negative: correctly cleared.

PPV reads across the top row: TP / (TP + FP) - of everyone who tested positive, the share who are truly sick.

Sensitivity, specificity, PPV, NPV: what is the difference?

This is the confusion the whole topic turns on, and the sliders above have just demonstrated the answer. Sensitivity and specificity are properties of the test. They describe what the test does to a group already sorted by the truth, and they do not move when the disease gets rarer. Predictive values are not properties of the test. They describe what a result means for the person in front of you, and they depend on how common the disease is among the people being tested.

Here is the same test — a mammogram, sensitivity 90%, specificity 91% — moved through four settings. Nothing about the assay changes. Watch the left two columns stand still and the right two move.

Who is being tested Prevalence SeSpPPVNPV
Rare-disease screening0.1%90%91%1.0%100.0%
Screening mammography1%90%91%9.2%99.9%
Symptomatic patient10%90%91%52.6%98.8%
Strong clinical suspicion50%90%91%90.9%90.1%

Sensitivity and specificity: identical in all four rows. PPV: from 1% to 91% — a factor of 92. Same test, same numbers on the box, four completely different meanings of the word “positive”.

The practical rule. Sensitivity and specificity are what you read off the manufacturer’s insert, and they transport between settings. Predictive values are what you compute yourself, from the prevalence of the population you are testing. A PPV printed in a paper describes that paper’s population, not your clinic.

So why does the disease’s rarity swing the answer this hard? Here is the reasoning in words, then the formula.

What the numbers actually mean

Sensitivity and specificity answer a forward question: if a person is sick, how often does the test say so? Your patient is asking the reverse question: given this positive result, am I actually sick? That reverse answer is the positive predictive value (PPV), and unlike sensitivity or specificity it depends on the prevalence, how common the disease is in the tested group. The test cannot know that, so the test alone cannot answer your patient.

$$\text{PPV} = \frac{Se \cdot p}{Se \cdot p + (1-Sp)(1-p)} \qquad \text{NPV} = \frac{Sp\,(1-p)}{Sp\,(1-p) + (1-Se)\,p}$$

p is the prevalence, the pre-test probability.

There is a trick that makes this effortless, and it is the one the surveyed doctors were missing: reason in people, not percentages. Ten in a thousand, the test catches nine is something anyone can follow; 90% sensitivity at 1% prevalence hides the answer. Whenever a test problem feels slippery, rebuild it as a crowd of 1,000, which is exactly what the dots above do.

If you come from machine learning: PPV is exactly what you call precision, and sensitivity is recall. Same math, different exam.

The best way to get it: work one by hand

Problem

A 50-year-old woman has a routine screening mammogram. In her age group, about 1 in 100 women has breast cancer at the time of screening. The mammogram detects about 90% of cancers (sensitivity) and returns a false positive in about 9% of healthy women (specificity 91%). Her result is positive. How likely is she to have cancer?

Do not start with the percentages. Start with 1,000 women like her:

• About 10 have cancer (1 in 100). The mammogram catches about 9 of them (90%): 9 true positives.
• About 990 are healthy. About 9% get a false positive: 89 false positives.
• So about 98 women test positive, and only 9 truly have cancer.
PPV = 9 / 98 ≈ 9%.

The formula agrees, of course:

$$\text{PPV} = \frac{0.90 \times 0.01}{0.90 \times 0.01 + 0.09 \times 0.99} = \frac{0.009}{0.098} \approx 0.092$$
Nine percent. A positive screening mammogram is wrong far more often than it is right, which is exactly why a positive screen leads to a biopsy, not a diagnosis. Press the Mammography preset above to see these same 1,000 women as dots.

Common questions

Why can a 99% accurate test still be wrong most of the time?

Because accuracy ignores how rare the disease is. When prevalence is low, the few true positives are outnumbered by false positives from the large healthy majority, so a positive result can be more likely wrong than right. Prevalence, not the test's headline accuracy, drives the predictive value.

What is the difference between sensitivity and PPV?

Sensitivity is fixed by the test: of the people who have the disease, the share it catches. PPV runs the other way and depends on prevalence: of the people who test positive, the share who are truly sick. A test can have 99% sensitivity and still a low PPV when the disease is rare.

Do sensitivity and specificity depend on prevalence?

No. They are properties of the test: they describe how it behaves in people already known to be diseased, or already known to be healthy. Predictive values are the opposite: PPV and NPV depend on prevalence, because they describe a mixed population of people whose status is unknown. This is why the same test can have a PPV of 1% in screening and 91% in a symptomatic patient.

Why does PPV depend on prevalence?

Because PPV is the share of true positives among all positives, and the false positives are drawn from the healthy group. When the disease is rare, the healthy group is almost the entire population, so even a small false positive rate produces more false positives than there are true cases in existence. Make the disease common and the arithmetic reverses.

How do you calculate positive predictive value?

PPV is the true positives divided by everyone who tests positive. In terms of the test, PPV equals sensitivity times prevalence, divided by that same term plus one-minus-specificity times one-minus-prevalence.

This is one intuition trap. The Paradoxes & Intuition Traps section of Stat Exam Pro is a whole set of them - exam-style questions with worked answers, in English and French.

Get it on iPhone