Skip to content

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

License

Notifications You must be signed in to change notification settings

Novartis/Causal-inference-in-RCTs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 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 conditional_marginal and hypothetical_estimand folders are based on simulated toy datasets and will not match the results from the short courses. The numerical results in the heart_transplant folder 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 repo, we implemented the following approaches:

  • Conditional treatment effect point estimate and SE using Huber-White robust “sandwich” estimator

  • Marginal treatment effect point estimate using standardization

  • SE of marginal treatment effect using

How to run the scripts

The utilized functions to calculated the conditional and marginal estimates are in conditional_marginal/funs/funs.R. A wrapper function summary_Estimate could be used to obtain the conditional and marginal estimates with corresponding SE calculated in different ways. It can be called by summary_Estimate(data=data, formula = as.formula("y ~ trt + X1"), nsim = 1000, trt.var = "trt", type = "OR"), where

  • data is the data frame including treatment factor and covariates of used samples

  • formula specifies the response, treatment variable and adjusted covariates

  • nsim is the number of bootstrap replicates when calculating SE for marginal estimate

  • trt.var is the name of treatment variable

  • type is the used estimator, "OR" for odds ratio and "RD" for risk difference.

To run the demo, first run source("conditional_marginal/src/01_gen_data.R"), which will generate the toy dataset using benchtm package. The toy dataset has 500 samples randomised to pbo (0) or treatment (1) arm with 10 covariates. And the response is generated using logit(p) = 0.5*(X1=='Y') + 1*X3 + 0.3*trt. Therefore, there are two prognostic covariates, X1 and X3.

Then source("conditional_marginal/src/02_analysis.R") gives the conditional and marginal estimates. And here we compare

  • unadjusted, Y ~ trt

  • adjusted with one moderate prognostic factor Y ~ trt + X1

  • adjusted with one moderate and one strong prognostic factor Y ~ trt + X1 + X3

  • adjusted with both prognostic factors and an unrelated factor Y ~ trt + X1 + X3 + X8

Both odds ratio and risk difference estimates will be calculated and saved in conditional_marginal/output/Result_condi_margin_OR.csv and conditional_marginal/output/Result_condi_margin_RD.csv respectively.

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

Languages