01 / 21

Assessing
Model Fit

Learn how to evaluate whether a classification model is actually good at its job: from confusion matrices to the ROC curve.

Biostatistics

What is Classification?

In biostatistics, we often build models that predict a categorical outcome: Does a patient have a disease or not? Will a treatment succeed or fail? These are classification problems.

Positive (+)
The model predicts the condition is present (e.g., "disease detected")
Negative (−)
The model predicts the condition is absent (e.g., "no disease")

Why Accuracy Alone Fails

Suppose 95 out of 100 patients are healthy. A model that always says "healthy" achieves 95% accuracy yet misses every sick patient. This is the accuracy paradox.

95 Healthy Model says: "Healthy" ✓ Correctly classified 5 Sick Model says: "Healthy" ✗ All 5 missed!

The Confusion Matrix

A confusion matrix cross-tabulates predicted labels against actual labels, giving us four critical counts:

ACTUAL CONDITION Positive Negative PREDICTED Pos Neg TP True Positive Correctly detected FP False Positive False alarm FN False Negative Missed case TN True Negative Correctly ruled out Diagonal = correct predictions | Off-diagonal = errors

Sensitivity & Specificity

Sensitivity (Recall)
Of all actually positive cases, how many did the model catch?

\(\text{Sensitivity} = \dfrac{TP}{TP + FN}\)
Specificity
Of all actually negative cases, how many did the model correctly rule out?

\(\text{Specificity} = \dfrac{TN}{TN + FP}\)

The Sensitivity-Specificity Trade-Off

Classification models output a probability score. We choose a threshold \(t\): if the score \(\geq t\), predict positive. Changing \(t\) shifts the balance:

Threshold (t) Rate 0 1 0 1 Sens Spec Optimal t

Introducing the ROC Curve

The Receiver Operating Characteristic (ROC) curve plots Sensitivity (True Positive Rate) on the y-axis versus \(1 - \text{Specificity}\) (False Positive Rate) on the x-axis, across every possible threshold.

False Positive Rate (\(1 - \text{Specificity}\))
True Positive Rate (Sensitivity) 0 0.5 1.0 0 0.5 1.0 Random (AUC = 0.5) AUC = 0.92 Perfect

Understanding AUC

The Area Under the ROC Curve (AUC) summarizes overall model performance in a single number between 0 and 1.

1
\(\text{AUC} = 1.0\): Perfect classification: no errors at any threshold.
2
\(\text{AUC} = 0.5\): No better than random guessing: the diagonal line.
3
\(\text{AUC} < 0.5\): Worse than random: flip the predictions!

Sensitivity vs Specificity: When to Prioritize

Prioritize Sensitivity Prioritize Specificity
Goal Catch every positive case Avoid false alarms
Cost of error Missing disease is dangerous Unnecessary treatment is costly
Example Cancer screening Confirmatory biopsy
Threshold Lower \(t\) Higher \(t\)
Trade-off More false positives More false negatives

How to Assess Model Fit

1
Build the confusion matrix. Classify predictions as TP, FP, FN, TN using a chosen threshold.
2
Calculate key metrics. Compute sensitivity, specificity, and accuracy from the confusion matrix cells.
3
Plot the ROC curve. Vary the threshold from 0 to 1, recording (FPR, TPR) at each step.
4
Compute AUC. Integrate under the ROC curve: closer to 1 = better discrimination.
5
Choose the optimal threshold. Balance sensitivity and specificity for your clinical context.

Example 1: Disease Screening

A blood test for diabetes is applied to 200 patients. Results:

ACTUAL Diabetic Healthy Pos Neg PREDICTED TP = 36 FP = 12 FN = 4 TN = 148 Total = 200

Example 2: Comparing Two Models

Two models predict heart disease. Which is better? Accuracy alone gives the same answer, but ROC tells a different story.

False Positive Rate True Positive Rate 0 0.5 1.0 1.0 0.5 Model A: AUC = 0.92 Model B: AUC = 0.72

Example 3: Choosing a Threshold

A cancer screening model with AUC = 0.95 offers different trade-offs at different thresholds:

Threshold \(t\) Sensitivity Specificity Clinical Impact
\(t = 0.3\) 0.97 0.70 Catch nearly all cancers, many false alarms
\(t = 0.5\) 0.88 0.90 Balanced performance
\(t = 0.7\) 0.72 0.96 Fewer false alarms, miss some cancers

PPV & NPV: The Patient's Perspective

Sensitivity and specificity describe the test's performance. But patients ask: "Given my result, what are the chances I actually have it?"

Positive Predictive Value
If the test says positive, how likely is it truly positive?

\(\text{PPV} = \dfrac{TP}{TP + FP}\)
Negative Predictive Value
If the test says negative, how likely is it truly negative?

\(\text{NPV} = \dfrac{TN}{TN + FN}\)

Common Mistakes

✗ Relying on Accuracy Alone
With imbalanced classes, a model can have high accuracy while missing most positive cases. Always check sensitivity.
✗ Ignoring the Threshold
AUC summarizes all thresholds, but clinical decisions require picking one. Don't skip this step.
✗ Confusing Sensitivity with PPV
Sensitivity = "Of those with disease, how many test positive?" PPV = "Of those who test positive, how many have disease?" These are different questions.

Summary of Key Metrics

Metric Formula Answers
Sensitivity \(\frac{TP}{TP+FN}\) How well does it detect positives?
Specificity \(\frac{TN}{TN+FP}\) How well does it rule out negatives?
PPV \(\frac{TP}{TP+FP}\) Is a positive result trustworthy?
NPV \(\frac{TN}{TN+FN}\) Is a negative result trustworthy?
AUC Area under ROC How well does the model discriminate overall?

Question 1 of 5

A confusion matrix shows: \(TP = 80, FP = 20, FN = 10, TN = 90\). What is the sensitivity of this model?

Question 2 of 5

A model that always predicts "negative" for a disease with 2% prevalence will have:

Question 3 of 5

On an ROC curve, the ideal model would have its curve pass through which point?

Question 4 of 5

For a cancer screening test, which threshold strategy is most appropriate?

Question 5 of 5

Model X has AUC = 0.85 and Model Y has AUC = 0.65. Which statement is most accurate?