ExpertIndependently reviewed, not yet spot-checked by a human

Target trial emulation

Write down the randomised trial you would run if you could, fill in its seven components, and only then ask which people and which time points in your observational data can stand in for that protocol. The discipline exists to catch immortal time bias, prevalent user bias and the missing active comparator — three design errors no amount of statistical adjustment can repair. Unmeasured confounding is not one of the things it fixes.

What this page answers

The five pages before this one all deal with problems of analysis: what to adjust for, how to match, how to weight, what to do when a confounder was never measured. This page deals with something that comes earlier — design.

The reason is an uncomfortable fact: the most serious errors in observational research are usually not the wrong choice of statistical method, but a research question that was never written down properly. “Does this drug work?” is not a question you can hand to an analysis, because it does not say: compared with what? Starting from when? Who counts as having taken it? Do three days count? What happens to people who stop?

In a randomised controlled trial those questions cannot go unanswered — you have to write the protocol before you can enrol the first patient. In a database study the data are already sitting there, you can start fitting models immediately, and so the questions get skipped. The consequences come back as bias.

Target trial emulation takes the trial’s discipline and moves it across: first write down the randomised trial you would run if ethics and money were no obstacle, fill in its seven components, and only then ask which people and which time points in the observational data can stand in for that protocol.

It is not a statistical method. It is a form to fill in. And what it repairs happens to be exactly what statistical methods cannot.

The seven components of a target trial

ComponentHow a trial writes itThe commonest mistake in a database study
1. EligibilityDecided before randomisationSelecting people using information only the future reveals (“patients who completed the course”)
2. Treatment strategiesWhat each arm does, written so it could be followed“Ever used the drug” is not a strategy: no dose, no duration, no rule for stopping
3. Assignment procedureRandom, with blinding statedObservational data cannot randomise, so this cell becomes “conditional on which covariates can assignment be treated as random?”
4. Follow-up periodFrom the moment of randomisation to a defined endpointTime zero is undefined, or the arms have different time zeros
5. OutcomeDefined in advance, with how and when it is measuredAssembled from whichever codes the database happens to hold, with no discussion of misclassification
6. Causal contrastIntention-to-treat or per-protocol, stated in advanceNever stated, so the analysis drifts between the two
7. Analysis planPrimary, secondary and sensitivity analyses, all pre-specifiedWhat to adjust for and whether to stratify is decided after seeing the results

Of the seven, the first, third and fourth carry most of the weight, because they correspond to the three commonest and most damaging design errors.

Three design errors

Immortal time bias

If group membership can only be known after baseline (“did they start the drug during follow-up?”), then the stretch between baseline and starting the drug is time during which anyone assigned to the treated group could not have died — had they died, they would never have appeared in that group. Counting that stretch as treated survival hands the treated arm a span of guaranteed-alive follow-up out of thin air.

The censoring and the structure of survival data page demonstrates the mechanism in full with the real Stanford heart transplant data, so it is not repeated here. What the target trial framework adds is an explanation of why it happens: a trial cannot have this problem, because time zero is the moment of randomisation and the basis for allocation is already settled at that moment. Database studies commit it because the “time zero” cell was left blank.

Prevalent user bias

If people who are already taking the drug when the study window opens are enrolled into the treated group, what you have enrolled is people who have taken it for a while and come to no harm. The ones most susceptible — who developed a side effect after two weeks and stopped, or who already had the event — never make it into your cohort.

This is depletion of susceptibles, and it systematically makes the drug look safer than it is. It cannot happen in a trial, because a trial only enrols people who have not yet started. The corresponding fix is the new-user design: pin time zero to the moment treatment starts, and enrol only people who had not used the drug before that moment.

No active comparator (confounding by indication)

“Treated versus untreated” has a structural problem: the untreated are people a clinician judged did not need treating. They differ from treated patients in health status, in how often they see a doctor, in comorbidity, and in a great many things nobody wrote down.

An active comparator uses another drug for the same indication as the control. Both groups are people a clinician judged needed treatment, so the unmeasured factors that drive “treat or not” largely cancel between them. What remains is “why A rather than B”, which is usually a narrower and more measurable set of factors.

One simulated dataset, seven analyses

The setup: 8000 patients are followed in a database for 84 months, with the study window opening after month 24. Two drugs treat the same indication — drug A truly lowers the hazard of death to 0.80 (a hazard ratio), and drug B has no effect. There are two confounders:

  • L, a recorded severity marker. It affects both whether someone is treated and which of the two drugs they get.
  • U, an unrecorded measure of frailty. It affects whether someone is treated and it affects death, but it does not affect the choice between A and B.

The simulated data behave accordingly: treated and untreated people differ by 0.49 standard deviations of U, whereas users of A and users of B differ by only -0.082 of U — but by 0.65 of L. That contrast is the entire rationale for an active comparator design.

library(survival)
set.seed(20260822)

N <- 8000; RUN_IN <- 24; END <- 84; TRUE_HR <- 0.80

L <- rnorm(N)                                  # severity: recorded
U <- rnorm(N)                                  # frailty: not recorded
p_init <- plogis(-4.4 + 0.7 * L + 0.7 * U)     # monthly chance of starting some drug
is_A   <- rbinom(N, 1, plogis(0.8 * L))        # which drug, driven by L alone

alive <- rep(TRUE, N); init <- rep(NA_integer_, N)
onA <- rep(FALSE, N); onB <- rep(FALSE, N); death <- rep(NA_integer_, N)
for (m in 1:END) {
  start <- alive & is.na(init) & (runif(N) < p_init)
  init[start] <- m
  onA <- onA | (start & is_A == 1); onB <- onB | (start & is_A == 0)
  h <- 0.0055 * exp(0.6 * L + 0.6 * U + log(TRUE_HR) * onA)
  d <- alive & (runif(N) < pmin(h, 1))
  death[d] <- m; alive[d] <- FALSE
}

# -- The naive analysis: everyone alive when the window opens, grouped by
#    whether they ever used A. Prevalent users stay in (init <= 24) and the
#    clock starts at month 24 -> two errors stacked ----------------------
# -- The target trial version: enrol only people who start after the window
#    opens (new users), set time zero to the month they start, use people
#    starting B in the same period as the control arm (active comparator),
#    then apply IPTW on L ------------------------------------------------
ac <- data.frame(id = which(!is.na(init) & init > RUN_IN))
ac$arm  <- as.integer(is_A[ac$id] == 1)
ac$L    <- L[ac$id]
ac$time <- pmin(ifelse(is.na(death[ac$id]), END, death[ac$id]), END) - init[ac$id] + 1
ac$event <- as.integer(!is.na(death[ac$id]) & death[ac$id] <= END)
ac <- ac[ac$time > 0, ]

ps   <- fitted(glm(arm ~ L, data = ac, family = binomial()))
ac$w <- ac$arm / ps + (1 - ac$arm) / (1 - ps)
coxph(Surv(time, event) ~ arm, data = ac, weights = ac$w, robust = TRUE)

Verified with R 4.6.0 and survival 3.8.6; the simulation and all seven analyses use base R and survival only

A forest plot of seven hazard ratios with 95% confidence intervals against a dashed line at the simulated true hazard ratio. The naive analysis sits to the right of 1; the row with immortal time added sits close to the truth; the unadjusted new-user row points towards harm; the two adjusted active-comparator rows cover the truth.
Seven analyses of the same simulated data. The black dashed line is the true hazard ratio. Note that this ladder does not descend monotonically — the second row, the one carrying immortal time bias, lands almost exactly on the truth, and it is wrong.Plotting script figures/scripts/B6-06-target-trial.R
DesignAnalysed n (A / control)EventsHR95% CIWhat is wrong
True effect (the simulation’s setting)0.80
Prevalent users kept, grouped at baseline by “ever used”5092 (2003 / 3089)14821.131.02–1.25Two design errors stacked
New users vs untreated, clock started at the study window5737 (870 / 4867)10150.780.66–0.93Immortal time
New users vs untreated, unadjusted5737 (870 / 4867)10151.341.13–1.59Confounding by indication
New users vs untreated, adjusted for the measured L5737 (870 / 4867)10151.010.85–1.20The unmeasured U is still there
New users + active comparator, unadjusted1778 (870 / 908)3390.930.75–1.15U cancels out, L remains
New users + active comparator, adjusted for L1778 (870 / 908)3390.790.63–0.99Covers the truth
New users + active comparator + IPTW1778 (870 / 908)3390.780.62–0.99Covers the truth

“Analysed n” is the size of the dataset that row’s model actually ran on, not the size of the simulated cohort — change the design and the people who qualify change with it, so each row’s n and event count have to be read alongside its hazard ratio.

Reading down the ladder, each row changes exactly one thing:

  • Row one is the analysis you see most often: of the 6777 people alive when the study window opens, 1685 who ever used drug B are dropped, and the remaining 5092 are grouped by whether they ever used drug A (people who used B are in neither arm, and that exclusion is itself something a paper should report). Of them, 1133 are prevalent users, already on the drug before the window opened, and everyone’s clock starts at the window. The estimate is 1.13 — the drug genuinely cuts the hazard of death by a fifth, and the naive analysis says it causes harm.
  • Rows two and three differ in one thing only: time zero. They use exactly the same two groups of people. In row three the treated clock starts at the moment treatment begins, with no immortal time; in row two it starts at the study window, so those 21125 person-months of not-yet-treated time are counted as treated follow-up. The hazard ratio moves from 1.34 to 0.78. That gap is immortal time and nothing else.
  • Row three to row four: adjusting for the measured L pulls 1.34 to 1.01. Better, but still far from the truth — because the unmeasured U is still there.
  • Row three to row five: switch to an active comparator (new users of A against new users of B). Neither row adjusts for any covariate; changing the comparator alone moves the estimate from 1.34 to 0.93 — U cancelled between the arms without a single extra covariate being adjusted for. (Row four’s 1.01 is adjusted for L and so cannot be compared with row five: that would change two things at once.)
  • Rows six and seven: deal with L as well, by regression adjustment or by IPTW, giving 0.79 and 0.78, with confidence intervals covering the true value of 0.80.

Time zero: three timelines

Three timelines for the same patient, who starts treatment in month 46 and dies in month 70. On the first, time zero is month 24 and months 24 to 46 are marked as immortal time; on the second and third, time zero is month 46.
One patient, three designs. The yellow stretch on the first timeline is immortal time — during it he had not yet started the drug, yet it is already counted as treated follow-up. The second and third pin time zero to the moment treatment starts, and the yellow stretch disappears.Plotting script figures/scripts/B6-06-target-trial.R

Time zero has to satisfy three conditions at once, and this is the framework’s most practical single check:

  1. Eligibility is fully determined at that moment — no information that only arrives later.
  2. The treatment strategy is assigned at that moment — you cannot wait to find out later which arm someone belongs to.
  3. Follow-up begins at that moment — and all three must be the same instant.

Misalign them and bias follows. The new-user design works precisely because “the first dispensing of this drug” satisfies all three at once.

How this page ties the previous five together

Every cell of the seven-component form draws on one of the earlier pages:

Target trial componentWhat supplies it in observational data
Eligibility settled at time zeroNew-user design; the landmark analysis on the censoring page is an alternative repair
Treatment strategy spelled outDefine dose, duration, and how stopping and switching count; where competing risks are in play, settle the endpoint first
Assignment treatable as randomAnother name for conditional exchangeability — which variables to condition on is a DAG question, and it is only one of the three identifiability assumptions
Implementing the assignmentMatching and weighting; when the covariates were never measured, only instrumental variables remain
Choosing the comparatorActive comparator; part of the residual confounding discussed in the cohort chapter is designed away here
Follow-up periodThe three conditions on time zero; immortal time bias
Causal contrast and analysisITT or per-protocol; per-protocol has to handle exposure that changes over time, which is what the marginal structural model page covers

There is also a diagonal connection: self-controlled designs are a different answer to the question of where the control comes from — inside the same person. They need no active comparator and no propensity score, because they never make a between-person comparison in the first place. That is where triangulation earns its keep: two designs whose assumptions barely overlap agreeing on an answer is more persuasive than any single analysis.

When a target trial cannot be emulated

One side effect of this framework is that it will tell you when a question cannot be answered with the data you have. Three common cases:

  • Time zero is invisible in the data. Suppose you want to study the effect of taking up exercise, but no field records the day a person started — there is no time zero, and any grouping will be retrospective.
  • Eligibility requires future information. “Patients who stayed on the drug for a year” can only be determined by surviving a year; that is not an eligibility criterion, it is an outcome.
  • There is no reasonable active comparator. The drug is first in class, or the only possible control arm is no treatment. Unmeasured confounding by indication then cannot be escaped, and all you can do is quantify it honestly with a sensitivity analysis (an E-value, say).

“It cannot be answered” is a result too, and a far more valuable one than a structurally flawed analysis pushed through. It usually points to a different question, a different dataset, or a different design.

Why this page recommends no videos

As with self-controlled designs, this topic has no teaching-level video in any language — nothing at all in Chinese, and in English only three lecture recordings of between fifty-seven and eighty minutes. This site does not list videos of insufficient quality just to have some.

If you want to watch one, the most authoritative is Target Trial Emulation, given by Miguel Hernán himself (80 minutes); the other two are from Northwestern Feinberg (58 minutes) and NIHR RSS (57 minutes). All three assume you already know Cox models and IPTW, so they repay reading B6-01 through B6-05 first.

In print, the way in is Hernán and Robins’ original methodological paper (Am J Epidemiol 2016), together with the explanatory series that followed in JAMA and the BMJ.

Common misuses

MisuseWhy it is wrong
Saying “we performed a target trial emulation” without showing the seven-component tableThe table is where all the value of the framework sits; without it, it is a slogan
Leaving time zero undefinedThe three conditions — eligibility, assignment, start of follow-up — must fall at the same instant
Grouping at baseline by “used the drug at any point during follow-up”Immortal time bias; see B3-01
Enrolling people already on the drug when the window opens into the treated armPrevalent user bias: the susceptible have already been depleted
Using “people who did not take the drug” as the control without discussing confounding by indicationThose people are the ones a clinician judged did not need treating
Using future information in the eligibility criteriaThat is not eligibility, it is an outcome
Not stating whether ITT or per-protocol is being estimatedThey answer different questions and are analysed differently
A per-protocol analysis that ignores stopping and switchingThat needs time-varying weighting, not the exclusion of non-adherent patients
Trusting the design because the estimate looks plausibleBiases in opposite directions cancel; row two of this page is the demonstration
Using target trial emulation in place of a discussion of unmeasured confoundingThe framework repairs design errors, not unmeasured confounding
Writing a non-significant result as “the two drugs are equally effective”It means this analysis did not detect a difference

Reproducing every number on this page

/opt/homebrew/bin/Rscript figures/scripts/B6-06-target-trial.R

Read the figure

The answer comes from the same statistical output that produced this page's figures, not from a number typed in beside them.

Row two carries immortal time bias and estimates 0.78, against a true hazard ratio of 0.80 in the simulation. Which sentence explains why row two lands so close to the truth?

Show the answer and why

Correct answer: The same two groups with time zero pinned back to the day treatment starts give 1.34 — two biases running in opposite directions cancelled

Rows two and three use exactly the same two groups and differ only in time zero: row three starts the treated arm's clock at the moment treatment begins, row two starts it when the study window opens, so a long stretch of not yet treated person-time is credited to the treated arm's follow-up. That single change moves the hazard ratio from 1.34 to 0.78, so the flaw is neither small nor inert. Row two lands near the truth of 0.80 because confounding by indication, which pushes the estimate up, and immortal time, which pushes it down, happen to cancel; the upper limit of 0.93 sitting below one is a by-product of that cancellation. The target trial version arrives at the same number, but it got there by removing three design errors one at a time, and the two are not equally credible. Bias is removed by design, not judged by whether the result looks plausible.

The naive analysis in row one gives 1.13 and the unadjusted new-user analysis in row three gives 1.34. Row one is closer to one. Which sentence describes that?

Show the answer and why

Correct answer: Row one starts every clock at the study window, crediting 21125 person-months of immortal time to the treated arm — closer to one and more wrong

The trouble with row one is not how far it sits from one but that it commits three errors at once: prevalent users are kept, the clock starts at the study window rather than at treatment initiation (21125 person-months of immortal time credited to the treated arm), and confounding by indication sits on top. The three biases point in different directions and their tug of war produces a mild-looking 1.13. Row three commits only the confounding, which makes 1.34 the more honest number. The 1133 extra prevalent users are not a gain in precision — they are a selected group, and adding them buys a narrower interval around a larger bias. The 1685 is the number of people excluded for having used the other drug; that exclusion should be reported, but removing everyone who ever took the other drug also removes the only people who could serve as an active comparator. Closer to one has never been a way to judge bias.

Going from row three to row five changes exactly one thing: the comparator becomes new users starting the other drug in the same period instead of untreated people, with no extra covariate adjusted. The estimate falls from 1.34 to 0.93. Why?

Show the answer and why

Correct answer: Because unrecorded frailty differs by only -0.082 of a standard deviation between the two drugs; it affects who gets treated, not which drug they get

An active comparator works because the unmeasured confounder no longer differs between the two treatment groups: treated and untreated people differ by 0.492 of a standard deviation in frailty, while people on the two drugs differ by only -0.082, because the unrecorded variable affects whether someone is treated and not which drug they receive. The 0.492 is that treated-versus-untreated gap rather than a residue left after the comparator changed — it is row three's pathology, not row five's achievement. The 0.649 is the gap in recorded severity between the two drugs, which changing comparator did not address; rows six and seven, with adjustment and weighting, are what address it. What the comparator swap replaced is the thing you cannot measure.

Time zero has to do three things at once: settle eligibility, assign the treatment strategy, and start follow-up. Where does row three fail to do them?

Show the answer and why

Correct answer: The untreated arm contains 1778 people who start treatment later, their pre-treatment person-time counted as untreated, so the two arms do not share a time zero

Row three pins the treated arm's clock to the month treatment began, while the untreated arm's clock is pinned to the moment the study window opened, so the two arms do not share a time zero. On top of that, 1778 people in the untreated arm start treatment later; their pre-treatment person-time is counted as untreated and censored only in the month they start, with no weighting to handle that censoring, so one person's different stretches appear in both arms. The 870 is the size of row three's treated arm, which did align all three conditions — but one arm getting it right is not alignment, and the problem is in the other arm. The 6777 is everyone alive when the window opened, the starting point for row one's selection rather than the size of row three's comparator arm, so citing it points at the wrong row. Doing this properly means treating each month as its own small trial with risk-set sampling, and handling switching or stopping with clone-censor-weight.

Row four adjusts for measured severity and moves the estimate from 1.34 to 1.01, still far from the truth of 0.80. Which sentence describes the distance row four has left?

Show the answer and why

Correct answer: Row five estimates 0.93 with no covariate adjusted at all, so what moved the estimate was the comparator, not the adjustment

Row four adjusts for recorded severity, while what pushes the estimate off is unrecorded frailty — a variable that is not in the dataset, so no statistical adjustment can reach it. Both 1.01 and the upper limit of 1.20 remain on the right of one, and the remaining distance is not a matter of covariates not yet added: everything the data holds is already in. What moves the estimate is row five's change of comparator, which reaches 0.93 with nothing extra adjusted, because the unmeasured confounder cancels between the two treatment groups; row six's 0.79 comes from adjusting after the comparator has already been swapped, and reading it as the reward for more adjustment credits the wrong step. The target trial framework handles immortal time, prevalent users and the missing active comparator — three design errors. Unmeasured confounding needs something else: an active comparator, a self-controlled design, or an instrumental variable.

Row one contains 1133 prevalent users, people already on the drug before the study window opened. What is wrong with keeping them in?

Show the answer and why

Correct answer: 1338 people in the cohort started the drug before the window, and row one caught only 1133 of them; the shortfall is where the selection happened

Taking people who are already on the drug when the window opens into the treated arm means taking people who have been on it a while and are still fine. The cohort holds 1338 people who started before the window, and row one caught only 1133 of them; the couple of hundred in between died before the window opened, which is exactly the group that ran into trouble early on the drug, and they never had a chance to enter the analysis. This is depletion of susceptibles, and it makes the drug look systematically safer than it is. It is not a sample-size problem: nobody among row one's 5092 people is counted twice, that number is what survived the selection rather than a list needing de-duplication, and the missing group was never observed at all, so no arithmetic recovers it. The 2208 is everyone who ever took the drug, and taking all of them in does not undo the selection, it only makes it more thorough. The fix is a new-user design: time zero at initiation, and only people who had not used the drug before it — the reason a trial cannot suffer this bias is that a trial enrols only people who have not started.

Sources and licences

This page is original writing

Report a content problem

The statistics on this site are written by AI and reviewed by AI; a human only spot-checks. What you can see may be what we cannot.

The more specific, the more fixable — e.g. which sentence disagrees with which textbook or paper.

Needed only if you want a reply; reports without it are still read.

Sent along with your report

These are attached automatically. You can drop any of them.