How to compute sensitivity and specificity of a test

Compute sensitivity, specificity, PPV, NPV, likelihood ratios and Youden index from 2x2 table. Bayesian prevalence adjustment, F1-score, DOR, 95% Wilson CI. Clinical screening examples.

Calculation parameters
Was this calculator useful?

How to compute sensitivity and specificity of a diagnostic test: from 2x2 contingency table (TP, FP, FN, TN) Sensitivity = TP/(TP+FN) (fraction of diseased correctly identified) and Specificity = TN/(TN+FP) (fraction of healthy correctly excluded). PPV (positive predictive value) = TP/(TP+FP) probability that positive is truly diseased; NPV = TN/(TN+FN). Likelihood Ratios: LR+ = sens/(1-spec), LR- = (1-sens)/spec. Youden index = sens + spec - 1 (ROC cutoff optimization). Accuracy = (TP+TN)/N. Observed PPV/NPV depends on study prevalence: for populations with different prevalence apply Bayes PPV = sens*prev/(sens*prev + (1-spec)*(1-prev)). Fundamental tool in screening, radiology, ML evaluation, USPSTF, FDA HTA.

Diagnostic formulas

Sensitivity and Specificity: Sensitivity (true positive rate) = TP/(TP+FN). Sensitive test rules out disease when negative (SnNout rule). Specificity (true negative rate) = TN/(TN+FP). Specific test rules in when positive (SpPin rule). False Positive Rate FPR = 1 - spec, False Negative Rate FNR = 1 - sens.

Predictive values: PPV = TP/(TP+FP), post-test probability that positive patient is truly diseased. NPV = TN/(TN+FN). Vary with prevalence: in low prevalence population (1%) even 95% sens/95% spec test has PPV = 16% (high false positive rate). Bayes formula for adjustment: PPV = sens*prev / (sens*prev + (1-spec)*(1-prev)).

Likelihood Ratios (Jaeschke 1994 EBM): LR+ = sens/(1-spec) how much a positive test increases disease odds; LR- = (1-sens)/spec how much a negative test decreases odds. Practical thresholds: LR+ > 10 strong rule-in, 5-10 moderate, 2-5 mild; LR- < 0.1 strong rule-out. Independent of prevalence, ideal for Fagan nomogram applicable to single patient.

Accuracy indices: Accuracy = (TP+TN)/N global measure, misleading with imbalanced classes. Youden index J = sens + spec - 1, range [-1, +1], 0 = useless, 1 = perfect. Used to identify optimal cutoff in ROC curves. F1-score = 2*PPV*sens/(PPV+sens) precision-recall harmonic mean, popular in ML. DOR (Diagnostic Odds Ratio) = (TP*TN)/(FP*FN) = LR+/LR-, summary, used in diagnostic meta-analysis (HSROC).

Confidence Intervals: for proportions use Wilson 1927 95% CI (preferred over Wald for small samples): center = (p + z^2/2n)/(1 + z^2/n) with z = 1.96. STARD 2015 (Standards for Reporting Diagnostic accuracy studies) requires CI for sens, spec, PPV, NPV.

History and context

Terms "sensitivity" and "specificity" were introduced by Jacob Yerushalmy of UC Berkeley in 1947 ("Statistical Problems in Assessing Methods of Medical Diagnosis" Public Health Reports), in response to limitations of simple "accuracy" rate for evaluating tuberculosis tests in military screening. Yerushalmy noted that a test can have high accuracy but systematically err on the diseased (low sensitivity) in low-prevalence populations, common in screening. ROC curve (Receiver Operating Characteristic) derives from signal detection theory developed during World War II for radar (Peterson-Birdsall-Fox 1954) and was introduced in medicine by Charles Metz (University of Chicago, 1978) for radiology. William Youden (NIST) proposed the index in 1950 for cutoff optimization. Likelihood ratios were popularized in EBM (Evidence-Based Medicine) by Jaeschke-Guyatt-Sackett (1994) JAMA "Users' guides to the medical literature III: How to use an article about a diagnostic test". Today STARD 2015 (Bossuyt et al, BMJ) is reporting standard; QUADAS-2 (Whiting et al 2011) for quality assessment; PRISMA-DTA for meta-analysis. ICH E9, FDA Guidance for Industry on Statistical Approaches, EMA Reflection Papers use these indicators. Cochrane Collaboration has dedicated Diagnostic Test Accuracy group.

Benchmark values table for clinical tests

  • Optimal test: sens > 0.90, spec > 0.90 (e.g., RT-PCR SARS-CoV-2 95%/99%)
  • Adequate screening: sens > 0.85 (sensitivity priority to not miss diseased)
  • Confirmation test: spec > 0.95 (specificity priority to avoid false positives)
  • Mammography (50-74 yrs): sens 80-90%, spec 90-95% (USPSTF 2024)
  • Pap test cervix: sens 60-80% (low, repeated every 3 years), spec 95%
  • HPV-DNA cervix: sens 95%, spec 90% (USPSTF 2018 grade A)
  • SARS-CoV-2 rapid test: sens 70-90%, spec 95-99% (symptomatic vs asymptomatic)
  • D-dimer pulmonary embolism: sens 95%, spec 50% (rule-out test)
  • HIV rapid test: sens 99%, spec 99.7% (requires Western blot confirmation)
  • Cohen kappa 0.4 inter-rater fairness, 0.6 good, 0.8 excellent

Worked numerical examples

Example 1 - SARS-CoV-2 antigen rapid test. FDA EUA study: 200 symptomatic suspects, 95 positive RT-PCR (gold standard). 2x2 table: TP=85, FN=10, FP=5, TN=100. Sensitivity = 85/95 = 89.5% (95% CI 81.5-94.4%). Specificity = 100/105 = 95.2% (CI 89.3-98.0%). Observed PPV = 85/90 = 94.4%. NPV = 100/110 = 90.9%. LR+ = 18.8 (strong rule-in); LR- = 0.11 (moderate rule-out). Youden = 0.847. Adequate test for triage symptomatic, but in 1% asymptomatic screening PPV would crash to 16% applying Bayes.

Example 2 - mammography 60-year-olds. ACS study 10,000 women 60-69, breast cancer prevalence 0.6%. Table: TP=51, FN=9, FP=940, TN=9000. Sens = 51/60 = 85%, spec = 9000/9940 = 90.5%. Observed PPV = 51/991 = 5.1% (high false positive %). LR+ = 8.9 (moderate rule-in), LR- = 0.17. ACS recommends biennial 55-74 yrs; USPSTF 2024 extended 40-74.

Example 3 - high-sensitivity troponin myocardial infarction. ESC Guidelines 2023: hs-cTnT cutoff 14 ng/L. Validation 1,200 chest pain patients, NSTEMI prevalence 18%. Sens 95%, spec 80%. LR+ 4.75, LR- 0.06. NPV = 99% supports rapid rule-out (1h algorithm). Decision time reduced 40%, AHA 2025 chest pain pathway compliance.

Example 4 - HPV test vs Pap test cervix. HTA AHRQ study: 50,000 women 30-64 primary screening. HPV-DNA: sens 95%, spec 90%, precancer prevalence 0.8%. Bayes PPV = 0.95*0.008 / (0.95*0.008 + 0.1*0.992) = 7.1%. Pap test: sens 70%, spec 95%, PPV = 10.1%. HPV more sensitive (longer intervals), Pap more specific. USPSTF 2018 grade A recommends HPV primary 30-65.

Example 5 - ML deep learning radiology classifier. CNN chest CT for lung nodules, validation set 5,000 images, nodule prevalence 12%. Model output: sens 92%, spec 85%, PPV 45%, F1 = 0.605. AUC ROC 0.94. Cohen kappa with radiologists 0.78. FDA 510(k) clearance Software as Medical Device class II, validation studies for clearance.

Limits and considerations

  1. Sens/spec are intrinsic test characteristics (independent of prevalence), PPV/NPV are not.
  2. For populations different from study apply Bayes with local prevalence (USPSTF, FDA HTA).
  3. Spectrum bias (Ransohoff-Feinstein 1978): sens/spec depend on study population severity.
  4. Verification bias: gold standard not applied to all suspects, distorts estimates.
  5. Interpretation bias: test reader knows disease status, distorts reading.
  6. For continuous cutoffs (biomarkers) ROC analysis superior to single 2x2 table.
  7. STARD 2015 reporting (Bossuyt BMJ): mandatory 95% CI, flowchart, clear gold standard.
  8. QUADAS-2 (Whiting 2011) standard tool for quality assessment in systematic reviews.
  9. For ML: F1-score robust to imbalance; AUC ROC global measure; Matthews Correlation Coefficient (MCC) preferred by Chicco-Jurman 2020.
  10. USPSTF, ECDC, FDA HTA use sens/spec for public screening decisions.

Common errors

  1. Confusing sensitivity with PPV (frequent error in medical students).
  2. Reporting observed PPV without specifying study prevalence.
  3. Not Bayes-adjusting PPV when applied to different population.
  4. Using accuracy as single metric with imbalanced classes (e.g., 99% accuracy for 1% disease).
  5. Confusing Youden index with AUC (Youden is a point, AUC is integral).
  6. Not reporting 95% CI for sens/spec (non-compliant with STARD 2015).
  7. Computing LR+ with specificity = 1 (division by zero, use continuity method).
  8. Applying training set "optimal" cutoff to test set (overfitting).
  9. Confusing sens with true positive count (sens is rate, not count).
  10. Not considering verification bias when gold standard not applied to all.

Practical applications

  1. Screening: USPSTF, ACS mammography, USPSTF HPV, CDC vaccines.
  2. Radiology: CT, MRI, ultrasound, AI computer-aided detection.
  3. Cardiology: troponin ESC, BNP heart failure, exercise ECG.
  4. Infectiology: SARS-CoV-2, HIV, HCV, malaria, CDC surveillance.
  5. Oncology: PSA prostate, liquid biopsy biomarkers, FDA cell-free DNA.
  6. Genetics: BRCA1/2, NIPT prenatal, NGS panels.
  7. Machine learning: binary classifiers, F1-score, AUC ROC, MCC.
  8. Publications: STARD 2015, QUADAS-2, PRISMA-DTA for meta-analysis.
  9. Regulatory: FDA 510(k) IVD, EMA Reflection Paper, CE MDR EU 2017/745.
  10. HTA: AHRQ, NICE, IQWiG, CADTH cost-effectiveness diagnostics.

Support

Questions: info@calcoi.com. Educational tool for diagnostic accuracy. For professional applications consult Pepe "Statistical Evaluation of Medical Tests for Classification and Prediction" (Oxford 2003), STARD 2015 checklist, R packages epiR/pROC/mada, Python sklearn.metrics.

Updated July 2026

Frequently Asked Questions

Difference between sensitivity and PPV?

Sensitivity = TP/(TP+FN) measures how well the test detects diseased patients. PPV = TP/(TP+FP) measures probability that positive is truly diseased. Key difference: PPV depends on prevalence, sensitivity does not. In 1% prevalence screening, a 95%/95% sens/spec test has PPV only 16% (vast majority of positives are false). Yerushalmy 1947 introduced sens/spec specifically to separate test properties from prevalence.

How to interpret LR+ and LR-?

LR+ = sens/(1-spec) is positive likelihood ratio: how much a positive test increases disease odds. Jaeschke 1994 EBM thresholds: LR+ > 10 strong rule-in (changes post-test probability notably), 5-10 moderate, 2-5 mild, < 2 useless. LR- = (1-sens)/spec: < 0.1 strong rule-out, 0.1-0.2 moderate. Advantage: independent of prevalence, applicable to single patient via Fagan nomogram or odds * LR calculation.

When to use Youden's index?

To identify optimal cutoff maximizing sens + spec - 1, obtained at point farthest from ROC diagonal. Range [-1, +1], 0 = useless test, 1 = perfect. Youden 1950 proposed as balanced criterion without preference between false positives and negatives. For asymmetric applications (cancer: missing diseased more serious) use instead (sens, spec) ROC coordinates. Pepe 2003 "Statistical Evaluation of Medical Tests" Oxford UP chapter 4 details.

How to correct PPV for prevalence different from study?

Bayes formula: PPV = (sens * prev) / (sens * prev + (1-spec) * (1-prev)). Example: 90%/90% sens/spec test validated on 30% study prevalence (observed PPV 79%); applied in 2% prevalence screening: PPV becomes only 15.5%. Critical for population screening: USPSTF and FDA HTA always adjust with target prevalence. Sensitivity and specificity remain invariant (intrinsic test properties); only PPV/NPV change.

What does AUC of ROC curve mean?

Area Under the ROC Curve = probability that test assigns higher value to random diseased vs random healthy patient. AUC 0.5 random, 0.7 acceptable, 0.8 good, 0.9 excellent, 1.0 perfect. Advantage: cutoff-independent, summarizes all sens/spec pairs. Limits: little discrimination for concrete applications (a test with AUC 0.80 may have different clinical behavior than another). Hosmer-Lemeshow 2013 recommend partial AUC for clinically relevant cutoff ranges.

What sample size needed to validate a test?

Buderer 1996 formula: n_diseased = z^2 * sens * (1-sens) / w^2 where w = required CI precision. For +/- 5% CI on sens 90%, n_diseased = 138; n_healthy analogous for spec. If 5% prevalence, n_total = 138/0.05 = 2760. STARD 2015 recommends reporting power calculation. Pepe 2003 chapter 6 rigorous methodology. Smaller studies with wide CI acceptable for pilot but not for FDA EMA regulatory.

Difference between DOR and AUC?

DOR (Diagnostic Odds Ratio) = (TP*TN)/(FN*FP) = LR+/LR-, summary, range [0, infinity], DOR=1 useless. Typical clinical range 10-100; > 100 excellent. AUC is ROC curve integral, range [0.5; 1]. Glas-Lijmer-Prins-Bonsel-Bossuyt (J Clin Epidemiol 2003) recommend DOR for meta-analysis (HSROC) due to symmetry. AUC more intuitive for clinicians. Both require 95% CI for correct interpretation. Cochrane Diagnostic Test Accuracy Working Group uses DOR-based methods.

Formula

Sens = TP / (TP + FN)
Spec = TN / (TN + FP)
PPV = sens*prev / (sens*prev + (1-spec)*(1-prev))
NPV = spec*(1-prev) / (spec*(1-prev) + (1-sens)*prev)
LR+ = sens / (1 - spec)
LR- = (1 - sens) / spec
J = sens + spec - 1
F1 = 2*PPV*sens / (PPV + sens)
DOR = (TP*TN) / (FN*FP) = LR+ / LR-
Yerushalmy 1947; Youden 1950; Jaeschke-Sackett 1994 JAMA EBM; STARD 2015 BMJ

Comments (0)

No comments yet. Be the first!