{"id":15118967,"url":"https://github.com/Novartis/Causal-inference-in-RCTs","last_synced_at":"2025-09-28T01:31:37.382Z","repository":{"id":173202312,"uuid":"650309677","full_name":"Novartis/Causal-inference-in-RCTs","owner":"Novartis","description":"This repository contains code examples for several methods in a Causal Inference in RCTs short course. ","archived":false,"fork":false,"pushed_at":"2025-07-31T15:57:34.000Z","size":85,"stargazers_count":26,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-07-31T19:17:21.704Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Novartis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-06-06T19:50:04.000Z","updated_at":"2025-07-31T15:57:38.000Z","dependencies_parsed_at":"2024-06-07T20:25:43.673Z","dependency_job_id":"da807fdb-d978-4541-8e61-50f94cd6460d","html_url":"https://github.com/Novartis/Causal-inference-in-RCTs","commit_stats":null,"previous_names":["novartis/causal-inference-in-rcts"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Novartis/Causal-inference-in-RCTs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Novartis%2FCausal-inference-in-RCTs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Novartis%2FCausal-inference-in-RCTs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Novartis%2FCausal-inference-in-RCTs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Novartis%2FCausal-inference-in-RCTs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Novartis","download_url":"https://codeload.github.com/Novartis/Causal-inference-in-RCTs/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Novartis%2FCausal-inference-in-RCTs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":277315117,"owners_count":25797567,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-27T02:00:08.978Z","response_time":73,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-26T01:53:41.153Z","updated_at":"2025-09-28T01:31:37.375Z","avatar_url":"https://github.com/Novartis.png","language":"R","funding_links":[],"categories":["Ranked by starred repositories"],"sub_categories":[],"readme":"# Causal inference in RCTs\n\nThis repository contains code examples for several methods in a \nCausal Inference in RCTs short course. \nNovartis associates and external collaborators presented the\nshort course at the following conferences:\n\n- [ICSA 2023 Applied Statistics Symposium](https://www.icsa.org/icsa-2023-applied-statistics-symposium/)\n- [Joint Statistical Meetings 2023](https://ww2.amstat.org/meetings/jsm/2023/)\n- [ASA Biopharmaceutical Section Regulatory-Industry Statistics Workshop 2023](https://ww2.amstat.org/meetings/biop/2023/)\n- [CEN 2023](https://cen2023.github.io/home/)\n- [Australian Pharmaceutical Biostatistics Group 2024](https://apbg.org.au/apbg-events/)\n- [International Society for Biopharmaceutical Statistics 2024](https://www.isbiostat.org/)\n- [PSI 2024](https://www.psiweb.org/conferences/about-the-conference)\n- [Joint Statistical Meetings 2024](https://ww2.amstat.org/meetings/jsm/2024/)\n- [International Biometric Conference 2024](https://www.ibc2024.org/home)\n- [Joint Statistical Meetings 2025](https://ww2.amstat.org/meetings/jsm/2025/)\n\nFor data privacy reasons, \nthe numerical results in the [`hypothetical_estimand`](hypothetical_estimand) folder are based on simulated toy datasets and will not\nmatch the results from the short courses. \nThe numerical results in the [`heart_transplant`](heart_transplant) and [`conditional_marginal`](conditional_marginal) folders\nwill match the results from the short courses.\n\n# Repository contents\n\n## Conditional and marginal effects ([`conditional_marginal`](conditional_marginal))\n\nThis folder contains example code for the \n\"conditional and marginal treatment effect\" lecture of the short course.\n\nIn this repository, we implemented the following approaches:\n\n  * Conditional treatment effect point estimates and SEs using Huber-White \n  robust \"sandwich\" estimator. \n  * Marginal treatment effect point estimates and SEs using \n  [Ye et al. (2023)](https://pmc.ncbi.nlm.nih.gov/articles/PMC10665030/)\n  semiparametric approaches implemented in \n  [RobinCar2 package](https://cran.r-project.org/package=RobinCar2)\n  * Functions from previous lectures, available in \n  [conditional_marginal/funs/old_funs.R](conditional_marginal/funs/old_funs.R) estimate the \n  SE of the marginal treatment effect via the following approaches:\n    \n      * Nonparametric bootstrap method ([Efron and Tibshirani, 1994](https://www.taylorfrancis.com/books/mono/10.1201/9780429246593/introduction-bootstrap-bradley-efron-tibshirani)) \n      * Delta method\n      * Parametric bootstrap method ([Aalen et al., 1998](https://onlinelibrary.wiley.com/doi/10.1002/(SICI)1097-0258(19971015)16:19%3C2191::AID-SIM645%3E3.0.CO;2-5)).\n\n### How to run the scripts\n\nTo run the demo, first run [conditional_marginal/src/01_gen_data.R](conditional_marginal/src/01_gen_data.R), \nwhich will generate the toy dataset using the `benchtm` package.\nThe toy dataset has 500 samples randomized to placebo (`0`) or treatment (`1`) arm with 10 covariates. The binary response is generated from the model \n`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\n[conditional_marginal/data/toy_data.rds](conditional_marginal/data/toy_data.rds). \nThe data are also stored in the repository to ensure reproducibility. \n\nSecond, [conditional_marginal/src/02_analysis.R](conditional_marginal/src/02_analysis.R) estimates the \nmarginal and conditional treatment effects on both the risk difference and \nodds ratio scales. This script compares treatment effects under the following adjustment models:\n\n* unadjusted, `Y ~ trt`\n\n* adjusted with one prognostic factor `Y ~ trt + X1`\n\n* adjusted with two prognostic factors `Y ~ trt + X1 + X2`.\n\n## Heart transplant example ([`heart_transplant`](heart_transplant))\n\nThis folder contains two approaches to estimate \nthe average causal effect on the risk difference scale (E[Y(1) - Y(0)]) for\na binary treatment Z, a binary covariate X, and a binary outcome Y.\nThe data example in these scripts is modified from the heart transplant example\nin Chapter 1 of \n[Hernán and Robins (2020)](https://www.hsph.harvard.edu/miguel-hernan/causal-inference-book/).\n\n- [`gcomp.R`](heart_transplant/gcomp.R): Example of G-computation to estimate\nE[Y(1) - Y(0)] and bootstrapping to construct a confidence interval.\n\n- [`ipw.R`](heart_transplant/ipw.R): Example of inverse probability weighting\nto estimate E[Y(1) - Y(0)] and bootstrapping to construct a confidence \ninterval.\n\n## Hypothetical estimand example ([`hypothetical_estimand`](hypothetical_estimand))\n\nThis folder contains two approaches to\nestimate a hypothetical estimand. Suppose Y is an outcome, Z_0 indicates \ninitial treatment assignment, and Z_1 indicates a switch to rescue medication.\nLet Y(z_0, z_1) represent the potential outcome under treatment assignment\nZ_0 = z_0 and rescue medication use indicated by Z_1 = z_1.\nThese examples estimate E[Y(1,0) - Y(0,0)], which represents the average\ntreatment effect in a hypothetical trial without the possibility of switching \nto rescue medication. This approach uses methods from\n[Parra, Daniel, and Bartlett (2022)](https://www.tandfonline.com/doi/full/10.1080/19466315.2022.2081599).\n\n- [`hypothetical_gcomp.R`](hypothetical_estimand/hypothetical_gcomp.R): \nExample of G-computation to estimate E[Y(1,0) - Y(0,0)] and bootstrapping to \nconstruct a confidence interval.\n\n- [`hypothetical_ipw.R`](hypothetical_estimand/hypothetical_ipw.R):\nExample of inverse probability weighting to estimate E[Y(1,0) - Y(0,0)] and \nbootstrapping to construct a confidence interval.\n\n# Required packages\n\nWe list all packages that are required to run scripts within this repository.\nUnless otherwise specified, packages can be installed from CRAN by using\n`install.packages()`.\n\n- [`benchtm`](https://github.com/Sophie-Sun/benchtm): \nInstall by running `devtools::install_github(\"Sophie-Sun/benchtm\")`.\n- [`data.table`](https://cran.r-project.org/web/packages/data.table/index.html)\n- [`future.apply`](https://cran.r-project.org/web/packages/future.apply/index.html)\n- [`lmtest`](https://cran.r-project.org/web/packages/lmtest/index.html)\n- [`mgcv`](https://cran.r-project.org/web/packages/mgcv/index.html)\n- [`progress`](https://cran.r-project.org/web/packages/progress/index.html)\n- [`sandwich`](https://cran.r-project.org/web/packages/sandwich/index.html)\n- [`tidyverse`](https://cran.r-project.org/web/packages/tidyverse/index.html)\n\n# External links\n\n- [Markdown document](https://oncoestimand.github.io/princ_strat_drug_dev/princ_strat_example.html) with code examples for the principal stratum estimation approaches from [Bornkamp et al. (2021)](https://onlinelibrary.wiley.com/doi/10.1002/pst.2104). Created by Björn Bornkamp and Kaspar Rufibach.\n\n# Code authors\n\n- Robin Dunn, robin.dunn@novartis.com\n- Jiarui Lu, jiarui.lu@novartis.com\n- Tianmeng Lyu, tianmeng.lyu@novartis.com\n- Tobias Muetze, tobias.muetze@novartis.com\n- Cong Zhang, cong.zhang@novartis.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNovartis%2FCausal-inference-in-RCTs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FNovartis%2FCausal-inference-in-RCTs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNovartis%2FCausal-inference-in-RCTs/lists"}