Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kaz-yos/regmedint

R implementation of effect measure modification-extended regression-based closed-formula causal mediation analysis
https://github.com/kaz-yos/regmedint

causal-inference mediation-analysis

Last synced: 4 days ago
JSON representation

R implementation of effect measure modification-extended regression-based closed-formula causal mediation analysis

Awesome Lists containing this project

README

        

---
output: github_document
---

```{r, message = FALSE, tidy = FALSE, echo = F}
## knitr configuration: http://yihui.name/knitr/options#chunk_options
library(knitr)
showMessage <- FALSE
showWarning <- TRUE
set_alias(w = "fig.width", h = "fig.height", res = "results")
opts_chunk$set(comment = "##", error= TRUE, warning = showWarning, message = showMessage,
tidy = FALSE, cache = FALSE, echo = TRUE,
fig.width = 7, fig.height = 7,
fig.path = "man/figures")
## for rgl
## knit_hooks$set(rgl = hook_rgl, webgl = hook_webgl)
## for animation
opts_knit$set(animation.fun = hook_ffmpeg_html)
## R configuration
options(width = 116, scipen = 5)
```

# regmedint

[![R-CMD-check](https://github.com/kaz-yos/regmedint/workflows/R-CMD-check/badge.svg)](https://github.com/kaz-yos/regmedint/actions)
[![](http://www.r-pkg.org/badges/version/regmedint)](http://www.r-pkg.org/pkg/regmedint)
[![CRAN RStudio mirror downloads](http://cranlogs.r-pkg.org/badges/regmedint)](http://www.r-pkg.org/pkg/regmedint)

This is an extension of the regression-based causal mediation analysis first proposed by Valeri and VanderWeele (2013) and Valeri and VanderWeele (2015). The current version supports including effect measure modification by covariates (treatment-covariate and mediator-covariate product terms in mediator and outcome regression models). It also accommodates the original 'SAS' macro (can be found at Dr. VanderWeele's [Tools and Tutorials](https://www.hsph.harvard.edu/tyler-vanderweele/tools-and-tutorials/)) and PROC CAUSALMED procedure in 'SAS' when there is no effect measure modification. Linear and logistic models are supported for the mediator model. Linear, logistic, loglinear, Poisson, negative binomial, Cox, and accelerated failure time (exponential and Weibull) models are supported for the outcome model.

To cite this software, please cite Li et al (2023)

# Implemented models

The following grid of models are implemented. `yreg` refers to the outcome model and `mreg` refers to the mediator model.

| yreg \\\\ mreg | linear | logistic |
|:----------------|:---------------:|:---------------:|
| linear | :heavy_check_mark: | :heavy_check_mark: |
| logistic$^1$ | :heavy_check_mark: | :heavy_check_mark: |
| loglinear | :heavy_check_mark:$^2$ | :heavy_check_mark:$^2$ |
| poisson | :heavy_check_mark: | :heavy_check_mark: |
| negbin | :heavy_check_mark: | :heavy_check_mark: |
| survCox$^1$ | :heavy_check_mark: | :heavy_check_mark: |
| survAFT exp | :heavy_check_mark: | :heavy_check_mark: |
| survAFT weibull | :heavy_check_mark: | :heavy_check_mark: |

$^1$ Approximation depends on the rare event assumptions.

$^2$ Implemented as a modified Poisson model (log link with robust variance) as in Z2004.

See the corresponding vignettes (Articles on the package website) for how to perform bootstrapping and multiple imputation.

# Installation

For the developmental version on Github, use the following commands to install the package.
```{r}
# install.packages("devtools") # If you do not have devtools already.
devtools::install_github("kaz-yos/regmedint")
```

The CRAN version can be installed as follows.

```{r, eval = FALSE}
install.packages("regmedint")
```

# Data Example
We use `VV2015` dataset for demonstration.
```{r, eval = TRUE}
library(regmedint)
data(vv2015)
```

## `regmedint()` to fit models
The `regmedint` function is the user interface for constructing a result object of class `regmedint`. The interface is similar to the original SAS macro. For survival outcomes, the indicator variable is an event indicator (1 for event, 0 for censoring). `c_cond` vector is required be specified. This vector is the vector of covariate values at which the conditional effects are evaluated at.

1. When there is no effect measure modification by covariates, `emm_ac_mreg = NULL`, `emm_ac_yreg = NULL`, `emm_mc_yreg = NULL`.
```{r}
regmedint_obj1 <- regmedint(data = vv2015,
## Variables
yvar = "y",
avar = "x",
mvar = "m",
cvar = c("c"),
eventvar = "event",
## Values at which effects are evaluated
a0 = 0,
a1 = 1,
m_cde = 1,
c_cond = 3,
## Model types
mreg = "logistic",
yreg = "survAFT_weibull",
## Additional specification
interaction = TRUE,
casecontrol = FALSE)
summary(regmedint_obj1)
```

2. When there is effect measure modification by covariates, `emm_ac_mreg`, `emm_ac_yreg` and `emm_mc_yreg` can take a sub-vector of covariates in `cvar`.
```{r}
regmedint_obj2 <- regmedint(data = vv2015,
## Variables
yvar = "y",
avar = "x",
mvar = "m",
cvar = c("c"),
emm_ac_mreg = c("c"),
emm_ac_yreg = c("c"),
emm_mc_yreg = c("c"),
eventvar = "event",
## Values at which effects are evaluated
a0 = 0,
a1 = 1,
m_cde = 1,
c_cond = 3,
## Model types
mreg = "logistic",
yreg = "survAFT_weibull",
## Additional specification
interaction = TRUE,
casecontrol = FALSE)
summary(regmedint_obj2)
```

## `summary()` to examine extended results
The `summary` method gives the summary for `mreg`, `yreg`, and mediation analysis results. The `exponentiate` option will add the exponentiated estimate and confidence limits if the outcome model is not a linear model. The pure natural direct effect (`pnde`) is what is typically called the natural direct effect (NDE). The total natural indirect effect (`tnie`) is the corresponding natural indirect effect (NIE).
```{r}
summary(regmedint_obj2, exponentiate = TRUE)
```
Use `coef` to extract the mediation analysis results only.
```{r}
coef(summary(regmedint_obj2, exponentiate = TRUE))
```
Note that the estimates can be re-evaluated at different `m_cde` and `c_cond` without re-fitting the underlyng models.
```{r}
coef(summary(regmedint_obj2, exponentiate = TRUE, m_cde = 0, c_cond = 5))
```

# Formulas
See [here](https://osf.io/d4brv/) for the following formulas.

## Effect formulas in the supplementary document
| yreg \\\\ mreg | linear | logistic |
|-----------------|--------------------------------------|--------------------------------------|
| linear | Formulas (1) - (5) | Formulas (11) - (15) |
| | | |
| logistic | Formulas (21) - (25) | Formulas (31) - (35) |
| loglinear | Formulas (21) - (25) | Formulas (31) - (35) |
| poisson | Formulas (21) - (25) | Formulas (31) - (35) |
| negbin | Formulas (21) - (25) | Formulas (31) - (35) |
| | | |
| survCox | Formulas (21) - (25) | Formulas (31) - (35) |
| survAFT exp | Formulas (21) - (25) | Formulas (31) - (35) |
| survAFT weibull | Formulas (21) - (25) | Formulas (31) - (35) |

## Standard error formulas in the supplementary document
| yreg \\\\ mreg | linear | logistic |
|-----------------|--------------------------------|--------------------------------|
| linear | Formulas (6) - (10) | Formulas (16) - (20) |
| | | |
| logistic | Formulas (26) - (30) | Formulas (36) - (40) |
| loglinear | Formulas (26) - (30) | Formulas (36) - (40) |
| poisson | Formulas (26) - (30) | Formulas (36) - (40) |
| negbin | Formulas (26) - (30) | Formulas (36) - (40) |
| | | |
| survCox | Formulas (26) - (30) | Formulas (36) - (40) |
| survAFT exp | Formulas (26) - (30) | Formulas (36) - (40) |
| survAFT weibull | Formulas (26) - (30) | Formulas (36) - (40) |

Note: The point estimate and standard error formulas (multivariate delta method) were derived based on the following references.

- V2015: VanderWeele (2015) Explanation in Causal Inference.
- VV2013A: Valeri & VanderWeele (2013) Appendix
- VV2015A: Valeri & VanderWeele (2015) Appendix

## Effect formulas are based on the following propositions
| yreg \\\\ mreg | linear | logistic |
|-----------------|--------------------------------------|--------------------------------------|
| linear | V2015 p466 Proposition 2.3 | V2015 p471 Proposition 2.5 |
| | | |
| logistic | V2015 p468 Proposition 2.4 | V2015 p473 Proposition 2.6 |
| loglinear | VV2013A p8 Use Proposition 2.4 | VV2013A p8 Use Proposition 2.6 |
| poisson | VV2013A p8 Use Proposition 2.4 | VV2013A p8 Use Proposition 2.6 |
| negbin | VV2013A p8 Use Proposition 2.4 | VV2013A p8 Use Proposition 2.6 |
| | | |
| survCox | V2015 p496 Proposition 4.4 (Use 2.4) | V2015 p499 Proposition 4.6 (Use 2.6) |
| survAFT exp | V2015 p494 Proposition 4.1 (Use 2.4) | V2015 p495 Proposition 4.3 (Use 2.6) |
| survAFT weibull | V2015 p494 Proposition 4.1 (Use 2.4) | V2015 p495 Proposition 4.3 (Use 2.6) |

## Standard error formulas are based on the following propositions
| yreg \\\\ mreg | linear | logistic |
|-----------------|--------------------------------|--------------------------------|
| linear | V2015 p466 Proposition 2.3 | V2015 p471 Proposition 2.5 |
| | | |
| logistic | V2015 p468 Proposition 2.4 | V2015 p473 Proposition 2.6 |
| loglinear | VV2013A p8 Use Proposition 2.4 | VV2013A p8 Use Proposition 2.6 |
| poisson | VV2013A p8 Use Proposition 2.4 | VV2013A p8 Use Proposition 2.6 |
| negbin | VV2013A p8 Use Proposition 2.4 | VV2013A p8 Use Proposition 2.6 |
| | | |
| survCox | V2015 p496 Use Proposition 2.4 | V2015 p499 Use Proposition 2.6 |
| survAFT exp | V2015 p494 Use Proposition 2.4 | V2015 p495 Use Proposition 2.6 |
| survAFT weibull | V2015 p494 Use Proposition 2.4 | V2015 p495 Use Proposition 2.6 |

# Similar or related projects for counterfactual-based causal mediation analysis
## R
- mediation (simulation-based): https://CRAN.R-project.org/package=mediation
- medflex (natural effect model): https://CRAN.R-project.org/package=medflex
- intmed (interventional analogue): https://CRAN.R-project.org/package=intmed
- CMAverse (regression-based approach, weighting-based approach, inverse odd-ratio weighting, natural effect model, marginal structural model, g-formula approach): https://bs1125.github.io/CMAverse/
- mediator (regression-based): https://github.com/GerkeLab/mediator
- causalMediation (regression-based): https://github.com/harvard-P01/causalMediation

## Other statistical environment
- SAS macro (original regression-based) https://www.hsph.harvard.edu/tyler-vanderweele/tools-and-tutorials/
- SAS PROC CAUSALMED (regression-based) https://support.sas.com/rnd/app/stat/procedures/causalmed.html

# References
- V2015: VanderWeele (2015) Explanation in Causal Inference.
- VV2013: Valeri & VanderWeele (2013) Psych Method. 18:137.
- VV2015: Valeri & VanderWeele (2015) Epidemiology. 26:e23.
- Z2004: Zou (2004) Am J Epidemiol 159:702.