{
  "id": "sensitivity-specificity",
  "version": "435826dff29b",
  "status": "published",
  "name": "Sensitivity and Specificity Calculator",
  "question": "A test’s sensitivity and specificity",
  "summary": "Computes a test’s sensitivity, specificity, positive and negative predictive values, accuracy and likelihood ratios from true and false positives and negatives.",
  "category": "statistics",
  "subcategory": "tests",
  "url": "https://www.acalculator.org/statistics/sensitivity-specificity-calculator",
  "markdown": "https://www.acalculator.org/statistics/sensitivity-specificity-calculator.md",
  "kind": "function",
  "method": "Sensitivity = TP ÷ (TP + FN); specificity = TN ÷ (TN + FP); PPV = TP ÷ (TP + FP); NPV = TN ÷ (TN + FN); LR+ = sensitivity ÷ (1 − specificity); LR− = (1 − sensitivity) ÷ specificity; at prevalence p, PPV = sens × p ÷ [sens × p + (1 − spec)(1 − p)].",
  "assumptions": [
    "The reference standard decides who has the condition; the counts come from one group of people tested.",
    "Values that would divide by zero are not shown (for example LR+ when there are no false positives)."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "tp": {
        "title": "True positives",
        "description": "People with the condition whose test is positive.",
        "type": "integer",
        "minimum": 0,
        "maximum": 1000000000000
      },
      "fp": {
        "title": "False positives",
        "description": "People without the condition whose test is positive.",
        "type": "integer",
        "minimum": 0,
        "maximum": 1000000000000
      },
      "fn": {
        "title": "False negatives",
        "description": "People with the condition whose test is negative.",
        "type": "integer",
        "minimum": 0,
        "maximum": 1000000000000
      },
      "tn": {
        "title": "True negatives",
        "description": "People without the condition whose test is negative.",
        "type": "integer",
        "minimum": 0,
        "maximum": 1000000000000
      },
      "prev": {
        "title": "Prevalence in your population",
        "description": "Optional: the share of people with the condition where the test will be used, to rework the predictive values.",
        "type": "number",
        "x-unit": "percent",
        "exclusiveMinimum": 0,
        "exclusiveMaximum": 100
      }
    }
  },
  "outputs": {
    "sensitivity": {
      "label": "Sensitivity",
      "description": "True positives ÷ everyone with the condition: the share the test finds.",
      "format": "percent"
    },
    "specificity": {
      "label": "Specificity",
      "description": "True negatives ÷ everyone without the condition: the share the test clears.",
      "format": "percent"
    },
    "ppv": {
      "label": "Positive predictive value",
      "description": "True positives ÷ all positive tests.",
      "format": "percent"
    },
    "npv": {
      "label": "Negative predictive value",
      "description": "True negatives ÷ all negative tests.",
      "format": "percent"
    },
    "accuracy": {
      "label": "Accuracy",
      "description": "True positives and true negatives ÷ everyone tested.",
      "format": "percent"
    },
    "prevalenceTable": {
      "label": "Prevalence in the table",
      "description": "Everyone with the condition ÷ everyone tested.",
      "format": "percent"
    },
    "lrPositive": {
      "label": "Positive likelihood ratio",
      "description": "Sensitivity ÷ (1 − specificity).",
      "format": "number"
    },
    "lrNegative": {
      "label": "Negative likelihood ratio",
      "description": "(1 − sensitivity) ÷ specificity.",
      "format": "number"
    },
    "ppvAt": {
      "label": "Positive predictive value at your prevalence",
      "description": "The PPV worked from the typed prevalence.",
      "format": "percent"
    },
    "npvAt": {
      "label": "Negative predictive value at your prevalence",
      "description": "The NPV worked from the typed prevalence.",
      "format": "percent"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "tp": 231,
      "fp": 32,
      "fn": 27,
      "tn": 54
    },
    "outputs": {
      "sensitivity": 89.53488372093024,
      "specificity": 62.7906976744186,
      "ppv": 87.83269961977186,
      "npv": 66.66666666666667,
      "accuracy": 82.84883720930233,
      "prevalenceTable": 75,
      "lrPositive": 2.40625,
      "lrNegative": 0.16666666666666666
    },
    "text": "Sensitivity is 89.53% and specificity is 62.79%."
  },
  "examples": [
    {
      "given": {
        "tp": 231,
        "fp": 32,
        "fn": 27,
        "tn": 54
      },
      "expect": {
        "sensitivity": 89.53488372093024,
        "specificity": 62.7906976744186,
        "ppv": 87.83269961977186,
        "npv": 66.66666666666667,
        "accuracy": 82.84883720930233,
        "prevalenceTable": 75
      },
      "source": "Altman DG, Bland JM. Diagnostic tests 1: sensitivity and specificity. BMJ 1994;308:1552 (231/258 = 0.90 and 54/86 = 0.63); predictive values 231/263 and 54/81 by hand in content.mdx; Python 3 cross-check in docs/progress/WP-126/xcheck.py; https://www.bmj.com/content/308/6943/1552"
    },
    {
      "given": {
        "tp": 42,
        "fp": 2,
        "fn": 106,
        "tn": 142,
        "prev": 10
      },
      "expect": {
        "sensitivity": 28.37837837837838,
        "specificity": 98.61111111111111,
        "lrPositive": 20.43243243243243,
        "lrNegative": 0.7263037685572896,
        "ppvAt": 69.42148760330579
      },
      "source": "Deeks JJ, Altman DG. Diagnostic tests 4: likelihood ratios. BMJ 2004;329:168 (LR+ (42/148)/(2/144) = 20.4, LR− 0.73, post-test probability about 0.69 from a pre-test probability of 0.1); https://pmc.ncbi.nlm.nih.gov/articles/PMC478236/",
      "tolerance": 1e-12
    },
    {
      "given": {
        "tp": 90,
        "fp": 0,
        "fn": 10,
        "tn": 100
      },
      "expect": {
        "sensitivity": 90,
        "specificity": 100,
        "ppv": 100,
        "npv": 90.9090909090909,
        "lrNegative": 0.1
      },
      "source": "hand calculation in content.mdx: 90 ÷ 100, 100 ÷ 100, 100 ÷ 110, (1 − 0.9) ÷ 1; https://www.bmj.com/content/308/6943/1552"
    }
  ],
  "sources": [
    "Altman DG, Bland JM. Statistics Notes: Diagnostic tests 1: sensitivity and specificity. BMJ 1994;308:1552, retrieved 2026-10-18. https://www.bmj.com/content/308/6943/1552 (index: https://pmc.ncbi.nlm.nih.gov/articles/PMC2540489/)",
    "Altman DG, Bland JM. Statistics Notes: Diagnostic tests 2: predictive values. BMJ 1994;309:102, retrieved 2026-10-18. https://www.bmj.com/content/309/6947/102.1",
    "Deeks JJ, Altman DG. Statistics Notes: Diagnostic tests 4: likelihood ratios. BMJ 2004;329:168-169, retrieved 2026-10-18. https://pmc.ncbi.nlm.nih.gov/articles/PMC478236/",
    "Centers for Disease Control and Prevention. Guidelines for Evaluating Surveillance Systems. MMWR 1988;37(S-5) (sensitivity A/(A+C), predictive value positive A/(A+B)), retrieved 2026-10-18. https://www.cdc.gov/mmwr/preview/mmwrhtml/00001769.htm"
  ],
  "related": [
    "odds-ratio",
    "nnt",
    "incidence-rate",
    "probability"
  ],
  "changelog": []
}
