EPID 785R

Labs

Labs are hands-on R sessions that provide an opportunity to practice deploying concepts learned in the lectures. Each lab has a handout you can read in the browser and a starter bundle (project file, scripts, and README) to download and work from. Lab deliverables are yours to keep; they are not collected or graded.

  • Opens the lab handout in the browser.
  • Downloads the starter files (zip).
  • Downloads the answer packet (answer key and completed scripts). Unzip it into your lab folder, next to the starter files.

Each starter bundle can be downloaded as a self-contained file that includes everything you need to run the lab. Material for later labs will be posted here as the course progresses. Datasets used in the lecture notes live on the Data page.

Lab 1: Emulating a Target Trial with ICU Data
Build an analytic dataset from the eICU demo database, from protocol and eligibility through exposure, outcome, and quality control.
Lab 2: The Case-Cohort Design
Draw a 20% subcohort plus all cases from the Lab 1 cohort, build the time-varying weights, and check weighted risk-curve, risk-ratio, and risk-difference estimates against the fully enumerated cohort.
Lab 3: Three Questions
Fit one logistic regression to the Lab 1 cohort before asking any question, then read the same printout three times — descriptively, predictively, and causally — writing down the estimand and the assumptions each reading needs.
Lab 4: Dissect a Regression Model
Turn one dial of one model at a time on the Lab 1 cohort: change the link (identity, log, logit) and compare fitted values; add an offset and watch a risk ratio become a rate ratio; fit death against age as a line, a spline, and a saturated model, and visualize the parametric-to-nonparametric spectrum.
Lab 5: Fit the GLM Family to a Single Outcome
Fit Lab 3's model as a logistic, log-binomial, Poisson (with and without the person-time offset), and linear probability model; watch which fits converge and what each reports for the exposure; compare predicted probabilities; fit death against age as a line, a spline, and a saturated model (carried over from Lab 4); then compute the logistic fit's residuals, leverage, and Cook's distance by hand.
Lab 6: Compute Variance Three Ways
No dataset this time: build a world in which the truth is known, compute the model-based and robust (HC0 to HC3) sandwiches by hand and with the sandwich package, see what R, Stata, and SAS each print by default for the same model, then draw thousands of samples to see which standard error matches the spread of the estimates, with and without heteroscedasticity; finish with the bootstrap by hand and with boot(), and put the bootstrap inside the simulation to check its coverage too.

eICU attribution. The Lab 1 bundle redistributes the eICU Collaborative Research Database Demo (v2.0.1), and the Lab 2, Lab 3, Lab 4, and Lab 5 bundles a dataset derived from it, under the Open Data Commons Open Database License v1.0. Please cite: Pollard T, Johnson A, Raffa J, Celi LA, Badawi O, Mark R. eICU Collaborative Research Database Demo (version 2.0.1). PhysioNet, 2021. doi:10.13026/4mxk-na84; and the companion paper: Pollard et al., Scientific Data 2018;5:180178. Documentation: eicu.mit.edu.