regmedint

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

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

Science Score: 36.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
    Found 1 DOI reference(s) in README
  • Academic publication links
  • Committers with academic emails
    2 of 7 committers (28.6%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (12.4%) to scientific vocabulary

Keywords

causal-inference mediation-analysis
Last synced: 10 months ago · JSON representation

Repository

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

Basic Info
Statistics
  • Stars: 30
  • Watchers: 3
  • Forks: 5
  • Open Issues: 12
  • Releases: 0
Topics
causal-inference mediation-analysis
Created over 6 years ago · Last pushed over 2 years ago
Metadata Files
Readme Changelog

README.Rmd

---
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.

Owner

  • Name: Kazuki Yoshida
  • Login: kaz-yos
  • Kind: user
  • Location: Boston, MA, USA

Father in Training | Rheumatology & Drug Safety/Efficacy & Clinical Research

GitHub Events

Total
  • Issues event: 2
Last Year
  • Issues event: 2

Committers

Last synced: over 2 years ago

All Time
  • Total Commits: 1,095
  • Total Committers: 7
  • Avg Commits per committer: 156.429
  • Development Distribution Score (DDS): 0.148
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
kaz-yos k****a@m****u 933
einsley1993 e****3@g****m 106
Yi Li y****i@Y****l 36
Kazuki Yoshida k****a@d****u 10
YI LI y****i@M****l 6
Kazuki Yoshida k****8@c****g 3
einsley1993 6****3 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 10 months ago

All Time
  • Total issues: 13
  • Total pull requests: 2
  • Average time to close issues: N/A
  • Average time to close pull requests: 11 days
  • Total issue authors: 12
  • Total pull request authors: 1
  • Average comments per issue: 1.77
  • Average comments per pull request: 1.0
  • Merged pull requests: 1
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 2
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 1
  • Pull request authors: 0
  • Average comments per issue: 0.0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • hadley (2)
  • Jingyilang (1)
  • Cmaj7sharp11 (1)
  • syj1997104 (1)
  • Ali777927 (1)
  • dianashams (1)
  • smohaus (1)
  • zhangyz1997 (1)
  • HaibinLi0817 (1)
  • yuxx0510 (1)
  • acmilannesta (1)
  • PEWilliamZhou (1)
Pull Request Authors
  • einsley1993 (2)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • cran 437 last-month
  • Total docker downloads: 22,085
  • Total dependent packages: 0
  • Total dependent repositories: 2
  • Total versions: 5
  • Total maintainers: 1
cran.r-project.org: regmedint

Regression-Based Causal Mediation Analysis with Interaction and Effect Modification Terms

  • Versions: 5
  • Dependent Packages: 0
  • Dependent Repositories: 2
  • Downloads: 437 Last month
  • Docker Downloads: 22,085
Rankings
Docker downloads count: 0.6%
Forks count: 10.8%
Stargazers count: 11.8%
Average: 17.0%
Dependent repos count: 19.3%
Dependent packages count: 28.8%
Downloads: 30.9%
Maintainers (1)
Last synced: 11 months ago

Dependencies

DESCRIPTION cran
.github/workflows/R-CMD-check.yaml actions