Skip to the confounder shift demo

Medical AI lab · Confounder shift ·

Confounder shift: interactive demo

Confounder shift is when something linked to the disease in the study data, such as body mass index (BMI) in obstructive sleep apnea, is linked to it differently where the model is used. A model that folded the study’s BMI pattern into its score loses accuracy there, and can fall below a model that ignores BMI. In this demo a model that adds BMI to the evidence from an overnight oximetry recording scores an AUC of 0.83 in the study and 0.64 in a population where BMI no longer tracks apnea, while the recording alone scores 0.72 in both. Keeping BMI as a separate prior, and replacing it with the local one, brings the score back to 0.72.

In one line: Signal plus BMI scores AUC 0.83 in the study and 0.64 where BMI no longer tracks apnea; the signal evidence alone scores 0.72 in both, and a stated risk of 50% is really 34%.

SYNTHETIC DATA

These demos are illustrative. Every signal, image, patient and note is synthetic and fictional, generated and scored in your browser, and every number shown is computed from that synthetic data. They show general principles, not the performance of any real model, product or project, and none of them is a medical device.

Nothing is uploaded. No patient data is used.

15

Clinical model validation / confounder shift

BMI is a prior. Keep it out of the evidence.

What this shows: when the sleep apnea patients in a study are heavier than the healthy volunteers, a model can score well partly by reading body mass index (BMI). Where BMI is linked to apnea differently, that part of the score works against it. Keeping BMI as a separate prior, and replacing it with the local one, holds up.

Change the study and the new population

The signal evidence is what an overnight oximetry recording says about apnea. At the right end the new population has the same BMI link as the study. In the middle BMI says nothing about the disease, as when many people with apnea are lean. At the left end the link is reversed, an extreme case.

The same models, as the BMI link changes

closed-form model, 20% prevalence
AUC against the BMI link in the new populationAUC of five ways of scoring patients as the BMI link changes.

Grey dashed: BMI aloneWhite: signal evidence aloneRed: plain signal modelAmber: signal + BMI, study priorBlue: signal + BMI, local prior

Stated risk against actual risk at the selected link
Stated risk against actual riskCalibration of three models in the new population.
Each method where the model is used
AUC in the study—
AUC here, study prior—
AUC here, signal alone—
AUC here, local prior—

Synthetic data · illustrative · not a medical device

Where this matters

Any model developed on a case-control study, a referral clinic or a single site and then used in another population or at another site. Body weight is the confounder here; sex, device, site and referral route behave the same way. Ask how the model handles each one, and test it in a population where the link is different.

What this experiment models

Each patient has two numbers that are independent given the diagnosis: a BMI score and a signal score, both normally distributed. In the study the diseased group’s BMI score is higher by an amount that gives the chosen AUC for BMI alone. In the new population that difference is multiplied by the BMI link, from 100% to minus 100%. The signal score differs between diseased and healthy by the same amount everywhere. Every method is a weighted sum of the two scores: the signal evidence alone, a plain signal model that also carries the chosen share of the study’s BMI pattern, the signal evidence plus the study’s BMI prior, and the signal evidence plus the BMI prior of the new population. AUC and the actual risk behind each stated risk are computed exactly, with no random sampling. Prevalence is 20% in both populations. The local prior is assumed known; in practice it is estimated from local BMI and disease rates, which needs no recordings. No real study is reproduced and no number here comes from patient data.

The principle

How it works

A confounder is something that goes with the diagnosis in the data without being the disease. In obstructive sleep apnea, body weight is the usual one: in many studies the patients referred to a sleep clinic are heavier than the healthy volunteers. BMI then predicts the label well, and in this demo it reaches an AUC of 0.78 with no recording at all. That is real information in the study. It is information about who was referred and recruited, and it holds only where the same kind of people are tested.

There are two ways BMI gets into a model. It can be given as an input next to the recording. Or the recording itself can reveal it, because body weight leaves its own marks on breathing and oxygen levels overnight, and a plain signal model then learns the BMI pattern without being asked. Either way the score becomes a mix of evidence about the disease and a guess based on weight. Where the BMI link is the same as in the study the mix helps. Where the link is weaker, absent or reversed, the BMI part adds errors, and the stated risks are too high for heavier patients and too low for lean ones.

The remedy is to keep the two parts separate. The signal evidence is trained so that it carries no BMI pattern, for example by weighting or matching the study groups by BMI. BMI enters as a prior, a starting risk, and the signal evidence moves that risk up or down. The two are added on a log-odds scale. A prior can then be replaced with the one that fits the population in front of you, while the signal evidence stays as it is. See clinical model validation.

Worked example

A model built on heavy patients and lean volunteers

Picture a team that develops a model to detect obstructive sleep apnea from an overnight oximetry recording. The patients come from a sleep clinic and most of them are heavy. The healthy volunteers are staff and relatives and most of them are lean. The model is given the recording and the BMI, and it is tested on a held-out part of the same study.

The demo’s default settings reproduce that. BMI alone separates the study groups with an AUC of 0.78 and the signal evidence alone with 0.72. AUC in the study reads 0.83: adding BMI to the recording looks like a clear gain. A plain signal model that was never given the BMI, but picks up half of the BMI pattern from the recording, scores 0.82 in the study.

Now the model is used in a population where many people with apnea are lean, and BMI says nothing about who has it. That is the default position of the last slider. AUC here, study prior reads 0.64. AUC here, signal alone reads 0.72. The model that looked best in the study is now worse than the signal evidence it was built on, because it still raises the score of every heavy patient. The plain signal model scores 0.69. The calibration plot shows the cost in risk terms: patients told 50% have an actual risk of 34%.

Move the last slider fully left, to a population where the people with apnea are the leaner ones. That is an extreme case, shown to mark the limit. AUC here, study prior reads 0.40, which is below a coin flip, and a stated risk of 50% is really 11%. The signal evidence alone still reads 0.72. Move the slider fully right and every method returns to its study result.

The readout under the plots follows one heavy patient with a suspicious recording. BMI alone puts the risk at 41% in the study and 20% in the new population. The recording multiplies the odds by 1.9. The stated risk is 58% with the study prior and 32% with the local prior. Same patient, same recording, and the difference is only which population the starting risk came from.

The correct practice is to decide, for each confounder, whether it is allowed to inform the score, and to make that choice visible. Train the signal evidence on groups balanced for BMI. Report performance inside BMI bands as well as overall. Add BMI as a prior that can be replaced, and estimate that prior for each population of use from local BMI and disease rates.

Checklist

What to check in your own project

  • Do the diseased and healthy groups in the study differ in BMI, sex, site or device?
  • How well does the confounder alone predict the label, with no recording?
  • Is performance reported inside BMI bands, or only overall?
  • Was the signal model trained on groups balanced or weighted for the confounder?
  • Is the confounder a separate prior that can be replaced, or is it folded into one score?
  • Has the model been tested in a population where the link is different?

Related: our clinical model validation service, the wiki page on medical AI validation, and the demos on shortcut learning and calibration and decision thresholds.

FAQ

Common questions

What is confounder shift in clinical AI?

It is a change, between the study and the place of use, in how something like body weight is linked to the disease. A model that used the study’s link keeps applying it where it no longer holds. In this demo a sleep apnea model that adds BMI to an oximetry recording scores an AUC of 0.83 in the study and 0.64 in a population where BMI is unrelated to apnea.

Should BMI be an input to a sleep apnea model?

BMI can be used, but as a separate prior and not as one more input folded into a single score. The link between BMI and apnea in a study reflects who was referred and recruited. Kept separate, the prior can be replaced for a new population. In the demo that takes the AUC from 0.64 back to 0.72, the level of the signal evidence.

Why does my model do worse in a new population than in the case-control study?

One common reason is that the study groups differed in body weight or another confounder and the model learned that difference. Where the groups are alike, that part of the score no longer helps and adds errors. In the demo the result is an AUC of 0.64 against 0.72 for the signal evidence alone, and patients told 50% have an actual risk of 34%.

How do I stop a model from learning BMI instead of the disease?

Balance the training groups for BMI, by matching diseased and healthy patients on BMI or by weighting them so the BMI distributions agree. Then check the result inside BMI bands: a model that ranks patients well within each band is using something other than BMI. No method guarantees it, so test on a population with a different BMI link.

How is confounder shift different from shortcut learning?

A shortcut is a feature with no medical meaning, such as a hospital tag on the data, and the fix is to remove it. A confounder such as BMI carries real information about risk, so removing it throws something away. The fix is to keep it apart from the signal evidence and use the value that fits each population.

Medical AI lab

More demos

01 / Heart rate from ECGHeart rate from a noisy ECG – interactive demoMissed and false beats behind a correct average02 / Patient leakagePatient-level data leakage – interactive demoRecord-level vs patient-level train/test splits03 / Calibration & thresholdsCalibration and decision thresholds – interactive demoCalibration plot, decision curve and net benefit04 / Scanner shiftScanner shift in medical imaging – interactive demoSegmentation tuned on one scanner, tested on another05 / Dice vs clinical errorDice score vs clinical error – interactive demoDice, HD95 and lesions detected06 / Note de-identificationDe-identifying a clinical note – interactive demoEnglish, Hebrew and mixed notes vs a rule-based detector07 / Nodule volume 3DNodule volume and CT slice thickness – 3D interactive demoThe same nodule, measured on thin and thick slices08 / Sample sizeSample size for validating a clinical AI model – interactive demoHow wide the interval is around a measured sensitivity09 / SubgroupsHidden subgroup failure in clinical AI – interactive demoA good overall score next to a weak subgroup10 / Slice-by-slice 3DSlice-by-slice segmentation of a 3D lesion – 3D interactive demoA high per-slice Dice and a lesion reported in pieces11 / Predictive value 3DPositive predictive value and prevalence – 3D interactive demoWhat a positive result means when the condition is rare12 / Shortcut learningShortcut learning in medical imaging AI – interactive demoA model that reads the hospital tag, not the disease13 / DriftModel drift and performance monitoring – interactive demoHow late a monitoring rule notices a slow decline14 / Alert burdenAlert burden of a clinical early-warning model – interactive demoA threshold counted in alerts per nurse per shift

MLAIA DATA SCIENCE

Tell us what
you’re working on.

Share the problem, the data you have and what success would look like. We’ll discuss a practical next step.

Please don’t include confidential datasets, credentials or patient information.

yochai@mlaia.com
WhatsApp: +972 52 484 6282

Your inquiry is handled under our Privacy Policy.