How to calculate sensitivity and specificity
Sensitivity and specificity describe how well a binary diagnostic test (or classifier) separates people who have a condition from people who do not. Both are computed from a 2×2 confusion matrix that cross-tabulates the test result against the true disease status, verified by a reference "gold standard".
The four cells are: true positives (TP) — has the condition and tested positive; false negatives (FN) — has the condition but tested negative; true negatives (TN) — free of the condition and tested negative; and false positives (FP) — free of the condition but tested positive.
- Sensitivity (true positive rate, recall) = TP / (TP + FN). Of everyone who truly has the condition, the fraction the test correctly identifies.
- Specificity (true negative rate) = TN / (TN + FP). Of everyone who is truly free of the condition, the fraction the test correctly clears.
A worked example: screening 1,000 people where 100 truly have the disease. If the test catches 90 of them (TP = 90, FN = 10) and correctly clears 860 of the 900 healthy people (TN = 860, FP = 40), then sensitivity = 90 / 100 = 0.90 (90%) and specificity = 860 / 900 ≈ 0.9556 (95.6%).
Why both numbers matter
Sensitivity and specificity trade off against each other as you move a test's classification cutoff. Lowering the cutoff catches more true cases (higher sensitivity) but also flags more healthy people (lower specificity). A test that simply calls everyone positive has 100% sensitivity and 0% specificity, which is why you must always report the pair together, not one in isolation.
Predictive values and prevalence
Sensitivity and specificity are intrinsic to the test and do not change with how common the disease is, because each is measured within a single disease-status group. What patients and clinicians usually want, though, is the reverse question answered by predictive values:
- Positive predictive value (PPV) = TP / (TP + FP): given a positive test, the probability the person really has the condition.
- Negative predictive value (NPV) = TN / (TN + FN): given a negative test, the probability the person is really free of it.
PPV and NPV depend heavily on prevalence. When a disease is rare, even a highly specific test produces mostly false positives, so PPV falls — the key reason population screening for rare conditions is interpreted cautiously.
Common reference points
A useful mnemonic: SnNout (a highly Sensitive test that is Negative rules a condition out) and SpPin (a highly Specific test that is Positive rules it in). Confirmatory tests are chosen for high specificity; screening tests are chosen for high sensitivity so few true cases slip through.