SkillAgentSearch skills...

Regmedint

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

Install / Use

/learn @kaz-yos/Regmedint
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

regmedint <img src="man/figures/hex.png" align="right" height="140"/>

R-CMD-check

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) 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 use: regmedint (v1.0.0; Yoshida, Li, & Mathur, 2021)

<!-- cite the r package: https://easystats.github.io/report/articles/cite_packages.html -->

Implemented models

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

<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"> <table> <thead> <tr class="header"> <th style="text-align: left;">yreg \\ mreg</th> <th style="text-align: center;">linear</th> <th style="text-align: center;">logistic</th> </tr> </thead> <tbody> <tr class="odd"> <td style="text-align: left;">linear</td> <td style="text-align: center;">:heavy_check_mark:</td> <td style="text-align: center;">:heavy_check_mark:</td> </tr> <tr class="even"> <td style="text-align: left;">logistic<span class="math inline"><sup>1</sup></span></td> <td style="text-align: center;">:heavy_check_mark:</td> <td style="text-align: center;">:heavy_check_mark:</td> </tr> <tr class="odd"> <td style="text-align: left;">loglinear</td> <td style="text-align: center;">:heavy_check_mark:<span class="math inline"><sup>2</sup></span></td> <td style="text-align: center;">:heavy_check_mark:<span class="math inline"><sup>2</sup></span></td> </tr> <tr class="even"> <td style="text-align: left;">poisson</td> <td style="text-align: center;">:heavy_check_mark:</td> <td style="text-align: center;">:heavy_check_mark:</td> </tr> <tr class="odd"> <td style="text-align: left;">negbin</td> <td style="text-align: center;">:heavy_check_mark:</td> <td style="text-align: center;">:heavy_check_mark:</td> </tr> <tr class="even"> <td style="text-align: left;">survCox<span class="math inline"><sup>1</sup></span></td> <td style="text-align: center;">:heavy_check_mark:</td> <td style="text-align: center;">:heavy_check_mark:</td> </tr> <tr class="odd"> <td style="text-align: left;">survAFT exp</td> <td style="text-align: center;">:heavy_check_mark:</td> <td style="text-align: center;">:heavy_check_mark:</td> </tr> <tr class="even"> <td style="text-align: left;">survAFT weibull</td> <td style="text-align: center;">:heavy_check_mark:</td> <td style="text-align: center;">:heavy_check_mark:</td> </tr> </tbody> </table>

<sup>1</sup> Approximation depends on the rare event assumptions.

<sup>2</sup> 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.

# install.packages("devtools") # If you do not have devtools already.
devtools::install_github("kaz-yos/regmedint")

## 
##      checking for file ‘/private/var/folders/5m/w191nn3d52bc91mq5_jjgw880000gn/T/RtmpTDYzP5/remotesf00c1976f8fd/kaz-yos-regmedint-43d42e2/DESCRIPTION’ ...  ✔  checking for file ‘/private/var/folders/5m/w191nn3d52bc91mq5_jjgw880000gn/T/RtmpTDYzP5/remotesf00c1976f8fd/kaz-yos-regmedint-43d42e2/DESCRIPTION’
##   ─  preparing ‘regmedint’:
##      checking DESCRIPTION meta-information ...  ✔  checking DESCRIPTION meta-information
##   ─  checking for LF line-endings in source and make files and shell scripts
##   ─  checking for empty or unneeded directories
##      Removed empty directory ‘regmedint/man/figures’
##   ─  building ‘regmedint_1.0.0.tar.gz’
##      
## 

The CRAN version can be installed as follows.

install.packages("regmedint")

Data Example

We use VV2015 dataset for demonstration.

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

## ### Mediator model
## 
## Call:
## glm(formula = m ~ x + c, family = binomial(link = "logit"), data = data)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -1.5143  -1.1765   0.9177   1.1133   1.4602  
## 
## Coefficients:
##             Estimate Std. Error z value Pr(>|z|)
## (Intercept)  -0.3545     0.3252  -1.090    0.276
## x             0.3842     0.4165   0.922    0.356
## c             0.2694     0.2058   1.309    0.191
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 138.59  on 99  degrees of freedom
## Residual deviance: 136.08  on 97  degrees of freedom
## AIC: 142.08
## 
## Number of Fisher Scoring iterations: 4
## 
## ### Outcome model
## 
## Call:
## survival::survreg(formula = Surv(y, event) ~ x + m + x:m + c, 
##     data = data, dist = "weibull")
##               Value Std. Error     z           p
## (Intercept) -1.0424     0.1903 -5.48 0.000000043
## x            0.4408     0.3008  1.47        0.14
## m            0.0905     0.2683  0.34        0.74
## c           -0.0669     0.0915 -0.73        0.46
## x:m          0.1003     0.4207  0.24        0.81
## Log(scale)  -0.0347     0.0810 -0.43        0.67
## 
## Scale= 0.966 
## 
## Weibull distribution
## Loglik(model)= -11.4   Loglik(intercept only)= -14.5
##  Chisq= 6.31 on 4 degrees of freedom, p= 0.18 
## Number of Newton-Raphson Iterations: 5 
## n= 100 
## 
## ### Mediation analysis 
##              est         se         Z          p       lower      upper
## cde  0.541070807 0.29422958 1.8389409 0.06592388 -0.03560858 1.11775019
## pnde 0.505391952 0.21797147 2.3186151 0.02041591  0.07817572 0.93260819
## tnie 0.015988820 0.03171597 0.5041252 0.61417338 -0.04617334 0.07815098
## tnde 0.513662425 0.22946248 2.2385465 0.02518544  0.06392423 0.96340062
## pnie 0.007718348 0.02398457 0.3218047 0.74760066 -0.03929055 0.05472725
## te   0.521380773 0.22427066 2.3247837 0.02008353  0.08181835 0.96094319
## pm   0.039039346 0.07444080 0.5244348 0.59997616 -0.10686194 0.18494063
## 
## Evaluated at:
## avar: x
##  a1 (intervened value of avar) = 1
##  a0 (reference value of avar)  = 0
## mvar: m
##  m_cde (intervend value of mvar for cde) = 1
## cvar: c
##  c_cond (covariate vector value) = 3
## 
## Note that effect estimates can vary over m_cde and c_cond values when interaction = TRUE.
  1. 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.
<!-- -->
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",
                

Related Skills

View on GitHub
GitHub Stars35
CategoryDevelopment
Updated1mo ago
Forks9

Languages

R

Security Score

80/100

Audited on Mar 6, 2026

No findings