Lab 1 — Instructor answer key
Companion files: completed scripts (01–05 in this folder).
Contents: completed TARGET table · TODO code answers · expected checkpoints · expected QC output · model answers Q1–Q13 · grading notes
Completed TARGET 6a–6f table
| Item | Hypothetical target trial | eICU emulation |
|---|---|---|
| 6a Eligibility | Adults (≥18) in an ICU, enrolled at the moment of a first hypotensive episode (first MAP <65 mmHg during the ICU stay); not on a vasopressor at any time before that moment (new users); first ICU admission of the hospitalization. (After the landmark is introduced, effectively also: alive and in the ICU 60 min later.) | patient: age ≥18 ("> 89"→90), unitvisitnumber == 1. Index event: first plausible MAP (30–150 mmHg, offset ≥0) below 65, from invasive vitalPeriodic.systemicmean or cuff vitalAperiodic.noninvasivemean. New-user: no qualifying infusiondrug row before time_zero_offset. Landmark: unitdischargeoffset ≥ time_zero_offset + 60. |
| 6b Treatment strategies | (1) Early initiation: begin norepinephrine, epinephrine, phenylephrine, vasopressin, or dopamine within 60 min of hypotension onset (60-min grace period is part of the strategy). (2) No early initiation: none within 60 min; later initiation per usual care allowed. | Case-insensitive regex over infusiondrug.drugname (generic + brand names); early_vasopressor = 1 iff first qualifying infusionoffset ∈ [t0, t0+60]. |
| 6c Assignment | 1:1 randomization at hypotension onset; open-label (participants and clinicians aware; no placebo infusion). | No assignment exists; patients classified by observed initiation in the window. Comparability rests on conditional exchangeability given baseline covariates (not considered in this lab). Classification is not even determinable until the window closes, reflecting an alignment problem. |
| 6d Follow-up | From assignment (= time zero, hypotension onset) to hospital discharge or in-hospital death. | Landmark emulation: follow-up runs from landmark_offset = time_zero_offset + 60 to hospitaldischargeoffset. Landmark restores classification-before-follow-up at the cost of restricting to 60-min survivors. |
| 6e Outcome | Primary: in-hospital death. Secondary/retained: time from start of follow-up to death or live discharge. | hospital_death from hospitaldischargestatus (“Expired”=1, “Alive”=0, blank=NA; 18 NAs kept, not dropped); death_event + followup_days = (hospitaldischargeoffset − landmark_offset)/1440. |
| 6f Causal contrast | ITT-analog: risk of in-hospital death had all eligible patients initiated early vs. had none initiated early; risk difference and/or risk ratio. | Same contrast among the classified groups in the landmark population; stated only — no estimation in this lab. |
TODO code answers
| TODO | Answer |
|---|---|
| 1a | filter(age_num >= 18, unitvisitnumber == 1); The NA-comparison behavior of filter() drops the 4 missing ages |
| 1b | filter(map >= 30, map <= 150, observationoffset >= 0) |
| 1c | filter(map < 65) … distinct(patientunitstayid, .keep_all = TRUE) |
| 2a | "norepinephrine\|levophed\|epinephrine\|adrenalin\|phenylephrine\|neo.?synephrine\|vasopressin\|pitressin\|dopamine". accept any pattern passing the test battery; e.g. omitting norepinephrine still works because epinephrine matches inside it (worth discussing) |
| 2b | filter(is.na(first_vaso_before_t0)) |
| 2c | first_vasopressor_offset = first_vaso_after_t0; condition first_vasopressor_offset <= time_zero_offset + 60 |
| 3a | landmark_offset = time_zero_offset + 60; filter(unitdischargeoffset >= landmark_offset) |
| 3b | "Expired" ~ 1L, "Alive" ~ 0L (blanks fall to .default = NA_integer_; note read_csv reads the blank statuses as NA, which also lands in .default) |
| 3c | followup_days = (hospitaldischargeoffset - landmark_offset) / 1440; the conceptual blank; time_zero_offset here is the misalignment error |
| 5a | sum(analytic$first_vasopressor_offset < analytic$time_zero_offset, na.rm = TRUE) and sum(analytic$early_vasopressor == 1 & analytic$first_vasopressor_offset > analytic$landmark_offset, na.rm = TRUE) |
| 5b | sum(analytic$followup_days <= 0) |
Expected checkpoints
01: Adult first-ICU stays: 2111
01: Eligible stays written ...: 1378
02: drugname pattern: all tests pass
02: Vasopressor infusion rows: 7454 in 245 stays
02: After new-user criterion: 1308 (70 prevalent users excluded)
03: At the landmark: 1292 stays (16 excluded)
03: ... early initiators: 27
04: Analytic dataset written: 1292 rows, 13 columns
Expected QC output
Verbatim from solutions/05_qc.R on the demo data:
==================== QC REPORT ====================
1. Participant flow (a real report would draw this — TARGET item 8):
eligible w/ index hypotension (01) 1378
+ no vasopressor before time zero (02) 1308
+ alive & in ICU at 60-min landmark (03) 1292
analytic dataset (04) 1292
2. Strategy classification:
# A tibble: 2 × 3
early_vasopressor n pct
<dbl> <int> <dbl>
1 0 1265 97.9
2 1 27 2.1
3. Outcome:
in-hospital deaths: 136 of 1274 with a recorded status; missing status: 18
4. Uniqueness:
[PASS] duplicated patientunitstayid violations: 0
5. Binary coding:
[PASS] early_vasopressor not in {0, 1} violations: 0
[PASS] hospital_death not in {0, 1, NA} violations: 0
6. Treatment timing:
[PASS] first_vasopressor_offset before time zero violations: 0
[PASS] early initiator with initiation after landmark violations: 0
7. Follow-up:
[PASS] followup_days <= 0 violations: 0
[note] hospital discharge before ICU discharge (source records): 17
followup_days summary (days):
Min. 1st Qu. Median Mean 3rd Qu. Max.
0.004167 1.704688 3.854861 5.874380 7.667187 99.260417
8. Missingness in the analytic dataset:
# A tibble: 5 × 2
variable n_missing
<chr> <int>
1 age 0
2 sex 0
3 baseline_map 0
4 baseline_hr 3
5 hospital_death 18
==================== END QC =======================
Some context: crude mortality is 6/27 (22.2%) among early initiators vs 130/1,265 (10.3%), this is very likely confounding by indication, which is essential to consider but not discussed in this lab.
Model answers, Q1–Q13
Q1. What event defines eligibility in the hypothetical trial? The first hypotensive episode, which is the first time an adult, first-ICU-stay patient not already on a vasopressor experiences MAP <65 mmHg. That moment is enrollment and time zero: eligibility is assessed at it, using only information available by it.
Q2. What eICU data are being used to emulate that event? The first plausible (30–150 mmHg) MAP below 65 at ICU offset ≥0, taken from either the arterial-line series (vitalPeriodic.systemicmean) or the cuff series (vitalAperiodic.noninvasivemean), whichever occurs first. Strong answers note the imperfection (TARGET 7a): this is the first measured hypotension, not the first true hypotension, cuff readings are ~19 min apart at the median, so true onset precedes time zero by an unknown amount; and the plausibility window is an outcome-blind measurement-validity rule. Additionally, there is information to assess measurement error here that we ignore (comparision btw arterial line versus cuff measurements).
Q3. What are the two treatment strategies? (1) Initiate one of the five vasopressors within 60 minutes of time zero; (2) do not initiate within 60 minutes, with later initiation per usual care permitted. The 60-minute grace period is part of the strategy definition (6b), but “no early initiation” ≠ “never treated”. In fact, 108 patients in the final cohort initiate after the window and are correctly in strategy (2).
Q4. How would treatment assignment work in the hypothetical randomized trial? 1:1 randomization at the moment of eligibility (hypotension onset), open-label. Patients and clinicians would know the assignment, since blinding a titrated infusion is impractical. Randomization makes the arms exchangeable in expectation and fixes each patient’s group at time zero.
Q5. Why is observed treatment initiation not equivalent to randomized assignment? Initiation is a clinical decision made because of the patient’s state, which includes depth and trajectory of hypotension, perceived reversibility, goals of care. So, the classified groups differ systematically in prognosis (confounding by indication, which likely explains the 22% vs 10% crude mortality in treated verus non-treated). Mechanically, classification is not even determined at time zero: it depends on what happens during the following hour, which is what forces the landmark (or clone censor weighting or time-dependent analyses).
Q6. When does follow-up begin in our emulation? At the landmark, landmark_offset = time_zero_offset + 60, not at the hypotensive measurement.
Q7. Why does it begin at the landmark rather than at the first hypotensive measurement? Because classification uses the window [t0, t0+60]. Starting follow-up at t0 would define groups with future information: early initiators cannot die between t0 and their initiation (immortal time credited to the treated arm), while a patient dying mid-window without an infusion can only be classified “no early initiation” (early deaths would be classified into the untreated arm). Starting follow-up when classification is complete restores the lecture’s alignment rule, but at the potentially costly price that the emulated trial now enrolls only 60-minute survivors.
Q8. What ends follow-up? Hospital discharge: in-hospital death (the event) or discharge alive (which ends our ability to observe the outcome). Full treatment of discharge-as-censoring and competing events is deferred to the survival weeks.
Q9. Why does defining “treated” as initiation sometime during the next 60 minutes create a problem if follow-up begins immediately at hypotension? Group membership then depends on events after follow-up starts. The treated group’s person-time between t0 and initiation is immortal by construction, and the earliest deaths are forced into the untreated group, biasing the comparison in favor of early initiation even under a true null. (Full credit requires the mechanism — conditioning group membership on the future — not just the phrase “immortal time bias.”)
Q10. How would CCW address this differently from our landmark solution? The landmark moves time zero to t0+60 and drops non-survivors of the window; CCW keeps time zero at t0 and keeps everyone. Each eligible patient is cloned into both strategies (their data are compatible with both at t0); a clone is artificially censored the moment observed behavior deviates from its assigned strategy (no initiation by minute 60 censors the “early” clone; initiation within the window censors the “no early” clone); and inverse-probability-of-censoring weights correct the selection that this artificial censoring induces. Alignment holds with follow-up from t0, the population is unchanged, and the price is paid in censoring models and weights instead of in a changed population.
Q11. What two counterfactual treatment strategies are being compared? The risk of in-hospital death if everyone in the (landmark) population had initiated a vasopressor within 60 minutes of hypotension onset versus if no one had initiated within 60 minutes (with later initiation per usual care in both worlds).
Q12. How does the landmark restriction change the population represented by that contrast? The contrast now refers only to patients who survive and remain in the ICU (observable) through the first 60 minutes after hypotension onset — here 1,292 of 1,308 new users; patients who die or leave within the hour are outside the estimand’s population. The clinical question was posed at hypotension onset; the landmark answers it for a slightly healthier, slightly later population, and nothing guarantees the gap stays small in other settings or with longer landmarks.
Q13. How would the target trial differ if CCW rather than landmarking were used to handle the grace period? 6d: follow-up starts at assignment = hypotension onset itself, for every eligible patient. 6a: no 60-minute-survivor criterion. 6c/7c: assignment is emulated by cloning (classification into both compatible strategies) rather than by single classification at the window’s end. 6b is unchanged because the grace period remains part of the strategy. The identification burden shifts: instead of accepting a restricted population, we must correctly model the artificial-censoring process to estimate the weights.
Understanding notes
- The key answers are Q5, Q7/Q9 (same mechanism, asked twice from different angles, students should try to connect them), Q10, and Q12. Look for mechanisms (conditioning on the future; who absorbs the early deaths; what re-weights what).
- TARGET table: right column should name actual data tables/columns and at least one mapping imperfection (measured vs true onset; free-text drug names; blank discharge statuses).