A model predicts who will get diabetes in the next few years. Spotting it early isn't the goal. Preventing it is.
A model predicts how long a cancer patient will live. Past patients may have lived long only because they were treated.
People react differently to the same treatment, and past data follows today's rules.
To do better, you have to ask a different question.
A trial would mean forcing people to smoke or quit. Not possible, not ethical. So we use real-world data, where people chose for themselves.
Comparing cancer rates of smokers vs. non-smokers mixes both paths.
Some methods try to work out from data which way cause runs. With just two variables, the data fits both directions. Here we assume we already know.
Cities with more police have more crime. Do police bring crime, or does crime bring police? The numbers alone fit both.
Treatment never changes patient info.
Next week's topic is called dynamic treatment regimes, also known as off-policy reinforcement learning.
These fields often can't run experiments. Two examples:
Intro ML and CS courses skip these questions, which leaves a major hole.
Old methods break with this much data. Today: one way to turn a causal question into an ML problem.
Called potential outcomes, from the Rubin-Neyman causal model. Also called the red pill (Y0) and the blue pill (Y1). Books write these in different notations, but they mean the same thing.
Both use expected results, because the same pill can work or fail by luck.
| Y0 | Y1 | |
|---|---|---|
| Not treated | seen | ? |
| Treated | ? | seen |
Called the fundamental problem of causal inference. Each person gets one treatment, so you only ever see one of their two results. The other, the counterfactual, is never in the data and has to be guessed. Comparing people who got different treatments only works if they are alike, and the skew in who gets what usually means they aren't. Causal methods are ways to make that guess well.
Each arrow is the per-person effect (CATE) at that age. Big for the young and old, tiny for the middle-aged. If treatment were much cheaper, it could still make sense for the middle-aged.
Average each curve over everyone and take the gap: the average effect (ATE). A blanket rule like "all men over 50 get yearly screening" applies to everyone, so the ATE is the number that judges it: how much it changes outcomes across the whole group.
No curves, just scattered people. Control went mostly to the young, treatment mostly to the old, because of access, money or guidelines. That skew is the patient info → treatment arrow. Dots sit off the curves because of luck.
Question: is drug B better than A? Eight people each got one drug. Lower sugar is better. Each row has one seen result, and the other is never seen. The exercise answers the question two ways and compares them.
| Age | Sex | Exercises | Got | On A (Y0) | On B (Y1) |
|---|---|---|---|---|---|
| 45 | F | no | A | 6 | ? |
| 45 | F | yes | B | ? | 6.5 |
| 55 | M | no | A | 7 | ? |
| 55 | M | yes | B | ? | 8 |
| 65 | F | no | B | ? | 8 |
| 65 | F | yes | A | 7.5 | ? |
| 75 | M | no | B | ? | 9 |
| 75 | M | yes | A | 8 | ? |
The never-seen values are made up for teaching, as if "a magical creature" revealed them. In real data you never have them.
Average the seen sugar of people who got B, and of people who got A.
Average both full columns, using the never-seen values too.
An insurer pays for drug B only if it lowers sugar across all its members, which is the true average effect. The naive gap points the other way.
In real data the hidden values are missing, and who got what is skewed. In general this can't be solved. It takes strong assumptions. The first is SUTVA.
A confounder is anything that affects both which treatment a person got and how they do. This assumption says every confounder is in the data. Then, among people with the same patient info, who got which treatment is as good as random. Also called ignorability. Example: X is age, gender, weight, diet and resting heart rate. T is blood pressure medication A or B. Y0 and Y1 are blood pressure after A and after B.
A patient with high blood pressure and two medication options, A and B. The doctor gives B.
| Y0: blood pressure after A | stays high |
| Y1: blood pressure after B | drops |
| T: doctor gave | B |
| Y: what you see | drops |
The drug's effect is the gap between Y0 and Y1. The doctor's choice can't change those two what-ifs. It only picks which one comes true, so T → Y, but not T → Y0 or Y1.
A factor h that is not in the data, here being diabetic, breaks the assumption only if it affects both the treatment choice and the results.
You can't tell from the data. Ask domain experts, like a doctor who treats high blood pressure: what drives your treatment decisions? Then check those factors are in the data. Expect some back and forth.
Sensitivity analysis asks how much the conclusion would change if a hidden confounder of a given strength existed.
Every kind of patient must have some chance of getting each treatment. If nobody ever got B, there is no way to know what B would do. Violations invalidate every conclusion from the data.
That chance is the propensity score: for one kind of patient, the share who got treatment 1. It must never be 0 (nobody like them got it) or 1 (everybody like them got it).
Overlap needs some randomness in who gets what. If strict guidelines always gave the same patient the same drug, overlap would fail. Two common sources of randomness:
In the sugar table from 31:00, every patient type got only one drug. The 75-year-old man who exercises got A, and nobody with that profile got B, so overlap fails.
| Got A | Got B | |
|---|---|---|
| 45, F, exercises: no | ✓ | – |
| 45, F, exercises: yes | – | ✓ |
| 55, M, exercises: no | ✓ | – |
| 55, M, exercises: yes | – | ✓ |
| 65, F, exercises: no | – | ✓ |
| 65, F, exercises: yes | ✓ | – |
| 75, M, exercises: no | – | ✓ |
| 75, M, exercises: yes | ✓ | – |
With limited data it gets fuzzy: is a 74-year-old on B close enough?
Healthy people never get any treatment. Should they be removed from the data? It depends on how the question is set up.
With entry rules, the policy has to shrink too: "the effect is X for this type of patient", not for everyone.
The key tool for estimating the ATE from records. Also called the G-formula.
Why it helps: the ATE needs what-if results nobody saw. Ignorability lets you swap each one for something you did see: the results of similar people who got that treatment. So you compare like with like inside each kind of patient, then average across kinds by how common each kind is in the whole population.
Same setup as the sugar exercise. Treatment: diabetes drug A or drug B. Outcome: blood sugar afterward, lower is better. Half the population is young, half is old. Older people have higher sugar on either drug. Drug B went mostly to old people.
| Avg sugar, got B | Avg sugar, got A | B − A | Share of population | |
|---|---|---|---|---|
| Young | 6 | 7 | −1 | 50% |
| Old | 9 | 10 | −1 | 50% |
Naive math: if 90% of B patients are old and 90% of A patients are young, B averages 8.7 and A averages 7.3.
The formula averages over everyone, so it needs both results for every kind of patient. With limited data, some kinds have nobody similar on the other treatment.
| Similar on A | Similar on B | What-if | |
|---|---|---|---|
| Common type | ✓ | ✓ | average |
| Rare type | ✓ | none | guess |
Doesn't overlap guarantee similar people? Only with endless data. Real datasets are finite, so gaps remain.
From here there are many ways to fill the gaps. The next method uses a model.
Also called response surface modeling. Train an ML model that predicts the result from patient info plus treatment. Then ask it what-if questions.
Gap for each patient, averaged over everyone, is the estimated ATE. Variant: keep the real result for the treatment they got and predict only the other one. Both work.
Why it works: the model learns how results depend on patient info, separately seeing people who got A and people who got B. Asking "what if this patient got B?" returns the average result of similar people on B, which is exactly what the adjustment formula needs. Treatment is just one more input column. This step turns causal inference into an ML problem.
A 1970s US job training program (NSW) trained 185 people. A real randomized trial measured its effect on their 1978 earnings: +$1,794. Now pretend the trial's control group doesn't exist and compare the trainees with 15,992 people from a national survey (CPS) instead.
| Trainees | Survey people | |
|---|---|---|
| Avg age | 26 | 33 |
| Avg 1975 earnings | $1,532 | $13,651 |
The naive gap is far off because survey people earned much more to begin with. The models compare like with like and land near the trial. Gaps are averaged over the 185 trainees, the group the trial measured.
Five trainees, boosted-trees model, 1978 earnings:
| Age | Educ | 1975 | Actual | If trained | If not | Gap |
|---|---|---|---|---|---|---|
| 19 | 10 | $6,057 | $0 | $6,460 | $7,430 | −$970 |
| 23 | 12 | $501 | $671 | $4,280 | $5,980 | −$1,700 |
| 21 | 9 | $0 | $0 | $4,000 | $3,960 | +$40 |
| 37 | 11 | $0 | $9,930 | $5,990 | $1,490 | +$4,500 |
| 25 | 12 | $0 | $2,349 | $5,060 | $3,400 | +$1,660 |
Gaps vary by person: these are per-person effects. A straight-line model gives everyone the same gap (+$1,068), so it can't show who benefits more.
Averaged over all 16,177 people instead of the trainees, the boosted model says −$121. Most survey people look nothing like any trainee, so the model is guessing there. That is the overlap problem.
Data: LaLonde (1986), Dehejia and Wahba sample, CPS controls, via the causaldata package.
Each patient's gap, predicted B minus predicted A, is their estimated CATE. This fills in the arrows chart from 25:46. Use it to decide per patient: treat if the gap is good enough, for example above a threshold that covers cost.
An earlier course reading predicted outcomes for pneumonia patients in the ER from patient info alone. Asthma patients looked lower risk, because they got more intensive care. The model never included treatment and never asked what-if questions, yet was meant to guide choices like sending someone home.
Same trap as the cancer example at 3:49.
In ICU data like MIMIC, a lot. For sepsis, an infection-driven condition, antibiotics, fluids, blood-pressure drugs and ventilators are all recorded. Most ICU questions involve a sequence of treatments that react to the patient, which is next week's topic.
You don't, and it may not have. Treatment can be one weak input among many strong ones. With limited data and regularization (L1, L2, early stopping), the model can drop treatment entirely and predict from patient info alone.
In causal work treatment is special. The slides call patient info nuisance parameters and treatment the parameter of interest: the point is how the result changes when you change it, not how well you predict. Matters most with many inputs and complex models like deep nets. An active research area.
Same job-training data. A linear model with L1 regularization, three strengths. Trial answer: +$1,794.
| Prediction error | Estimated effect | |
|---|---|---|
| Light | $6,991 | +$1,056 |
| Medium | $6,994 | +$423 |
| Strong | $6,997 | $0, treatment dropped |
Prediction error barely moves ($6 out of ~$7,000). The effect estimate collapses to zero.
For a patient who got B, the method needs the model's prediction on A. If nobody even remotely similar got A, the model still outputs a number, but it is "garbage".
With overlap, more data eventually brings similar people on both treatments, so the model can learn the right answer. Real data is finite, though. When a model can extrapolate correctly with thin overlap is barely studied, and an opening for computer scientists.
This answers the challenge from 45:32: ignorability is used in the adjustment formula's step 3, and overlap shows up here.
No. If the true curves bend and the model is a straight line, more data never fixes it. The model family must be flexible enough, and grow more flexible as data grows.
Young people only got control and old people only got treatment. A straight line is the best fit to each group, and with no data on the other side nothing reveals it is wrong. Extended to the young, the lines cross: the model's per-person effect for a 25-year-old has the wrong sign.
If the true what-if results are straight lines, the coefficients of a linear model can be read as causal effects. A very strong assumption.
The data is observational. Doctors already chose who got treated, with no coin flip.
Each outcome is an average. The same treatment can work on one try and fail on the next.
Name causal questions the pandemic needs answered, framed as X, T and Y.
5:19 This breaks SUTVA, the Stable Unit Treatment Value Assumption: each person in the data is independent of the others.
Such questions need a different class of models that relax SUTVA. 6:04 Questions about how to treat COVID patients can only now be answered, because data is starting to come in.
The share of confirmed cases who died, the case fatality rate (CFR), was 4.3% in Italy and 2.3% in China. Is care in China better? Is the virus different?
Split by age, Italy is lower in every group. The overall numbers point the other way. This is Simpson's paradox.
8:32 The reason: the two groups of patients are very different. Italy's cases skew much older.
Simplified, for teaching only. Chart from slide 5. Data from von Kügelgen et al. (2020), Tables III and IV.
X is a patient's age. T is the country: the action is "moving" a patient from China to Italy. Y is whether they died. Question: what does changing the country do to Y?
The country decides the age mix of its patients, not the other way around. The same methods still apply, because both graphs look the same in observational data.
Fit any machine learning model f on patient features x plus the treatment T, to predict the outcome y.
The difference is the drug's effect for that patient. This only works if every reason behind who got treated is in the data. Then treated patients show what the drug does, and untreated patients show what happens without it.
13:30“A major difference in philosophy between machine learning and statistics.”
Which model to fit for f matters a lot. This is a major difference between machine learning and statistics, and between prediction and causal inference.
13:43 Assume the true model is linear, with one feature (age) and no age × drug term:
Noise is added too, and averages to zero.
The age term cancels and the noise averages out. CATE is γ for everyone, so ATE is γ too.
16:41 So if you fit a model of exactly this form, read the effect straight off the fitted drug coefficient. No plugging in needed. This only works because we assumed the truth is linear.
Chart: the slide 9 model drawn with made-up numbers.
19:09“In machine learning I typically tell my students: don't attempt to interpret your coefficients.”
If the fitted γ is off, the effect estimates are off too.
18:03 Class question: what does γ mean for the drug?
19:09 This explains a split between two fields:
For causal inference you need γ right, not the predictions. The slide calls this identification, not prediction.
20:12 With a new sample of 100 patients, the fitted γ would change. A 95% confidence interval for γ is also one for the average effect.
Chart: simulation, 300 new samples of 100 patients each.
23:35“This should scare you. If you're making the wrong assumptions about the true potential outcomes, you could get very, very wrong conclusions.”
Add one curved age term to the truth. The drug effect is still exactly γ for everyone. You don't know about the curve, so you fit a straight line anyway.
Even with endless data, the fitted coefficient is γ plus δ times a term from the age and treatment data. A large δ can turn a drug that lowers blood pressure into one that seems to raise it.
23:35 This is what makes covariate adjustment dangerous: wrong assumptions about the shape give very wrong conclusions. So you want models that make few assumptions, such as neural networks or random forests, which can fit the curve.
Chart: the slide 12 model with made-up numbers. Shown with the fit from endless data; the dots are one sample of 80.
Many machine learning methods have been used for causal inference:
24:34 Gaussian processes, two ways to set them up:
25:18 Neural networks, the design from his group:
Only the patient features go into the first layers. The shared part learns from treated and untreated patients together. Each treatment then gets its own head. This worked much better than simpler designs on several benchmark datasets.
Diagram from slide 15. Shalit, Johansson, Sontag, ICML 2017.
27:37“It actually is precisely identical to covariate adjustment.”
For each person, find a near-identical "twin" who got the other treatment. The twin's outcome stands in for the outcome we never see. It works for both the per-person and the average effect.
It looks unrelated to covariate adjustment. He will show it is the same thing, with one particular kind of model.
The twin's outcome answers "what if he had gone to business school?" A made-up example: no dataset is that big.
32:32“It's used all the time in clinical research, despite the fact that biostatisticians have been trying to argue that folks should not use this technique.”
Two patient features: age, and a score for how many other conditions they have, such as diabetes or high blood pressure. Outcomes are not shown. Each treated patient borrows the outcome of the closest untreated one.
30:50 Class questions:
Chart redrawn from slide 18, plus the far-away point he describes.
35:06 One person can be the closest twin for several others.
Class question: should closer twins count more? Yes, that works. He says there are a few hundred papers on variants like it.
37:39 Matching is easy to check:
42:19“Think about matching just as another type of covariate adjustment.”
Use a nearest-neighbor model as the f inside covariate adjustment:
So compare matching with other covariate adjustment models, such as models built to be easy to read.
44:19“The key idea of a propensity score method is to turn an observational study into something that looks like a randomized controlled trial.”
A second, different way to estimate the average effect. In a randomized trial, a coin decides treatment, and the estimate is simple:
With observational data, reweight people until the groups look like they came from a coin flip.
Only features and treatment are shown, no outcomes. Young people mostly went untreated. Older people mostly got treated.
45:20 Give each dot a weight. A treated person among mostly untreated people counts for more, and the reverse. Then in every region, treated and untreated weigh about the same.
Chart: made-up data, dot size shows the weight. Slides 23 and 24 show the same idea.
The propensity score is each person's chance of being treated, given their features. Learn it with any model, such as logistic regression. Ignore the outcome: here the label is the treatment.
47:34 This is the same idea as dataset shift from lecture 10.
48:36 The chances must be real probabilities, not just a yes/no guess. Deep neural networks are often poorly calibrated, so they need a calibration fix first.
In a coin-flip trial, everyone's chance of treatment is 0.5. No machine learning needed. Plug it in:
So 2/n is about 1 ÷ (group size), and the formula becomes the plain trial estimate: treated average minus untreated average.
52:19 Class question: is the propensity score the bias in who gets treated? Yes. Dividing by it removes that bias.
54:54 Same problem as dataset shift: we need an average over a different group than the one we have.
57:29 Estimate the share treated as n1/n, and plug in the propensity score for the chance. That gives the formula. The untreated half works the same way.
He assumes outcomes have no noise here, to keep the math simple.
58:27“We never had to use a model to predict y.”
59:15 A common fix is clipping: keep every chance away from 0 and 1. It is only a rule of thumb, and it can bias the estimate.
59:33 Doubly robust estimators combine covariate adjustment and propensity scores. If either one is wrong, the estimate is still valid.
Chart: weight = 1 ÷ chance. The 0.05 clip is an example value.
1:00:08“Both of these, I need to stress, are only going to give you valid results under the assumptions.”
1:00:36 Without overlap, both break:
1:01:21 The last slides list two recent ML workshops, two free causal inference books, and papers worth reading for course projects.