- Notifications
You must be signed in to change notification settings - Fork1
📦R package medRCT
License
Unknown, MIT licenses found
Licenses found
T0ngChen/medRCT
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Causal mediation analysis estimating interventional effects mapped toa target trial
The R packagemedRCT
for causal mediation analysis supports theestimation of interventional effects (VanderWeele, Vansteelandt, andRobins 2014), specifically interventional effects that are defined suchthat they map explicitly to a “target trial” (Hernán and Robins 2016),as recently proposed by Moreno-Betancur et al. (2021). In the targettrial, the treatment strategies are specified to reflect hypotheticalinterventions targeting and thus shifting the joint distribution of themediators.medRCT
can accommodate any number of potentially correlatedmediators, including mediators that are not of primary interest but thatare intermediate (exposure-induced) mediator-outcome confounders.
ThemedRCT
package is not yet available on CRAN. You can install thelatest stable version fromGitHubusing the following command:
remotes::install_github("T0ngChen/medRCT")
Using a simulated dataset based on a published case study from theLongitudinal Study of Australian Children (Goldfeld et al. 2023), weillustrate how to usemedRCT
to estimate the interventional effectsthat emulate a target trial. Specifically, we aim to estimate thedifference in expected outcome (risk of child mental health problems)under exposure (low family socioeconomic position) with versus without ahypothetical intervention that individually shifts the distribution ofeach mediator (parental mental health and preschool attendance) to thelevels in the unexposed (high family socioeconomic position), whileaccounting for baseline confounders, an intermediate (exposure-induced)mediator-outcome confounder (family stressful life events), andcorrelations amongst mediators.
We begin by loading the library and dataset, and defining the confoundervector.
# Load the medRCT packagelibrary(medRCT)# Set a seed for reproducibilityset.seed(2025)# Display the first few rows of the datasethead(LSACdata)#> child_sex child_atsi mat_cob mat_engl mat_age sep fam_stress parent_mh preschool_att child_mh#> 1 0 1 0 0 1 0 0 0 1 0#> 2 NA 0 0 0 NA 0 NA NA 0 0#> 3 NA 0 0 0 NA 0 NA NA 0 1#> 4 NA 0 0 0 NA 0 NA NA 0 0#> 5 1 0 0 0 1 1 0 0 0 1#> 6 1 0 0 0 1 0 1 1 0 1#> child_SDQscore#> 1 8.924660#> 2 7.349826#> 3 12.824643#> 4 6.611369#> 5 10.329341#> 6 13.552515# Define confounders for the analysisconfounders<- c("child_sex","child_atsi","mat_cob","mat_engl","mat_age")
Next we run the analyses, estimating interventional effects for ahypothetical intervention that shifts the distribution of each mediatorindividually.Note 1: the dataset has missing data. Incompleterecords are by default deleted before the analysis.Note 2: It isrecommended to perform the analysis with at least 200 Monte Carlosimulations by settingmcsim = 200
. For illustration purposes, we usemcsim = 50
, which takes approximately 90 seconds to run.
# Estimate interventional effects for a hypothetical intervention# that shifts the distribution of each mediator individuallymed_res<- medRCT(dat=LSACdata,exposure="sep",outcome="child_mh",mediators= c("parent_mh","preschool_att"),intermediate_confs="fam_stress",# intermediate confoundersconfounders=confounders,bootstrap=TRUE,intervention_type="shift_k",mcsim=50 )#> Conducting complete case analysis, 2499 observations were excluded due to missing data.#> Note: It is recommended to run analysis with no fewer than 200 Monte Carlo simulations.# Summarise the resultssummary(med_res)#>#> Estimated interventional indirect effect:#>#> Estimate Std. Error CI Lower CI Upper p-value#> IIE_1 (p_trt - p_1) 0.011155 0.004181 0.002814 0.019203 0.0076#> IIE_2 (p_trt - p_2) -0.000763 0.002501 -0.005443 0.004362 0.7604#> TCE (p_trt - p_ctr) 0.128669 0.024554 0.082420 0.178668 1.6e-07#>#> Estimated interventional direct effect:#>#> Estimate Std. Error CI Lower CI Upper p-value#> IDE_1 (p_1 - p_ctr) 0.1175 0.0247 0.0712 0.1679 1.9e-06#> IDE_2 (p_2 - p_ctr) 0.1294 0.0244 0.0833 0.1789 1.1e-07#>#> Estimated expected outcome in each trial arm:#>#> Estimate Std. Error CI Lower CI Upper p-value#> p_1 0.3302 0.0225 0.2872 0.3755 <2e-16#> p_2 0.3421 0.0221 0.2995 0.3862 <2e-16#> p_ctr 0.2127 0.0100 0.1922 0.2315 <2e-16#> p_trt 0.3413 0.0223 0.2987 0.3860 <2e-16#>#> Sample Size: 2608#>#> Simulations: 50
Based on the estimated interventional effect (IIE_1), a hypotheticalintervention improving the mental health of parents of children fromfamilies with low socioeconomic position to the levels of those fromfamilies with high socioeconomic position could potentially prevent 1per 100 cases of child mental health problems. Meanwhile, the effect ofa hypothetical intervention on preschool attendance (IIE_2) isnegligible.
For detailed guidance on using the package to handle more complexscenarios, please refer to thevignette.
For work involving themedRCT
R package, please cite the following:
@software{Chen2024medRCT, author = {Tong Chen and Margarita Moreno-Betancur and S. Ghazaleh Dashti}, title = {medRCT: Causal mediation analysis estimating interventional effects mapped to a target trial}, year = {2025}, url = {https://t0ngchen.github.io/medRCT/}, note = {R package version 0.1.0} }@article{Moreno2021Mediation, author={Margarita Moreno-Betancur and Paul Moran and Denise Becker and George C Patton and John B Carlin}, title={Mediation effects that emulate a target randomised trial: Simulation-based evaluation of ill-defined interventions on multiple mediators}, journal={Statistical Methods in Medical Research}, volume={30}, number={6}, pages={1395--1412}, year={2021}, URL={https://doi.org/10.1177/0962280221998409}, doi={10.1177/0962280221998409}, publisher={SAGE Publications Ltd} }
Goldfeld, Sharon, Margarita Moreno-Betancur, Sarah Gray, Shuaijun Guo,Marnie Downes, Elodie O’Connor, Francisco Azpitarte, et al. 2023.“Addressing Child Mental Health Inequities Through Parental MentalHealth and Preschool Attendance.”Pediatrics 151 (5): e2022057101.https://doi.org/10.1542/peds.2022-057101.
Hernán, Miguel A, and James M Robins. 2016. “Using Big Data to Emulate aTarget Trial When a Randomized Trial Is Not Available.”AmericanJournal of Epidemiology 183 (8): 758–64.https://doi.org/10.1093/aje/kwv254.
Moreno-Betancur, Margarita, Paul Moran, Denise Becker, George C Patton,and John B Carlin. 2021. “Mediation Effects That Emulate a TargetRandomised Trial: Simulation-Based Evaluation of Ill-DefinedInterventions on Multiple Mediators.”Statistical Methods in MedicalResearch 30 (6): 1395–1412.https://doi.org/10.1177/0962280221998409.
VanderWeele, Tyler J, Stijn Vansteelandt, and James M Robins. 2014.“Effect Decomposition in the Presence of an Exposure-InducedMediator-Outcome Confounder.”Epidemiology 25 (2): 300–306.https://doi.org/10.1097/EDE.0000000000000034.
About
📦R package medRCT