Emulating the trial you can't run
A guided pre-reading on target trial emulation, time zero, and the biases good design prevents
Current Topics in Biomedical Informatics and Data Science
Johns Hopkins Biomedical Informatics and Data Science · Seminar of November 5, 2026
Using synthetic patients where we know the true answer, we explore causal inference and the design biases in observational studies, and show methods that reduce them. Every number after Part 1's opening story is hypothetical.
What to take away. This is a demonstration of a few tools, not a full course: causal inference takes a semester or more to teach. The core lesson is that in observational data, a comparison of two groups can be badly biased even when the p-value is small and the confidence interval is narrow. Depending on your background and goals, you may come away with a sharper eye for when that bias is present and when it isn't. Or you may come away curious to learn these methods in depth.
Practice questions
Ten short questions are spread through this reading. They aren't graded. They help you check your understanding as you go, and they show us which ideas were hard. You'll see right away if you're right; if not, you get a hint and can try again.
Enter your name and the class PIN from the Canvas assignment to turn them on. Use the same name each time and your answers come back on any device. We store a scrambled code made from your name, not the name itself.
Part 1 · Why we need a target trial
A cautionary tale
For decades, observational studies suggested that hormone therapy after menopause protected women's hearts. In the Nurses' Health Study, women currently using hormones had about 40% fewer major coronary events than women who had never used them (relative risk 0.61).¹
Then the Women's Health Initiative randomized 16,608 women to estrogen plus progestin or placebo. The women assigned to hormones had more coronary heart disease (hazard ratio 1.29), and the trial was stopped early in 2002 because the risks outweighed the benefits.²
Same question, opposite answers. Was the observational data useless?
In 2008, Hernán and colleagues went back to the Nurses' Health Study and analyzed it as if it were a trial. They compared women who started hormones with women who didn't, with follow-up starting at the moment of that decision. Now the observational data pointed to more heart disease in the first two years after starting hormones, as in the trial, and the authors judged their estimates similar to the trial's.³
The data didn't change. The design did. The authors found the remaining differences were largely explained by who was compared (how long after menopause) and for how long (the early years vs the whole follow-up).³ There was likely one more reason the original analysis missed the early harm: "current users" had often been taking hormones for years, so the women harmed early on had already dropped out of that group.
¹ Grodstein et al., Ann Intern Med 2000;133:933-941. ² Writing Group for the Women's Health Initiative Investigators, JAMA 2002;288:321-333. ³ Hernán et al., Epidemiology 2008;19:766-779.
The idea: name the trial you wish you could run
A target trial is the randomized trial that would answer your question if you could run it, with no limits on money, time, or ethics committees.
Target trial emulation means writing that trial's protocol down, then copying each part of it as closely as you can with data you already have: electronic health records, insurance claims, registries. If the emulation works, it gives the same answer the trial would have, apart from chance.
The protocol forces you to answer questions that are easy to skip. Who is eligible, and when? What exactly is each group supposed to do? When does the clock start?
Words you'll need
| Term | Plain meaning |
|---|---|
| Target trial | The randomized trial you would run to answer your question. |
| Emulation | Copying that trial, step by step, with data collected for other reasons. |
| Eligibility criteria | Who can enter. They must be checked at time zero, using only what's known then. |
| Treatment strategy | Exactly what each group is supposed to do, like "start a statin today" vs "don't start today." |
| Assignment | How people end up in a group. In a trial, a coin flip (randomization). In real-world data, whatever the patient and doctor chose. |
| Time zero (baseline) | The moment follow-up starts. In a trial, it's when people are randomized. |
| Follow-up | The time from time zero until the outcome, the end of the study, or until we lose track of someone. |
| Outcome | What we count, like death by day 28. |
| Intention-to-treat effect | The effect of being assigned to (or starting) a strategy, whatever happens afterward. |
| Per-protocol effect | The effect of actually following the strategy as written. |
| Confounder | Something that affects both who gets treated and the outcome, like how sick a patient is. |
| Censoring | Ending someone's follow-up early in an analysis. Nothing after that moment counts. |
| Risk difference per 100 | The risk in one group minus the risk in the other, out of 100 people. "−3 per 100" means 3 fewer deaths for every 100 patients treated. |
| 95% confidence interval | The range of answers that fit the data, given chance alone. It says nothing about bias. |
The secret of a randomized trial: time zero
In a trial, three things happen at the same moment. A person is checked for eligibility, assigned to a group, and follow-up starts. That moment is time zero.
Observational analyses often break this alignment without noticing. The rule is simple: eligibility is checked at time zero, not later, and outcomes count only after time zero, never before. Hernán and colleagues have called the errors that follow "self-inflicted injuries."⁴
Check your understanding · Select all that apply
Enter your name and the class PIN at the top to answer.
Three biases we'll control for
1. Immortal time
Suppose you sort patients by what they do after time zero: "ever treated" vs "never treated." To be counted as treated, a patient had to survive long enough to get the treatment. The time before their first dose is immortal: they couldn't have died in it and still ended up in the treated group. Meanwhile, patients who die early are all counted as untreated. The treatment looks better than it is, sometimes much better.⁵
Check your understanding · Choose one
Enter your name and the class PIN at the top to answer.
2. Confounding
In real life, treatment isn't a coin flip. Doctors treat the patients who seem to need it most. If sicker patients are both more likely to be treated and more likely to die, the treatment looks harmful even when it helps. That's confounding by indication. The reverse happens too: healthier people are more likely to take preventive drugs, so those drugs look better than they are (the healthy-user effect).
The fix is adjustment: compare treated and untreated patients who look alike on the confounders, using regression, matching, weighting, or standardization. It works only for confounders someone recorded.
3. Prevalent-user selection
Compare people currently taking a drug with people who never took it, and you've started follow-up years after treatment began. Two things go wrong:
- Survivors only. People harmed early by the drug, or who stopped it because of side effects, are no longer "current users."
- Measurements on the drug. Their baseline values (cholesterol, blood pressure) were measured after the drug changed them.
The fix is a new-user design: start the clock when people start (or don't start) the drug.
Check your understanding · Select all that apply
Enter your name and the class PIN at the top to answer.
How we'll learn it: worlds where we know the truth
Real data never tell you whether you got the right answer. So we built two simulated worlds where we set the true effect of a drug, then analyzed each world's records the way published studies do.
Every patient has two potential outcomes: what would happen with the treatment, and what would happen without it. Real data only ever show one. A simulation can show both: we run every patient twice, once under each strategy, with the same random "luck" both times. We call this the perfect experiment. It's the answer key, and every analysis gets measured against it.
| World | The time-zero puzzle | The method | |
|---|---|---|---|
| Part 2 | An ICU: hydrocortisone in septic shock | Treatment can start any time in the first 24 hours, so at time zero you can't tell who's in which group | Clone-censor-weight |
| Part 3 | A clinic: statins after age 75 | People are eligible at every visit. Which visit is time zero? | Sequential trials |
⁴ Hernán et al., J Clin Epidemiol 2016;79:70-75. ⁵ Suissa, Am J Epidemiol 2008;167:492-499.
Part 2 · Clone-censor-weight: hydrocortisone in septic shock
The question
Septic shock is sepsis with low blood pressure that needs vasopressor drugs, plus a high lactate despite IV fluids. Hospital mortality is over 40%.⁶ Low-dose IV hydrocortisone, a steroid, is a common add-on, and whether it saves lives is still debated.
Our question: among adults with septic shock, does starting hydrocortisone within 24 hours of shock onset, compared with not starting it in the first 24 hours, change the risk of death by day 28?
The target trial, and how we'll emulate it
Here is the protocol, written out component by component. We list the start of follow-up, time zero, as its own row, because that's where things go wrong.
| Component | Target trial (the trial we'd run) | Emulation (with the hospital's records) |
|---|---|---|
| Eligibility | Adults in their first episode of septic shock, which began in this hospital, not taking steroids at home | The same rules, from age, transfer status, prior episodes, and the home medication list. Also must have a lactate result, a key confounder. |
| Treatment strategies | A: start IV hydrocortisone within 24 h of shock onset. B: no hydrocortisone in the first 24 h; usual care after. | The same, read from medication administration times |
| Assignment | Random, at shock onset | The team's choice. Adjust for age, sex, SOFA score, lactate, norepinephrine dose, and limits of care. |
| Time zero | Randomization, at shock onset | Shock onset (the first vasopressor), for every patient |
| End of follow-up | Death or day 28 | The same |
| Outcome | Death from any cause by day 28 | The same, from the death date in the records |
| Causal contrast | Per-protocol: following A vs following B | Per-protocol, by clone-censor-weight |
| Analysis plan | Compare the 28-day risk of death | Weighted risk curves, with bootstrap 95% CIs |
The tricky part is strategy A. It allows 24 hours to start, because no ICU can give a drug the instant a patient is randomized. This is called a grace period. During those 24 hours, a patient who hasn't started yet is following both strategies. Keep that in mind.
⁶ Singer et al., JAMA 2016;315:801-810 (Sepsis-3).
Our simulated ICU
Each patient is followed in 6-hour shifts for 28 days. In every shift, two things can happen:
- The team may start hydrocortisone. The chance depends on how sick the patient looks.
- The patient may die. The chance depends on how sick they are, and on whether they're on hydrocortisone.
We wrote down the rules ourselves. They're plausible, but we made them up. The most important one: hydrocortisone lowers the odds of dying in each shift by 20% (an odds ratio of 0.80). That's the truth every analysis will try to recover.
Sicker patients (higher SOFA score, lactate, and norepinephrine dose) are more likely to die and more likely to get hydrocortisone. Those are confounders. Patients with documented limits of care (for example, a do-not-escalate order) die more often but rarely get hydrocortisone. Prescriber style changes who gets treated but not who dies, so it isn't a confounder.
The answer key: a perfect experiment
Here are 12 simulated patients, run three times: once under usual care, once with everyone following strategy A, once with everyone following B. Each patient keeps the same random "luck" in all three runs, so only the strategy differs. Most patients have the same fate either way. Only a few are saved, or lost, by the drug.
Now do that for 200,000 patients: everyone under A, then everyone under B. It's the target trial done perfectly: no confounding, everyone follows their strategy, nobody is lost to follow-up.
This is the answer key: starting hydrocortisone within 24 hours prevents about 3 deaths per 100 patients by day 28. Every analysis from here on is measured against that number.
Two things to remember from these pictures:
- Day 1 is when hydrocortisone usually starts, and it's also the deadliest day. That overlap sets up immortal time.
- Sicker patients get more hydrocortisone and die more. That's confounding by indication. On its own, it should make hydrocortisone look harmful.
Hydrocortisone looks like a miracle drug: about 13 fewer deaths per 100 patients, four times the truth. And it's the opposite of what confounding should do: the treated patients were sicker. Something stronger is pushing the other way. That something is immortal time.
If a patient is in the "treated" group, they could not have died before their first dose. If they had, they'd be in the "untreated" group. So the hours between shock onset and the first dose are guaranteed survival, credited to hydrocortisone. Meanwhile, patients who died early, before anyone could treat them, all count as untreated.
Standard approach 2: adjust for confounders
The usual next step is to adjust, because the treated patients were sicker. We'll use propensity score weighting (inverse probability of treatment weighting, IPTW). It works in two steps:
- Propensity score. A regression predicts each patient's chance of being treated from the confounders. A score of 0.8 means "80% of patients who looked like this got hydrocortisone."
- Weights. Each patient counts as 1 ÷ (the chance of the treatment they actually got). An untreated patient with a score of 0.8 was a surprise: they count as 1 ÷ 0.2 = 5 patients, standing in for the similar patients who went the other way.
The weighted groups look alike on every measured confounder, as if treatment had been a coin flip.
The groups are now balanced, and the answer got worse. Adjustment did its job: it removed confounding by indication, which had been partly cancelling out the immortal time. With that counterweight gone, the immortal time bias shows through in full.
No amount of adjustment can fix groups that were defined using the future. We have to fix the design.
Check your understanding · Type a number
Enter your name and the class PIN at the top to answer.
Check your understanding · Choose one
Enter your name and the class PIN at the top to answer.
The fix: emulate the target trial
Start everyone's clock at shock onset, as the trial would. But there's a catch: at shock onset, we can't tell which strategy a patient is following. A patient untreated at hour 6 might start at hour 12, or never. Thanks to the grace period, their records fit both arms.
The answer is to make two exact copies of every patient: clones. The method is called clone-censor-weight:
- Clone. At time zero, copy every patient into both arms.
- Censor. Follow each clone only while its patient's records obey its arm's rule. The moment they break it, the clone is censored: from then on, nothing that happens to that patient counts in that arm.
- Weight. Censoring isn't random, so reweight the clones that remain to stand in for the ones that left.
Here are the clones of three patients:
- Patient 1 started at hour 6. Clone A follows the rule. Clone B broke "no hydrocortisone in 24 h" at hour 6, so it's censored.
- Patient 2 started at hour 48, too late for A. Clone A is censored at the deadline; clone B follows the rule.
- Patient 3 died at hour 6, before breaking either rule. The death counts in both arms, just as it would in a real trial for a patient randomized at hour 0 who died before treatment began. No one gets survival time for free.
Clones leave follow-up at different times, so we can't just divide deaths by clones. The Kaplan-Meier method handles that: at each moment, among the clones still being followed, what share die?
Fixing time zero removed the immortal time, and now hydrocortisone looks harmful. That's confounding coming back through censoring. The sickest patients start hydrocortisone early, so their arm-B clones break the rule and leave. Arm B is gradually left with healthier patients.
Check your understanding · Choose one
Enter your name and the class PIN at the top to answer.
Weighting the clones that remain
The fix mirrors propensity score weighting. A regression predicts each patient's chance of starting hydrocortisone in each first-day shift, from the same confounders. An arm-B clone that stayed untreated is weighted by 1 ÷ (its chance of staying untreated that long). A very sick patient who stayed untreated is rare, so their clone counts extra, standing in for the similar clones that were censored.
With weights, arm B keeps the mix of patients it started with. Now estimate the risks again, with each clone counted by its weight:
From the same records, the emulated trial recovers the truth. The solid curves sit on the dashed perfect-experiment curves. Nothing about the data changed. We changed the design, by lining up eligibility, assignment, and time zero the way a trial does, and then handled the censoring that design creates.
What did we estimate? Because each patient sits in both arms at time zero, cloning can't estimate an intention-to-treat effect. What we estimated is a per-protocol effect: what happens if patients follow strategy A vs strategy B.
The estimate roughly doubles, and nothing in the output warns you. Patients with limits of care rarely get hydrocortisone and often die. If we can't see them, "no hydrocortisone" looks deadlier than it is.
The emulated trial's interval covers the truth. The standard approaches, and the emulation missing a confounder, have narrow intervals far from the truth. A confidence interval only measures chance; it can't see bias. Precision isn't accuracy, and a bigger dataset would only make the wrong answers look more certain.
The lesson of Part 2: with time zero broken, adjustment made things worse. With time zero aligned, the answer was right only once the confounders were handled too (here, through the censoring weights). Design fixes time zero. Adjustment fixes measured confounding. You need both.
Check your understanding · Choose one
Enter your name and the class PIN at the top to answer.
Part 3 · Sequential trials: statins after age 75
The question
Whether statins help adults over 75 who have never had a heart attack or stroke is a real, open question. Everything below is hypothetical: a made-up clinic with made-up numbers.
Our question: in adults 75 or older with no heart attack or stroke, does starting a statin at a routine visit, compared with not starting at that visit, change the risk of a heart attack or stroke over 5 years?
Why one time zero isn't enough
In Part 2, everyone had an obvious time zero: shock onset. In a clinic, there's no such moment. Our clinic sees each patient every 3 months. At every visit, an eligible patient's doctor might start a statin. So the same person meets the trial's entry criteria at visit 1, again at visit 2, and so on, until they start a statin or have an event. Which visit is time zero?
Two honest choices. When people are eligible many times, there are two unbiased options: (1) pick a single eligible time, like the first, or (2) use all eligible times, starting a new trial at each one. Option 2 is called sequential trials, and it uses the data more efficiently. We'll try both.
| Component | Target trial (the trial we'd run) | Emulation (with the clinic's records) |
|---|---|---|
| Eligibility | Age 75 or older, no heart attack or stroke, never on a statin, at least 1 year of records | The same, from age, diagnoses, and prescriptions, checked at each visit |
| Treatment strategies | Start a statin today vs don't start today (usual care afterward, which may mean starting later) | A new statin prescription at this visit, or not |
| Assignment | Random, at the visit | The doctor's choice. Adjust for age, sex, diabetes, smoking, blood pressure, and the LDL and frailty recorded at that visit. |
| Time zero | The visit when randomized | Every eligible visit in the first 3 years: one trial per visit |
| End of follow-up | A heart attack or stroke, or 5 years | The same |
| Outcome | First heart attack or stroke within 5 years | The same, from diagnosis records |
| Causal contrast | Intention-to-treat | The observational analog of intention-to-treat: initiators vs non-initiators, whatever they do later |
| Analysis plan | Compare 5-year risks | Standardization over all the trials pooled; bootstrap CIs that resample people |
Our simulated clinic
Each patient is followed visit by visit, every 3 months, for 8 years. At each visit the doctor may start a statin, and over the next 3 months the patient may have a heart attack or stroke. To keep things simple, nobody in this clinic dies of other causes or moves away.
The true effect we built in: a statin lowers the odds of a heart attack or stroke in every 3-month period by 30% (an odds ratio of 0.70). As before, we made up all the numbers.
Look at frailty: it raises the risk of events but lowers the chance of getting a statin. So statin users will be healthier than non-users for reasons that have nothing to do with the drug: the healthy-user effect. High LDL and diabetes push the other way.
Two of these risk factors change over time. LDL wobbles from visit to visit, and frailty creeps upward. So the reasons a doctor starts a statin this year differ from last year's, and a fair comparison has to use the values recorded at the visit where the decision was made.
The answer key
First, say exactly what we want to know: when an eligible patient comes in for a routine visit, how many heart attacks and strokes over 5 years does starting a statin that day prevent, compared with not starting that day? Averaged over every eligible visit. That's an intention-to-treat question about a decision at a visit. It's not "always on a statin vs never."
The perfect experiment: for each of the 12 trial visits, rewind to that visit and run each eligible patient's future twice, starting and not starting, with the same luck.
The answer key: starting a statin at an eligible visit prevents about 3.5 heart attacks or strokes per 100 people over 5 years.
The clinic's records
Real life gets one run, under usual care: 20,000 older adults followed for 8 years. The records hold one row per patient per visit, with the LDL as measured (lower if the patient is on a statin), the frailty score, whether a statin was started, and whether a heart attack or stroke followed.
Who starts a statin, and who has events? Each bar covers a quarter of all eligible visits:
One adjustment method for every analysis
To keep the comparison fair, every analysis below uses the same adjustment. Only the design changes: who is compared with whom, and from when. The method is standardization (also called the g-formula):
- Model the outcome in each group. One regression among the treated, one among the untreated, each predicting the chance of an event within 5 years from the confounders.
- Predict twice. For every person, ask both models: "what's your risk if treated?" and "what's your risk if not?"
- Average. The averages are the risks if everyone were treated, and if no one were. Their difference is the effect.
Statins look more than twice as protective as they are. It's immortal time again: to be counted as a "statin user," a patient had to stay event-free until their first prescription. Anyone who had a heart attack first ended up a "never user."
Now the statin looks useless. Why? Look at the cholesterol the records hold for each group:
Prevalent users' baseline LDL was measured on the drug. The records make them look like people with naturally low cholesterol, when they're really high-risk people whose cholesterol is being treated. Adjusting for that on-treatment LDL hides their risk, so the statin seems to do nothing.
That's one of the two prevalent-user problems from Part 1. The other, survivors only, isn't built into this simulation, but it's the one from the hormone therapy story in Part 1: women harmed early had already dropped out of the "current users" group. Either way, the direction of the bias is hard to predict, which is why target trial emulations compare initiators (new users).
Check your understanding · Choose one
Enter your name and the class PIN at the top to answer.
A valid design: one trial at cohort entry
Now do it right, but only once: a single target trial at cohort entry, choice (1). Eligible: the new-user cohort at visit 0. Initiators started a statin at that visit; non-initiators didn't (and may start later). Everything uses information available at time zero.
This design is valid: no immortal time, no prevalent users. It answers a slightly narrower question (a decision at cohort entry), whose true answer is the solid tick. But only a few hundred people started a statin at that one visit. Everyone who started later is thrown away. We'll see the cost when we add confidence intervals.
Sequential trials: a new trial at every visit
Choice (2): emulate a new trial at each of the first 12 visits.
- Eligible: in the new-user cohort, not yet on a statin, no heart attack or stroke yet, at this visit.
- Assignment: initiators started a statin at this visit; non-initiators didn't.
- Time zero: this visit. Baseline values are the ones recorded at this visit.
- Follow-up: 5 years from this visit, whatever happens to treatment later (intention-to-treat).
Every eligible visit becomes one row of one trial. Here are four patients from our records, and every trial each one joins:
Read it row by row:
- A is a non-initiator in all 12 trials.
- B is a non-initiator in trials 1 to 5, an initiator in trial 6, then gone: on a statin, so no longer eligible.
- C's single event counts in every trial C joined.
- D is a non-initiator in the first two trials even though D started later. That's intention-to-treat: each trial groups people by what they did at its own time zero.
Each person is an initiator at most once, so everyone who starts a statin in the first 3 years contributes as an initiator. Here are the stacked rows for patients B and D:
Initiators have higher LDL and are less frail than non-initiators. First, compare them with no adjustment, then with standardization. We add the trial number to the models, so each trial keeps its own baseline risk.
From the same records, sequential trials recover the truth. Without adjustment, the healthy-user effect makes statins look too good. Here is standardization at work for three rows of the stacked data. Each row gets both predictions, whatever it actually did; the effect is the average gap over all rows.
Check your understanding · Choose one
Enter your name and the class PIN at the top to answer.
What design can't fix
Sequential trials assume we recorded everything that affects both starting a statin and events. Our records include a frailty score. Many real records don't. The same analysis, pretending frailty was never recorded:
The healthy-user effect comes back, and nothing in the output warns you. Frail patients rarely start statins and often have events. If we can't see frailty, "no statin" looks worse than it is.
How sure are we?
There's a catch. The same person appears in many rows, and their outcomes are linked: patient C's one event counted in every trial C joined. Standard confidence intervals treat every row as a different person, so they come out too narrow. The simple fix is to bootstrap people, not rows: draw patients at random, take all their rows, rerun everything, repeat.
Resampling rows pretends the non-initiators are about 100,000 different people. They're about 10,000 people, each counted up to 12 times, so that interval is far too narrow. Always resample people.
Here are all of Part 3's results with their 95% confidence intervals:
Both valid designs land near their own truth, but the sequential trials' interval is about half as wide. The single trial at entry throws away most of the people who started statins. The shortcuts, and the emulation missing frailty, are precise and wrong.
The lesson of Part 3:
- When people can start a treatment at any time, there's no single obvious time zero.
- Picking one by looking ahead (ever users) or by ignoring the past (current users) breaks the comparison.
- Picking one honestly (one trial at entry) works but wastes data.
- Emulating a trial at every eligible visit keeps the design honest and uses all the information. It still needs adjustment for the confounders, and a confidence interval that knows people repeat.
Check your understanding · Choose one
Enter your name and the class PIN at the top to answer.
Part 4 · Wrap-up
Every analysis from Parts 2 and 3, measured by how far it landed from the truth:
Key takeaways
- Write the target trial's protocol first. Eligibility, strategies, assignment, time zero, follow-up, outcome, causal contrast, analysis. Then copy it, one component at a time.
- Line up eligibility, assignment, and time zero. Ever-vs-never and current-vs-never comparisons break that alignment. The resulting biases are large, confident, and can point either way.
- Adjustment fixes confounding, and only for what was recorded. It can't fix a broken time zero, and it can make a broken design look worse.
- When strategies overlap at time zero (a grace period), clone, censor, and weight. The result is a per-protocol effect.
- When people are eligible many times, emulate a trial at each eligible time and pool them. Then resample people, not rows.