Calculator Inputs
Formula Used
Raw specificity measures how many actual negatives are correctly predicted. The formula is:
For oversampled validation data, each count is corrected with an inverse sampling rate. This calculator uses:
Weighted FP = FP / FP Sampling Rate
Adjusted Specificity = Weighted TN / (Weighted TN + Weighted FP)
If true negatives and false positives share the same sampling rate, the adjusted specificity equals the raw specificity. This is expected because specificity is conditional on actual negatives.
How to Use This Calculator
- Enter true negatives and false positives from your validation confusion matrix.
- Add true positives and false negatives for extra diagnostic metrics.
- Enter the sampling rate used for true-negative and false-positive records.
- Choose the confidence level and output precision.
- Press the calculate button to view adjusted specificity above the form.
- Use the CSV or PDF buttons to download the result report.
Example Data Table
| Scenario | TN | FP | TN Rate | FP Rate | Interpretation |
|---|---|---|---|---|---|
| Equal control sampling | 940 | 60 | 25% | 25% | Adjusted specificity remains the same. |
| FP records sampled more often | 940 | 60 | 20% | 60% | Adjusted specificity usually increases. |
| TN records sampled more often | 940 | 60 | 60% | 20% | Adjusted specificity usually decreases. |
Understanding Oversampling Adjusted Specificity
Why Adjustment Matters
Oversampling is common in model development. It helps analysts study rare outcomes. It also makes training and validation sets easier to inspect. Yet oversampling can distort performance summaries when the sampled data no longer represents the review population. Specificity is the share of actual negatives that a model labels as negative. It is often used in fraud checks, medical screening, quality control, credit review, and risk scoring.
What The Calculator Corrects
This tool corrects specificity by applying inverse sampling weights to true negatives and false positives. The weighted counts estimate how many records each sampled group represents in the target population. The adjusted rate is then computed from those corrected counts. This approach is useful when different negative subgroups were sampled at different rates. It is also useful when a validation file was enriched with hard negatives or borderline cases.
Important Statistical Note
Specificity is conditional on actual negative cases. If oversampling only changes the share of positive and negative outcomes, and all actual negatives are sampled uniformly, specificity may not change. In that situation, prevalence correction affects measures like precision, negative predictive value, and accuracy more strongly. This calculator still reports the raw value, the adjusted value, confidence intervals, and false positive rates for comparison.
Using Results In Reports
Use the adjusted value when the sampling rates are known and unequal. Keep the raw value beside it for audit clarity. Always document the sampling design, threshold, and validation period. If the sampling design is complex, confirm the weighting plan with a statistician. For SAS workflows, the generated code block can be copied into a validation program and adapted to your dataset variables.
Frequently Asked Questions
1. What is specificity?
Specificity is the percentage of actual negative cases correctly predicted as negative. It equals true negatives divided by true negatives plus false positives.
2. Why adjust specificity for oversampling?
Adjustment is useful when negative records were sampled at unequal rates. Weighting helps estimate the specificity expected in the target review population.
3. Does outcome oversampling always change specificity?
No. If all actual negative cases share one sampling rate, the rate cancels out. Raw and adjusted specificity will be identical.
4. What sampling rate should I enter?
Enter the inclusion percentage for each group. For example, enter 25 if one quarter of that group was included in validation.
5. What are weighted true negatives?
Weighted true negatives estimate represented true negatives in the population. The calculator divides observed true negatives by their sampling rate.
6. What confidence interval is used?
The calculator uses a Wilson-style interval. For adjusted specificity, it uses an approximate effective sample size based on the weights.
7. Can I use this for model validation?
Yes. It is helpful for validation reports, threshold reviews, and oversampled test files. Document your sampling plan with the result.
8. Why include TP and FN fields?
They are not needed for specificity. They support extra outputs like sensitivity, balanced accuracy, sample prevalence, and raw accuracy.