-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME.Rmd
106 lines (80 loc) · 5.25 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
---
output: github_document
bibliography: "inst/references.bib"
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# medRCT
<!-- badges: start -->
[![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)
[![R-CMD-check](https://github.com/T0ngChen/medRCT/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/T0ngChen/medRCT/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/T0ngChen/medRCT/graph/badge.svg)](https://app.codecov.io/gh/T0ngChen/medRCT)
<!-- badges: end -->
> Causal mediation analysis estimating interventional effects mapped to a target trial
The R package `medRCT` for causal mediation analysis supports the estimation of interventional effects [@vanderweele2014effect], specifically interventional effects that are defined explicitly in terms of a "target trial" [@hernan2016using], as recently proposed by @Moreno2021Mediation. In the target trial, the treatment strategies are specified to reflect hypothetical interventions targeting and thus shifting the joint distribution of the mediators. `medRCT` can accommodate any number of potentially correlated mediators, including mediators that are not of primary interest but that are intermediate (exposure-induced) mediator-outcome confounders.
## Installation
The `medRCT` package is not yet available on CRAN. You can install the latest stable version from [GitHub](https://github.com/T0ngChen/medRCT) using the following command:
``` r
remotes::install_github("T0ngChen/medRCT")
```
## Example
Using a simulated dataset based on a published case study from the Longitudinal Study of Australian Children [@Goldfeld2023], we illustrate how to use `medRCT` to estimate the interventional effects that emulate a target trial. Specifically, we aim to estimate the difference in expected outcome (risk of child mental health problems) under exposure (low family socioeconomic position) with versus without a hypothetical intervention that individually shifts the distribution of each mediator (parental mental health and preschool attendance) to the levels in the unexposed (high family socioeconomic position), while accounting for baseline confounders, an intermediate (exposure-induced) mediator-outcome confounder (family stressful life events), and correlations amongst mediators.
```{r eg, warning=FALSE, message=FALSE}
# Load the medRCT package
library(medRCT)
# Set a seed for reproducibility
set.seed(2025)
# Display the first few rows of the dataset
head(LSACdata)
# Define confounders for the analysis
confounders <- c("child_sex", "child_atsi", "mat_cob", "mat_engl", "mat_age")
```
**Note:** It is recommended to perform the analysis with at least 200 Monte Carlo simulations by setting `mcsim = 200`. For illustration purposes, we use `mcsim = 50`, which takes approximately 90 seconds to run.
```{r}
# Estimate interventional indirect effects for a hypothetical intervention
# that shifts the distribution of each mediator individually
med_res <- medRCT(
dat = LSACdata,
exposure = "sep",
outcome = "child_mh",
mediators = c("parent_mh", "preschool_att"),
intermediate_confs = "fam_stress", # intermediate confounders
confounders = confounders,
bootstrap = TRUE,
intervention_type = "shift_k",
mcsim = 50
)
# Summarise the results
summary(med_res)
```
Based on the estimated interventional effect (IIE_1), a hypothetical intervention improving the mental health of parents of children from families with low socioeconomic position to the levels of those from families with high socioeconomic position could potentially prevent 1 per 100 cases of child mental health problems. Meanwhile, the effect of a hypothetical intervention on preschool attendance (IIE_2) is negligible.
For detailed guidance on using the package to handle more complex scenarios, please refer to the [vignette](https://t0ngchen.github.io/medRCT/articles/intro.html).
## Citation
For work involving the `medRCT` R package, please cite the following:
@software{Chen2024medRCT,
author = {Tong Chen and Margarita Moreno-Betancur and S. Ghazaleh Dashti},
title = {`r gsub("\n", " ", paste0("medRCT: ", utils::packageDescription("medRCT", fields = "Title")))`},
year = {`r format(Sys.Date(), "%Y")`},
url = {https://t0ngchen.github.io/medRCT/},
note = {R package version `r utils::packageDescription("medRCT", fields = "Version")`}
}
@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}
}
## References