Skip to content

Novartis/Causal-inference-in-RCTs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Causal inference in RCTs

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:

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.

Repository contents

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:

How to run the scripts

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.

Required packages

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().

External links

Code authors

About

This repository contains code examples for several methods in a Causal Inference in RCTs short course.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages