Diagnostic Test 2×2 Table Calculator: Sensitivity, Specificity, and Predictive Values
The core of evaluating a diagnostic test is a 2×2 contingency table: rows represent test results (positive/negative), columns represent true disease status (disease present/absent). The four cells record four types of subjects:
True disease (+) No disease (−)
Test positive (+) TP FP
Test negative (−) FN TN
- TP (True Positive): disease present and correctly detected
- FP (False Positive): no disease but test is positive
- FN (False Negative): disease present but test is negative
- TN (True Negative): no disease and correctly excluded
Eight Core Metrics
Sensitivity Se = TP / (TP + FN)
Specificity Sp = TN / (TN + FP)
Positive Predictive Value PPV = TP / (TP + FP)
Negative Predictive Value NPV = TN / (TN + FN)
Positive Likelihood Ratio LR+ = Se / (1 − Sp)
Negative Likelihood Ratio LR− = (1 − Se) / Sp
Youden's Index J = Se + Sp − 1
Accuracy = (TP + TN) / (TP + FP + FN + TN)
Sensitivity and specificity are intrinsic properties of the test and are unaffected by disease prevalence — they can be compared across populations. PPV and NPV vary with prevalence: the same test applied in rare-disease screening (prevalence 0.1%) versus a high-risk clinic (prevalence 40%) can yield PPV values differing by a factor of 100.
LR+ (positive likelihood ratio): the larger it is, the more a positive result supports the diagnosis. LR− (negative likelihood ratio): the smaller it is, the more a negative result rules out the diagnosis. Jaeschke 1994 empirical thresholds: LR+ > 10 or LR− < 0.1 indicates strong diagnostic value; LR+ 2–5 or LR− 0.2–0.5 indicates limited diagnostic value.
Youden’s index J combines sensitivity and specificity, and is commonly used in ROC analysis to select the optimal cut-off point (the J-maximising point balances the costs of false positives and false negatives).
Bayesian Posterior Probability
If the prevalence P₀ (prior probability) in the target population is known, it can be updated to a posterior probability using the likelihood ratio:
Prior odds = P₀ / (1 − P₀)
Posterior odds = Prior odds × LR
Posterior probability = Posterior odds / (1 + Posterior odds)
This is mathematically equivalent to substituting the prevalence directly to compute adjusted PPV/NPV, but more intuitive: it treats the test result as evidence that updates the prior.
Confidence Intervals: Wilson Score Method
For proportion p̂ = k/n, the Wilson 95% confidence interval is:
Let z = 1.96
Centre = p̂ + z²/(2n)
Half-width = z × √(p̂(1−p̂)/n + z²/(4n²))
Denominator = 1 + z²/n
Lower = (Centre − Half-width) / Denominator
Upper = (Centre + Half-width) / Denominator
The Wilson method outperforms the common Wald method (p̂ ± 1.96 × SE): when p̂ is near 0 or 1, or the sample is small, Wald can produce negative lower bounds or upper bounds exceeding 1, whereas Wilson always stays within [0, 1].
Scope and Limitations
- Applicable only to binary outcomes (positive/negative). Continuous markers must have a cut-off defined before the 2×2 table can be filled.
- When any cell is 0, some metrics become undefined (e.g., FP = 0 → LR+ = ∞). The tool flags each case individually but does not automatically apply a 0.5 Haldane–Anscombe correction; that decision rests with the investigator.
- Using LR to update posterior probability implicitly assumes the test’s sensitivity/specificity in the target population matches those estimated in the study sample — different sample types or cut-off values may violate this assumption.
- This tool does not produce ROC curves (which require data across multiple cut-offs); it evaluates performance at a single specified cut-off.
Worked Example
Input: TP = 45, FP = 10, FN = 5, TN = 90 (n = 150, sample prevalence = 50/150 ≈ 0.333)
Se = 45 / (45 + 5) = 45 / 50 = 0.900
Sp = 90 / (90 + 10) = 90 / 100 = 0.900
PPV = 45 / (45 + 10) = 45 / 55 ≈ 0.818
NPV = 90 / (90 + 5) = 90 / 95 ≈ 0.947
LR+ = 0.900 / (1 − 0.900) = 0.900 / 0.100 = 9.00
LR− = (1 − 0.900) / 0.900 = 0.100 / 0.900 ≈ 0.111
J = 0.900 + 0.900 − 1 = 0.800
Accuracy = (45 + 90) / 150 = 135 / 150 = 0.900
If this test is applied in a screening population with prevalence P₀ = 0.1 (prior odds = 0.1/0.9 ≈ 0.111): - After a positive result: 0.111 × 9.00 = 1.000 → posterior probability = 0.500 - After a negative result: 0.111 × 0.111 = 0.0123 → posterior probability ≈ 0.012
LR+ = 9.0 indicates good test performance but falls short of the “strong diagnostic value” threshold (> 10).
Common Errors
- Swapping TP/FP/FN/TN across rows and columns: FP is “no disease but positive,” FN is “disease present but negative” — swapping them exchanges Se and Sp, yet the values remain within plausible ranges, making the error very hard to detect. Verify the definition of each cell before entering data.
- Using the sample proportion as the population prevalence: The disease proportion in the 2×2 table ((TP+FN)/n) reflects the enrolled study population, not necessarily the prevalence in the intended application population. If the sample proportion is used to estimate PPV/NPV for an external population, that assumption must be stated explicitly.
- Reporting PPV without stating the prevalence: PPV is meaningless without a prevalence context; readers cannot apply the result to their own population. Report LR+/LR− alongside PPV — they are properties of the test that are independent of the population.
FAQ
What is the difference between PPV and sensitivity?
Sensitivity is the proportion of diseased subjects correctly detected by the test; it depends only on the test itself and does not vary across populations. PPV is the probability that a positive result truly indicates disease, and also depends on prevalence. The same test applied in rare-disease screening (prevalence 0.1%) versus a high-risk clinic (prevalence 40%) can yield PPV values differing by more than 100-fold.
Why report likelihood ratios rather than just PPV?
Positive and negative likelihood ratios (LR+/LR−) are intrinsic properties of the test and do not change with population prevalence; PPV and NPV shift with every population. Reporting LR allows readers to apply Bayes' theorem with their own population's prevalence to derive posterior probabilities — more transferable than a standalone PPV.
How is Youden's index J used?
J = Sensitivity + Specificity − 1, ranging from 0 to 1; higher is better. It is commonly used to select the optimal cut-off from a continuous marker's ROC curve: the point maximising J balances the costs of false positives and false negatives. J = 0 is equivalent to random guessing; J = 1 is a perfect test.
How does this differ from a chi-square test?
The chi-square / Fisher's exact test (see the chi-square-fisher tool) asks whether there is a statistically significant association between test result and disease status (outputs p-value and odds ratio). This tool asks how clinically useful the test is (outputs sensitivity, specificity, and related metrics for direct use in clinical decisions). The two are complementary, not interchangeable.
What if one cell is zero?
If FP = 0, LR+ is undefined (positive infinity); if FN = 0, LR− = 0; if TP = 0 or TN = 0, Se or Sp cannot be defined. The tool flags each affected metric individually but does not automatically apply a 0.5 Haldane–Anscombe correction, because the decision to correct depends on the study design and rests with the investigator.
Related tools
Multiple Testing Correction Calculator: BH (FDR), BY, and Bonferroni
Paste a column of p-values and get BH q-values, BY, and Bonferroni corrections side by side in one step.
qPCR 2^−ΔΔCt Relative Quantification Online Calculator
Paste your Ct table and get ΔCt, ΔΔCt, fold-change, and within-group dispersion calculated automatically.
Gene List Intersection, Union & Difference — Online Venn Set Calculator
Paste 2–3 gene/ID lists and instantly get intersections, unions, and unique elements, with deduplication and case normalization.
Buy me a coffee