Contents/ Part XXX · Capstone Projects: Regression/ Chapter 188

Logistic Regression for Decisions: Clinical Risk Scoring

Capstone 27. Two models with the same AUC to four decimal places. One says four percent of these patients are in danger and the other says nine. A score that sends people home has to be right about the level, and AUC cannot see the level at all.

⏱️ ~21 min read
🎯 Risk prediction
📊 Chapter 188

A logistic regression that ranks patients well is not the same thing as one that can be trusted to set a threshold. This chapter is about the gap between those two claims, and about the metric that cannot tell them apart.

The brief
Setting
An emergency department: 8,938 presentations with chest pain, each with age, sex, vital signs, troponin, comorbidities and ECG findings, and whether a major cardiac event followed within 30 days.
The question
Which patients can safely be discharged, and which should be admitted for observation?
Why it matters
The score is not a research output. It is a rule that sends people home, so it has to be right about how much risk a patient carries and not merely about which patient carries more.
What we do
Fit the model on a training set and evaluate only on held-out data, report AUC because everyone asks for it, then build a second model with the same AUC and half the accuracy about risk, measure calibration properly, derive the threshold from a stated cost ratio rather than from the data, and check the whole thing with decision curve analysis.
Discrimination asks whether the model puts patients in the right order. Calibration asks whether the numbers it attaches to them are right. A threshold rule reads the numbers, so a model can discriminate perfectly and still be unusable for the decision it was built for.
The finding, up front

Two models, AUC 0.8097 both, identical to four decimals. One predicts a mean risk of 3.93 percent against an observed 3.93 percent. The other predicts 8.64 percent. At the clinicians' own threshold the second admits 951 more patients to catch 18 more events, which is 53 admissions each against a stated tolerance of 40.

1

The Decision the Score Is For

A patient scoring above the threshold is admitted for observation. Below it they go home with advice. Everything about how this model should be built and judged follows from that sentence, and almost none of it follows from the usual machine-learning defaults.

The defaultWhy it fails here
Report accuracyThe event rate is 3.9 percent. Sending everybody home scores 96.1 percent
Report AUCAnswers a question about ranking. The decision needs the level
Pick the threshold from the ROC curveYouden's index encodes a cost ratio of 1:1, silently, and nobody agreed to that
Drop rows with missing predictorsA troponin assay that was not ordered is informative about how the patient presented
Evaluate on the training setA variable with no real effect improves training performance every single time

After removing a duplicated extract, 35 blood pressures of zero from a cuff fault and 28 heart rates of 999 from a monitor sentinel, 8,938 presentations remain. The 138 patients with no troponin result are kept, with an indicator, because dropping them would quietly restrict the score to patients somebody already thought were worth testing.

2

Two Models, One AUC

Fit the model on 5,809 patients and hold back 3,129. Then build a second model that ranks every patient in exactly the same order and is wrong about the level, by adding a constant to the log-odds. That operation cannot change any patient's position in the queue.

ModelAUCBrierMean predicted riskObserved
A, calibrated0.80970.034483.93%3.93%
B, same ranking, inflated0.80970.039448.64%3.93%

The AUCs are identical to four decimal places, and they should be. AUC asks exactly one question: given a patient who had an event and one who did not, how often does the model score the first one higher? That is a question about order. Model B is wrong about the level by more than a factor of two, and the metric quoted in every paper and every model card cannot detect it.

The Brier score does notice, because it scores the probabilities rather than the ranking. It does not say where the problem is, which is what the next section is for.

Left: two ROC curves, one drawn solid and one dashed, lying exactly on top of each other, both labeled AUC 0.8097. Right: a calibration plot of observed against predicted risk by decile. Model A's points follow the diagonal closely from 0 to 18 percent; model B's points lie far below it, reaching only about 14 percent observed at 30 percent predicted.
Left: the two ROC curves are the same curve, drawn solid and dashed so both are visible. Any evaluation stopping at discrimination has no way to prefer one of these models. Right: the calibration plot, where model B sits below the diagonal at every decile.
3

Calibration, Measured Rather Than Eyeballed

Regressing the outcome on the predicted log-odds gives two numbers. The slope says whether the spread of predicted risks is right. The intercept says whether the level is.

A, intercept
−0.053
ideal 0
A, slope
0.980
ideal 1
B, intercept
−0.983
the level is wrong
B, slope
0.980
identical to A

Both models have a slope of 0.98, and that is the point. Model B inherited model A's spread exactly, so the slope cannot distinguish them either. Only the intercept notices. A model card reporting AUC and calibration slope, which is a common pairing, would pass model B without comment.

Model A's decile table is what a well-calibrated score looks like: 0.88 percent predicted against 0.96 observed, 3.08 against 4.15, 7.01 against 7.03, 17.99 against 16.93. The numbers mean what they say.

4

The Threshold Comes From Costs

A threshold is a statement about how much worse one error is than the other, and that ratio belongs to the clinicians. Here they judge a missed event 40 times worse than an unnecessary night of observation, which fixes the threshold at 1/(1+40) = 2.4 percent. The arithmetic is one line; the judgment behind it is not a statistical question at all.

At a 2.4% thresholdAdmittedEvents caughtEvents missedAdmit rate
Model A, calibrated1,3051051841.7%
Model B, inflated2,256123072.1%

Model B misses nothing, and that is not the good news it appears to be. It buys those eighteen events at 951 extra admissions, or 53 each. The clinicians said 40. A miscalibrated model does not become more cautious; it silently applies a different threshold than the one the clinical team chose, and nobody in the room knows the trade-off has been changed.

What calibration error actually looks like in practice

It does not look like error. It does not produce worse rankings, worse AUC, or a model that obviously fails. It produces a rule that quietly implements a different decision from the one it was asked to implement, while every metric on the dashboard stays green. That is why calibration belongs next to discrimination in every report, and not in an appendix.

5

Decision Curve Analysis

The threshold above rests on one cost ratio, and reasonable clinicians will disagree about it. Net benefit evaluates across the whole range, putting true and false positives on one scale using the threshold itself as the exchange rate, and comparing any rule against the two strategies it must beat: admit everyone, and admit nobody.

ThresholdModel AModel BAdmit everyoneAdmit nobody
1.0%0.03190.03050.02960
2.4% (chosen)0.02400.02230.01530
4.0%0.01740.0148−0.00070
10.0%0.00690.0003−0.06740
15.0%0.0053−0.0037−0.13020

Model A is better at every threshold anybody would choose, and the gap widens as the threshold rises. Two other things are worth reading off this table. Admitting everyone becomes worse than doing nothing above about a 4 percent threshold. And model B goes negative at 15 percent, meaning that at that cost ratio a clinician would do better ignoring it entirely.

Left: net benefit against threshold risk from 0.5 to 20 percent. Model A's curve is highest throughout, model B's is below it and crosses zero near 15 percent, the admit-everyone line falls steeply and crosses zero near 4 percent, and a vertical line marks the clinicians' 2.4 percent threshold. Right: grouped bars on a log scale comparing the two models at that threshold, showing 1,305 versus 2,256 admitted, 105 versus 123 events caught, and 18 versus 0 events missed.
Left: net benefit across every threshold a clinician might hold. A score earns its place by beating both trivial strategies across the range of costs people actually hold. Right: the same threshold applied to both models.
6

The Decoy, and Why Held-Out Data Is Not Optional

The dataset carries a variable with no effect whatsoever: the month the patient arrived. Adding it to the model is a test of the evaluation rather than of the model.

AUC without it
0.8097
held-out
AUC with it
0.8091
very slightly worse
Its coefficient
+0.046
the truth is 0
On training data
Always helps
by construction

On held-out data a useless variable contributes nothing, and here it costs a little. On the training set it would have looked like a small improvement, every time, because a model with one more free parameter always fits the data it was fitted to slightly better. That is the whole argument for a test set, and it is why C3 of the analysis plan was written before anything was fitted.

7

What to Watch

8

Calibration in Data Science & AI

Where it appearsThe same failure, in a different costume
Gradient boosting and random forestsBoth are systematically miscalibrated out of the box, and both report excellent AUC while doing it
Any model trained with class weights or resamplingRebalancing fixes the ranking and destroys the level, which is fine until somebody reads the probability
Credit scoring and pricingThe predicted probability is multiplied by an amount of money, so a calibration error becomes a pricing error directly
Neural network confidenceModern deep networks are famously overconfident, which is why temperature scaling exists
Language model probabilitiesA stated confidence that does not match the observed rate of being right is the same defect, in a setting where it is much harder to measure
Where the research went

The Brier score dates from 1950 and weather forecasting, which is the field that took calibration seriously first and for the obvious reason: a forecast of rain is consumed as a number. Cox's 1958 calibration regression is the slope-and-intercept decomposition used here. Vickers and Elkin introduced decision curve analysis in 2006 precisely because discrimination metrics could not answer whether a model was worth using. On the repair side, Platt scaling and isotonic regression recalibrate an existing model's outputs, and temperature scaling is the one-parameter version now standard for neural networks. All three fix the level while leaving the ranking, and therefore the AUC, exactly where it was.

🐍

The full project, step by step

The companion notebook reads the plan before fitting anything, cleans the extract and keeps the patients with no troponin result, holds out 3,129 presentations, constructs the second model with identical ordering, measures calibration by slope and intercept and by decile, shows what accuracy would have said, derives the threshold from a stated cost ratio, computes net benefit across the range clinicians disagree over, and finishes with a decoy variable that earns nothing on held-out data.

📓 View Notebook (code & outputs) ▶ Open in Colab ⬇ View / Download on GitHub
Read the reports & get the data

The dataset (capstone-clinical-risk-scoring.xlsx) holds 9,060 emergency presentations with a duplicated extract, cuff faults, monitor sentinels and missing assays left in, a decoy variable that predicts nothing, the analysis plan agreed with the clinical lead before modeling, and the generating coefficients. Two written reports accompany it: a plain-language brief for the clinical lead, and a technical report covering discrimination, calibration and net benefit.

🎓 Key Takeaways

  • AUC reads order, decisions read level. Two models with AUC 0.8097 differed by a factor of two in predicted risk.
  • The calibration slope missed it too. Both scored 0.980; only the intercept, −0.983 against 0, caught the fault.
  • Thresholds come from costs. A 40:1 cost ratio fixes the threshold at 2.4 percent, and no statistical criterion can supply that ratio.
  • Miscalibration looks like caution. Model B missed zero events by admitting 951 extra patients, 53 per event against a stated tolerance of 40.
  • Accuracy is meaningless at a 3.9 percent event rate. Sending everybody home scores 96.1 percent.

Quiz: Test Yourself