This repository contains code examples for several methods in a Causal Inference in RCTs short course. Novartis associates and external collaborators presented the short course at the following conferences:
- ICSA 2023 Applied Statistics Symposium
- Joint Statistical Meetings 2023
- ASA Biopharmaceutical Section Regulatory-Industry Statistics Workshop 2023
- CEN 2023
- Australian Pharmaceutical Biostatistics Group 2024
- International Society for Biopharmaceutical Statistics 2024
- PSI 2024
- Joint Statistical Meetings 2024
- International Biometric Conference 2024
- Joint Statistical Meetings 2025
For data privacy reasons,
the numerical results in the hypothetical_estimand
folder are based on simulated toy datasets and will not
match the results from the short courses.
The numerical results in the heart_transplant
and conditional_marginal
folders
will match the results from the short courses.
Conditional and marginal effects (conditional_marginal
)
This folder contains example code for the "conditional and marginal treatment effect" lecture of the short course.
In this repository, we implemented the following approaches:
-
Conditional treatment effect point estimates and SEs using Huber-White robust "sandwich" estimator.
-
Marginal treatment effect point estimates and SEs using Ye et al. (2023) semiparametric approaches implemented in RobinCar2 package
-
Functions from previous lectures, available in conditional_marginal/funs/old_funs.R estimate the SE of the marginal treatment effect via the following approaches:
- Nonparametric bootstrap method (Efron and Tibshirani, 1994)
- Delta method
- Parametric bootstrap method (Aalen et al., 1998).
To run the demo, first run conditional_marginal/src/01_gen_data.R,
which will generate the toy dataset using the benchtm
package.
The toy dataset has 500 samples randomized to placebo (0
) or treatment (1
) arm with 10 covariates. The binary response is generated from the model
logit(p) = 1*(X1=='Y') + 0.3*X2 + 0.3*trt
. Therefore, there are two prognostic covariates, X1
and X2
. This script saves the generated data to
conditional_marginal/data/toy_data.rds.
The data are also stored in the repository to ensure reproducibility.
Second, conditional_marginal/src/02_analysis.R estimates the marginal and conditional treatment effects on both the risk difference and odds ratio scales. This script compares treatment effects under the following adjustment models:
-
unadjusted,
Y ~ trt
-
adjusted with one prognostic factor
Y ~ trt + X1
-
adjusted with two prognostic factors
Y ~ trt + X1 + X2
.
Heart transplant example (heart_transplant
)
This folder contains two approaches to estimate the average causal effect on the risk difference scale (E[Y(1) - Y(0)]) for a binary treatment Z, a binary covariate X, and a binary outcome Y. The data example in these scripts is modified from the heart transplant example in Chapter 1 of Hernán and Robins (2020).
-
gcomp.R
: Example of G-computation to estimate E[Y(1) - Y(0)] and bootstrapping to construct a confidence interval. -
ipw.R
: Example of inverse probability weighting to estimate E[Y(1) - Y(0)] and bootstrapping to construct a confidence interval.
Hypothetical estimand example (hypothetical_estimand
)
This folder contains two approaches to estimate a hypothetical estimand. Suppose Y is an outcome, Z_0 indicates initial treatment assignment, and Z_1 indicates a switch to rescue medication. Let Y(z_0, z_1) represent the potential outcome under treatment assignment Z_0 = z_0 and rescue medication use indicated by Z_1 = z_1. These examples estimate E[Y(1,0) - Y(0,0)], which represents the average treatment effect in a hypothetical trial without the possibility of switching to rescue medication. This approach uses methods from Parra, Daniel, and Bartlett (2022).
-
hypothetical_gcomp.R
: Example of G-computation to estimate E[Y(1,0) - Y(0,0)] and bootstrapping to construct a confidence interval. -
hypothetical_ipw.R
: Example of inverse probability weighting to estimate E[Y(1,0) - Y(0,0)] and bootstrapping to construct a confidence interval.
We list all packages that are required to run scripts within this repository.
Unless otherwise specified, packages can be installed from CRAN by using
install.packages()
.
benchtm
: Install by runningdevtools::install_github("Sophie-Sun/benchtm")
.data.table
future.apply
lmtest
mgcv
progress
sandwich
tidyverse
- Markdown document with code examples for the principal stratum estimation approaches from Bornkamp et al. (2021). Created by Björn Bornkamp and Kaspar Rufibach.
- Robin Dunn, robin.dunn@novartis.com
- Jiarui Lu, jiarui.lu@novartis.com
- Tianmeng Lyu, tianmeng.lyu@novartis.com
- Tobias Muetze, tobias.muetze@novartis.com
- Cong Zhang, cong.zhang@novartis.com