Sensitivity and Specificity: Calculate Both
- Specificity
- %
- Result
- Total cases
- cases
- Result
- True positives
- 80
- You entered
Calculate sensitivity by dividing true positives by all actual positives, and calculate specificity by dividing true negatives by all actual negatives. Enter the four counts from a confusion matrix to get both percentages, along with the total number of cases.
Formula
Sensitivity = TP ÷ (TP + FN) × 100. Specificity = TN ÷ (TN + FP) × 100.
- TP (true positives): cases that have the condition and receive a positive test result; count, with no physical unit.
- FN (false negatives): cases that have the condition but receive a negative result; count.
- TN (true negatives): cases without the condition that receive a negative result; count.
- FP (false positives): cases without the condition that receive a positive result; count.
The calculator reports sensitivity and specificity as percentages. Its inputs are counts, so they must be zero or greater. The denominator for sensitivity is TP + FN, the total number of actual positive cases. The denominator for specificity is TN + FP, the total number of actual negative cases. If either denominator is zero, that metric cannot be calculated from the available data.
Worked Example
Using the calculator’s default values, the test correctly identifies 80 positive cases, misses 20 positive cases, correctly identifies 90 negative cases, and incorrectly labels 10 negative cases as positive.
- Sensitivity = 100 × 80 ÷ (80 + 20) = 100 × 80 ÷ 100 = 80.00%.
- Specificity = 100 × 90 ÷ (90 + 10) = 100 × 90 ÷ 100 = 90.00%.
- Total cases = 80 + 20 + 90 + 10 = 200.
In this example, the test returns a positive result for 80% of the cases that are actually positive, and a negative result for 90% of those actually negative. The percentages describe different groups; they do not mean that 80% or 90% of all test results are correct.
How to Build the Confusion Matrix
Before calculating either measure, compare the test’s results with a reference classification, sometimes called the reference standard. Arrange cases by what is actually true and what the test predicted:
- Actual positive, test positive: TP.
- Actual positive, test negative: FN.
- Actual negative, test negative: TN.
- Actual negative, test positive: FP.
The labels “positive” and “negative” refer to the classification being tested, not necessarily to whether a result is desirable. In a non-medical example, a spam filter can treat spam as the positive class: spam correctly flagged is a true positive, while legitimate email incorrectly flagged is a false positive. Define the positive class before counting to avoid swapping categories.
When to Use Each Measure
Sensitivity answers: “Among all cases that are actually positive, what fraction did the test detect?” It is also called the true positive rate or recall. A highly sensitive test has relatively few false negatives within the actual-positive group.
Specificity answers: “Among all cases that are actually negative, what fraction did the test correctly clear?” It is also called the true negative rate. A highly specific test has relatively few false positives within the actual-negative group.
These measures are useful for describing a classifier or diagnostic test against a chosen reference. Which matters more depends on the task and the consequences of each kind of error. Sensitivity and specificity alone do not tell you whether a positive result is likely to be correct in the population being tested. For that, readers often also examine positive predictive value and negative predictive value, which depend on how common the positive condition is in the tested population.
Common Calculation Mistakes and Limits
- Using the wrong denominator: Sensitivity uses actual positives (TP + FN), not all positive test results. Specificity uses actual negatives (TN + FP), not all negative test results.
- Swapping false positives and false negatives: A false positive is actually negative but tested positive; a false negative is actually positive but tested negative.
- Confusing sensitivity with accuracy: Accuracy is (TP + TN) ÷ (TP + FN + TN + FP). It measures the fraction of all cases classified correctly and is not interchangeable with either measure.
- Rounding too soon: Keep the original counts and round only the final percentage. Small samples can make a percentage change substantially when just one case changes.
- Ignoring the reference standard or sample: Counts are only as meaningful as the classification used to define “actual” status and the cases included. Performance may differ across settings or groups.
Sensitivity and specificity are proportions of defined groups, so they have no physical units; the calculator displays them as percentages. They do not, by themselves, describe overall usefulness, predictive value, or the practical impact of errors. The measures also assume each case is counted once and that the four categories are consistently defined.
Frequently Asked Questions
What is the formula for sensitivity?
Sensitivity = TP ÷ (TP + FN) × 100. Divide true positives by all actual positives, then multiply by 100 to express the result as a percentage.
What is the formula for specificity?
Specificity = TN ÷ (TN + FP) × 100. Divide true negatives by all actual negatives, then multiply by 100.
Can sensitivity or specificity be greater than 100%?
No. With valid nonnegative counts and a nonzero denominator, each is between 0% and 100%, inclusive. A result outside that range usually signals a counting or formula error.
What if there are no actual positive cases?
Sensitivity is undefined because TP + FN equals zero. Likewise, specificity is undefined if there are no actual negative cases. Do not treat an undefined value as 0%.
Are sensitivity and specificity the same as accuracy?
No. Sensitivity and specificity evaluate performance separately among actual positives and actual negatives. Accuracy combines correct classifications across all cases and can be misleading when the groups are very uneven in size.
Related
Formula used
in tp | True positives | - | 80 | 0 in fn | False negatives | - | 20 | 0 in tn | True negatives | - | 90 | 0 in fp | False positives | - | 10 | 0 out sensitivity | Sensitivity | % | 100 * tp / (tp + fn) | 2 out specificity | Specificity | % | 100 * tn / (tn + fp) | 2 out total | Total cases | cases | tp + fn + tn + fp | 0
Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.