Title: | Regression-Based Causal Mediation Analysis with Interaction and Effect Modification Terms |
---|---|
Description: | This is an extension of the regression-based causal mediation analysis first proposed by Valeri and VanderWeele (2013) <doi:10.1037/a0031034> and Valeri and VanderWeele (2015) <doi:10.1097/EDE.0000000000000253>). It supports including effect measure modification by covariates(treatment-covariate and mediator-covariate product terms in mediator and outcome regression models) as proposed by Li et al (2023) <doi:10.1097/EDE.0000000000001643>. It also accommodates the original 'SAS' macro 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. |
Authors: | Kazuki Yoshida [ctb, aut] , Yi Li [cre, aut] , Maya Mathur [ctb] |
Maintainer: | Yi Li <[email protected]> |
License: | GPL-2 |
Version: | 1.0.1 |
Built: | 2025-01-02 04:28:29 UTC |
Source: | https://github.com/kaz-yos/regmedint |
This function extracts coef
from mreg_fit
and pads with zeros appropriately to create a named vector consistently having the following elements:
(Intercept)
,
avar
,
cvar
(this part is eliminated when cvar = NULL
),
emm_ac_mreg
(this part is eliminated when emm_ac_mreg = NULL
).
beta_hat(mreg, mreg_fit, avar, cvar, emm_ac_mreg = NULL)
beta_hat(mreg, mreg_fit, avar, cvar, emm_ac_mreg = NULL)
mreg |
A character vector of length 1. Mediator regression type: |
mreg_fit |
Model fit object for mreg (mediator model). |
avar |
A character vector of length 1. Treatment variable name. |
cvar |
A character vector of length > 0. Covariate names. Use |
emm_ac_mreg |
A character vector of length > 0. Effect modifiers names. The covariate vector in treatment-covariate product term in the mediator model. |
A named numeric vector of coefficients.
This function returns functions that can be used to calculate the causal effect measures, given the mediator model fit (mreg_fit
) and the outcome model fit (yreg_fit
).
calc_myreg( mreg, mreg_fit, yreg, yreg_fit, avar, mvar, cvar, emm_ac_mreg, emm_ac_yreg, emm_mc_yreg, interaction )
calc_myreg( mreg, mreg_fit, yreg, yreg_fit, avar, mvar, cvar, emm_ac_mreg, emm_ac_yreg, emm_mc_yreg, interaction )
mreg |
A character vector of length 1. Mediator regression type: |
mreg_fit |
Model fit from |
yreg |
A character vector of length 1. Outcome regression type: |
yreg_fit |
Model fit from |
avar |
A character vector of length 1. Treatment variable name. |
mvar |
A character vector of length 1. Mediator variable name. |
cvar |
A character vector of length > 0. Covariate names. Use |
emm_ac_mreg |
A character vector of length > 0. Effect modifiers names. The covariate vector in treatment-covariate product term in the mediator model. |
emm_ac_yreg |
A character vector of length > 0. Effect modifiers names. The covariate vector in treatment-covariate product term in the outcome model. |
emm_mc_yreg |
A character vector of length > 0. Effect modifiers names. The covariate vector in mediator-covariate product term in outcome model. |
interaction |
A logical vector of length 1. The presence of treatment-mediator interaction in the outcome model. Default to TRUE. |
A list containing two functions. The first is for calculating point estimates. The second is for calculating the correspoding
Construct functions for the conditional effect estimates and their standard errors in the mreg linear / yreg linear setting. Internally, this function deconstructs model objects and feeds parameter estiamtes to the internal worker functions calc_myreg_mreg_linear_yreg_linear_est
and calc_myreg_mreg_linear_yreg_linear_se
.
calc_myreg_mreg_linear_yreg_linear( mreg, mreg_fit, yreg, yreg_fit, avar, mvar, cvar, emm_ac_mreg, emm_ac_yreg, emm_mc_yreg, interaction )
calc_myreg_mreg_linear_yreg_linear( mreg, mreg_fit, yreg, yreg_fit, avar, mvar, cvar, emm_ac_mreg, emm_ac_yreg, emm_mc_yreg, interaction )
mreg |
A character vector of length 1. Mediator regression type: |
mreg_fit |
Model fit from |
yreg |
A character vector of length 1. Outcome regression type: |
yreg_fit |
Model fit from |
avar |
A character vector of length 1. Treatment variable name. |
mvar |
A character vector of length 1. Mediator variable name. |
cvar |
A character vector of length > 0. Covariate names. Use |
emm_ac_mreg |
A character vector of length > 0. Effect modifiers names. The covariate vector in treatment-covariate product term in the mediator model. |
emm_ac_yreg |
A character vector of length > 0. Effect modifiers names. The covariate vector in treatment-covariate product term in the outcome model. |
emm_mc_yreg |
A character vector of length > 0. Effect modifiers names. The covariate vector in mediator-covariate product term in outcome model. |
interaction |
A logical vector of length 1. The presence of treatment-mediator interaction in the outcome model. Default to TRUE. |
A list containing a function for effect estimates and a function for corresponding standard errors.
Construct functions for the conditional effect estimates and their standard errors in the mreg linear / yreg logistic setting. Internally, this function deconstructs model objects and feeds parameter estimates to the internal worker functions calc_myreg_mreg_linear_yreg_logistic_est
and calc_myreg_mreg_linear_yreg_logistic_se
.
calc_myreg_mreg_linear_yreg_logistic( mreg, mreg_fit, yreg, yreg_fit, avar, mvar, cvar, emm_ac_mreg, emm_ac_yreg, emm_mc_yreg, interaction )
calc_myreg_mreg_linear_yreg_logistic( mreg, mreg_fit, yreg, yreg_fit, avar, mvar, cvar, emm_ac_mreg, emm_ac_yreg, emm_mc_yreg, interaction )
mreg |
A character vector of length 1. Mediator regression type: |
mreg_fit |
Model fit from |
yreg |
A character vector of length 1. Outcome regression type: |
yreg_fit |
Model fit from |
avar |
A character vector of length 1. Treatment variable name. |
mvar |
A character vector of length 1. Mediator variable name. |
cvar |
A character vector of length > 0. Covariate names. Use |
emm_ac_mreg |
A character vector of length > 0. Effect modifiers names. The covariate vector in treatment-covariate product term in the mediator model. |
emm_ac_yreg |
A character vector of length > 0. Effect modifiers names. The covariate vector in treatment-covariate product term in the outcome model. |
emm_mc_yreg |
A character vector of length > 0. Effect modifiers names. The covariate vector in mediator-covariate product term in outcome model. |
interaction |
A logical vector of length 1. The presence of treatment-mediator interaction in the outcome model. Default to TRUE. |
A list containing a function for effect estimates and a function for corresponding standard errors.
Construct functions for the conditional effect estimates and their standard errors in the mreg logistic / yreg linear setting. Internally, this function deconstructs model objects and feeds parameter estimates to the internal worker functions calc_myreg_mreg_logistic_yreg_linear_est
and calc_myreg_mreg_logistic_yreg_linear_se
.
calc_myreg_mreg_logistic_yreg_linear( mreg, mreg_fit, yreg, yreg_fit, avar, mvar, cvar, emm_ac_mreg, emm_ac_yreg, emm_mc_yreg, interaction )
calc_myreg_mreg_logistic_yreg_linear( mreg, mreg_fit, yreg, yreg_fit, avar, mvar, cvar, emm_ac_mreg, emm_ac_yreg, emm_mc_yreg, interaction )
mreg |
A character vector of length 1. Mediator regression type: |
mreg_fit |
Model fit from |
yreg |
A character vector of length 1. Outcome regression type: |
yreg_fit |
Model fit from |
avar |
A character vector of length 1. Treatment variable name. |
mvar |
A character vector of length 1. Mediator variable name. |
cvar |
A character vector of length > 0. Covariate names. Use |
emm_ac_mreg |
A character vector of length > 0. Effect modifiers names. The covariate vector in treatment-covariate product term in the mediator model. |
emm_ac_yreg |
A character vector of length > 0. Effect modifiers names. The covariate vector in treatment-covariate product term in the outcome model. |
emm_mc_yreg |
A character vector of length > 0. Effect modifiers names. The covariate vector in mediator-covariate product term in outcome model. |
interaction |
A logical vector of length 1. The presence of treatment-mediator interaction in the outcome model. Default to TRUE. |
A list containing a function for effect estimates and a function for corresponding standard errors.
Construct functions for the conditional effect estimates and their standard errors in the mreg logistic / yreg logistic setting. Internally, this function deconstructs model objects and feeds parameter estimates to the internal worker functions calc_myreg_mreg_logistic_yreg_logistic_est
and calc_myreg_mreg_logistic_yreg_logistic_se
.
calc_myreg_mreg_logistic_yreg_logistic( mreg, mreg_fit, yreg, yreg_fit, avar, mvar, cvar, emm_ac_mreg, emm_ac_yreg, emm_mc_yreg, interaction )
calc_myreg_mreg_logistic_yreg_logistic( mreg, mreg_fit, yreg, yreg_fit, avar, mvar, cvar, emm_ac_mreg, emm_ac_yreg, emm_mc_yreg, interaction )
mreg |
A character vector of length 1. Mediator regression type: |
mreg_fit |
Model fit from |
yreg |
A character vector of length 1. Outcome regression type: |
yreg_fit |
Model fit from |
avar |
A character vector of length 1. Treatment variable name. |
mvar |
A character vector of length 1. Mediator variable name. |
cvar |
A character vector of length > 0. Covariate names. Use |
emm_ac_mreg |
A character vector of length > 0. Effect modifiers names. The covariate vector in treatment-covariate product term in the mediator model. |
emm_ac_yreg |
A character vector of length > 0. Effect modifiers names. The covariate vector in treatment-covariate product term in the outcome model. |
emm_mc_yreg |
A character vector of length > 0. Effect modifiers names. The covariate vector in mediator-covariate product term in outcome model. |
interaction |
A logical vector of length 1. The presence of treatment-mediator interaction in the outcome model. Default to TRUE. |
A list containing a function for effect estimates and a function for corresponding standard errors.
Extract point estimates evaluated at a0
, a1
, m_cde
, and c_cond
.
## S3 method for class 'regmedint' coef(object, a0 = NULL, a1 = NULL, m_cde = NULL, c_cond = NULL, ...)
## S3 method for class 'regmedint' coef(object, a0 = NULL, a1 = NULL, m_cde = NULL, c_cond = NULL, ...)
object |
An object of the |
a0 |
A numeric vector of length 1 |
a1 |
A numeric vector of length 1 |
m_cde |
A numeric vector of length 1 The mediator value at which the controlled direct effect (CDE) conditional on the adjustment covariates is evaluated. If not provided, the default value supplied to the call to |
c_cond |
A numeric vector of the same length as |
... |
For compatibility with the generic. Ignored. |
A numeric vector of point estimates.
library(regmedint) data(vv2015) regmedint_obj <- 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 = 0.5, ## Model types mreg = "logistic", yreg = "survAFT_weibull", ## Additional specification interaction = TRUE, casecontrol = FALSE) coef(regmedint_obj) ## Evaluate at different values coef(regmedint_obj, m_cde = 0, c_cond = 1)
library(regmedint) data(vv2015) regmedint_obj <- 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 = 0.5, ## Model types mreg = "logistic", yreg = "survAFT_weibull", ## Additional specification interaction = TRUE, casecontrol = FALSE) coef(regmedint_obj) ## Evaluate at different values coef(regmedint_obj, m_cde = 0, c_cond = 1)
Extract the result matrix from a summary_regmedint object.
## S3 method for class 'summary_regmedint' coef(object, ...)
## S3 method for class 'summary_regmedint' coef(object, ...)
object |
An object with a class of |
... |
For compatibility with the generic. |
A matrix populated with results.
library(regmedint) data(vv2015) regmedint_obj <- 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 = 0.5, ## Model types mreg = "logistic", yreg = "survAFT_weibull", ## Additional specification interaction = TRUE, casecontrol = FALSE) coef(summary(regmedint_obj))
library(regmedint) data(vv2015) regmedint_obj <- 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 = 0.5, ## Model types mreg = "logistic", yreg = "survAFT_weibull", ## Additional specification interaction = TRUE, casecontrol = FALSE) coef(summary(regmedint_obj))
Construct Wald approximate confidence intervals for the quantities of interest.
## S3 method for class 'regmedint' confint( object, parm = NULL, level = 0.95, a0 = NULL, a1 = NULL, m_cde = NULL, c_cond = NULL, ... )
## S3 method for class 'regmedint' confint( object, parm = NULL, level = 0.95, a0 = NULL, a1 = NULL, m_cde = NULL, c_cond = NULL, ... )
object |
An object of the |
parm |
For compatibility with generic. Ignored. |
level |
A numeric vector of length one. Requested confidence level. Defaults to 0.95. |
a0 |
A numeric vector of length 1 |
a1 |
A numeric vector of length 1 |
m_cde |
A numeric vector of length 1 The mediator value at which the controlled direct effect (CDE) conditional on the adjustment covariates is evaluated. If not provided, the default value supplied to the call to |
c_cond |
A numeric vector of the same length as |
... |
For compatibility with generic. |
A numeric matrix of the lower limit and upper limit.
library(regmedint) data(vv2015) regmedint_obj <- 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 = 0.5, ## Model types mreg = "logistic", yreg = "survAFT_weibull", ## Additional specification interaction = TRUE, casecontrol = FALSE) confint(regmedint_obj) ## Evaluate at different values confint(regmedint_obj, m_cde = 0, c_cond = 1) ## Change confidence level confint(regmedint_obj, m_cde = 0, c_cond = 1, level = 0.99)
library(regmedint) data(vv2015) regmedint_obj <- 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 = 0.5, ## Model types mreg = "logistic", yreg = "survAFT_weibull", ## Additional specification interaction = TRUE, casecontrol = FALSE) confint(regmedint_obj) ## Evaluate at different values confint(regmedint_obj, m_cde = 0, c_cond = 1) ## Change confidence level confint(regmedint_obj, m_cde = 0, c_cond = 1, level = 0.99)
lm
is called if mreg = "linear"
. glm
is called with family = binomial()
if mreg = "logistic"
.
fit_mreg(mreg, data, avar, mvar, cvar, emm_ac_mreg = NULL)
fit_mreg(mreg, data, avar, mvar, cvar, emm_ac_mreg = NULL)
mreg |
A character vector of length 1. Mediator regression type: |
data |
Data frame containing the following relevant variables. |
avar |
A character vector of length 1. Treatment variable name. |
mvar |
A character vector of length 1. Mediator variable name. |
cvar |
A character vector of length > 0. Covariate names. Use |
emm_ac_mreg |
A character vector of length > 0. Effect modifiers names. The covariate vector in treatment-covariate product term in the mediator model. |
A regression object of class lm (linear) or glm (logistic)
The outcome model type yreg
can be one of the following "linear"
, "logistic"
, "loglinear"
(implemented as modified Poisson), "poisson"
, "negbin"
, "survCox"
, "survAFT_exp"
, or "survAFT_weibull"
.
fit_yreg( yreg, data, yvar, avar, mvar, cvar, emm_ac_yreg = NULL, emm_mc_yreg = NULL, eventvar, interaction )
fit_yreg( yreg, data, yvar, avar, mvar, cvar, emm_ac_yreg = NULL, emm_mc_yreg = NULL, eventvar, interaction )
yreg |
A character vector of length 1. Outcome regression type: |
data |
Data frame containing the following relevant variables. |
yvar |
A character vector of length 1. Outcome variable name. It should be the time variable for the survival outcome. |
avar |
A character vector of length 1. Treatment variable name. |
mvar |
A character vector of length 1. Mediator variable name. |
cvar |
A character vector of length > 0. Covariate names. Use |
emm_ac_yreg |
A character vector of length > 0. Effect modifiers names. The covariate vector in treatment-covariate product term in the outcome model. |
emm_mc_yreg |
A character vector of length > 0. Effect modifiers names. The covariate vector in mediator-covariate product term in outcome model. |
eventvar |
An character vector of length 1. Only required for survival outcome regression models. Note that the coding is 1 for event and 0 for censoring, following the R survival package convention. |
interaction |
A logical vector of length 1. The presence of treatment-mediator interaction in the outcome model. Default to TRUE. |
The outcome regression functions to be called are the following:
"linear"
lm
"logistic"
glm
"loglinear"
glm
(modified Poisson)
"poisson"
glm
"negbin"
glm.nb
"survCox"
coxph
"survAFT_exp"
survreg
"survAFT_weibull"
survreg
Model fit object from on of the above regression functions.
Calculate the gradient of the proportion mediated for yreg linear case.
grad_prop_med_yreg_linear(pnde, tnie)
grad_prop_med_yreg_linear(pnde, tnie)
pnde |
A numeric vector of length one. Pure natural direct effect. |
tnie |
A numeric vector of length one. Total natural indirect effect. |
A numeric vector of length two. Gradient of the proportion mediated with respect to pnde and tnie.
Calculate the gradient of the proportion mediated for yreg logistic case.
grad_prop_med_yreg_logistic(pnde, tnie)
grad_prop_med_yreg_logistic(pnde, tnie)
pnde |
A numeric vector of length one. Pure natural direct effect. |
tnie |
A numeric vector of length one. Total natural indirect effect. |
A numeric vector of length two. Gradient of the proportion mediated with respect to pnde and tnie.
This is not a user function and meant to be executed within the regmedint function after validatingthe arguments.
new_regmedint( data, yvar, avar, mvar, cvar, emm_ac_mreg, emm_ac_yreg, emm_mc_yreg, eventvar, a0, a1, m_cde, c_cond, yreg, mreg, interaction, casecontrol )
new_regmedint( data, yvar, avar, mvar, cvar, emm_ac_mreg, emm_ac_yreg, emm_mc_yreg, eventvar, a0, a1, m_cde, c_cond, yreg, mreg, interaction, casecontrol )
data |
Data frame containing the following relevant variables. |
yvar |
A character vector of length 1. Outcome variable name. It should be the time variable for the survival outcome. |
avar |
A character vector of length 1. Treatment variable name. |
mvar |
A character vector of length 1. Mediator variable name. |
cvar |
A character vector of length > 0. Covariate names. Use |
emm_ac_mreg |
A character vector of length > 0. Effect modifiers names. The covariate vector in treatment-covariate product term in the mediator model. |
emm_ac_yreg |
A character vector of length > 0. Effect modifiers names. The covariate vector in treatment-covariate product term in the outcome model. |
emm_mc_yreg |
A character vector of length > 0. Effect modifiers names. The covariate vector in mediator-covariate product term in outcome model. |
eventvar |
An character vector of length 1. Only required for survival outcome regression models. Note that the coding is 1 for event and 0 for censoring, following the R survival package convention. |
a0 |
A numeric vector of length 1. The reference level of treatment variable that is considered "untreated" or "unexposed". |
a1 |
A numeric vector of length 1. |
m_cde |
A numeric vector of length 1. Mediator level at which controlled direct effect is evaluated at. |
c_cond |
A numeric vector of the same length as |
yreg |
A character vector of length 1. Outcome regression type: |
mreg |
A character vector of length 1. Mediator regression type: |
interaction |
A logical vector of length 1. The presence of treatment-mediator interaction in the outcome model. Default to TRUE. |
casecontrol |
A logical vector of length 1. Default to FALSE. Whether data comes from a case-control study. |
A regmedint object.
Print the mreg_fit
, yreg_fit
, and the mediation analysis effect estimates.
## S3 method for class 'regmedint' print( x, a0 = NULL, a1 = NULL, m_cde = NULL, c_cond = NULL, args_mreg_fit = list(), args_yreg_fit = list(), ... )
## S3 method for class 'regmedint' print( x, a0 = NULL, a1 = NULL, m_cde = NULL, c_cond = NULL, args_mreg_fit = list(), args_yreg_fit = list(), ... )
x |
An object of the |
a0 |
A numeric vector of length 1 |
a1 |
A numeric vector of length 1 |
m_cde |
A numeric vector of length 1 The mediator value at which the controlled direct effect (CDE) conditional on the adjustment covariates is evaluated. If not provided, the default value supplied to the call to |
c_cond |
A numeric vector of the same length as |
args_mreg_fit |
A named list of argument to be passed to the method for the |
args_yreg_fit |
A named list of argument to be passed to the method for the |
... |
For compatibility with the generic. Ignored. |
Invisibly return the regmedint
class object as is.
library(regmedint) data(vv2015) regmedint_obj <- 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 = 0.5, ## Model types mreg = "logistic", yreg = "survAFT_weibull", ## Additional specification interaction = TRUE, casecontrol = FALSE) ## Implicit printing regmedint_obj ## Explicit printing print(regmedint_obj) ## Evaluate at different values print(regmedint_obj, m_cde = 0, c_cond = 1)
library(regmedint) data(vv2015) regmedint_obj <- 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 = 0.5, ## Model types mreg = "logistic", yreg = "survAFT_weibull", ## Additional specification interaction = TRUE, casecontrol = FALSE) ## Implicit printing regmedint_obj ## Explicit printing print(regmedint_obj) ## Evaluate at different values print(regmedint_obj, m_cde = 0, c_cond = 1)
summary.regmedint
Print results contained in a summary_regmedint
object with additional explanation regarding the evaluation settings.
## S3 method for class 'summary_regmedint' print(x, ...)
## S3 method for class 'summary_regmedint' print(x, ...)
x |
An object of the class |
... |
For compatibility with the generic function. |
Invisibly return the first argument.
library(regmedint) data(vv2015) regmedint_obj <- 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 = 0.5, ## Model types mreg = "logistic", yreg = "survAFT_weibull", ## Additional specification interaction = TRUE, casecontrol = FALSE) ## Implicit printing summary(regmedint_obj) ## Explicit printing print(summary(regmedint_obj))
library(regmedint) data(vv2015) regmedint_obj <- 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 = 0.5, ## Model types mreg = "logistic", yreg = "survAFT_weibull", ## Additional specification interaction = TRUE, casecontrol = FALSE) ## Implicit printing summary(regmedint_obj) ## Explicit printing print(summary(regmedint_obj))
Calculate the proportion mediated on the mean difference scale.
prop_med_yreg_linear(pnde, tnie)
prop_med_yreg_linear(pnde, tnie)
pnde |
Pure natural direct effect. |
tnie |
Total natural indirect effect. |
Proportion mediated value.
Calculate the approximate proportion mediated on the risk difference scale.
prop_med_yreg_logistic(pnde, tnie)
prop_med_yreg_logistic(pnde, tnie)
pnde |
Pure natural direct effect on the log scale. |
tnie |
Total natural indirect effect on the log scale. |
Proportion mediated value.
The package is an R implementation of regression-based closed-form causal mediation as originally described in Valeri & VanderWeele 2013 and Valeri & VanderWeele 2015 https://www.hsph.harvard.edu/tyler-vanderweele/tools-and-tutorials/. The earlier version is a sister program of the SAS macro. The current extended version (version 1.0 and later) supports effect modification by covariates (treatment-covariate and mediator-covariate product terms) in mediator and outcome models.
This is a user-interface for regression-based causal mediation analysis as described in Valeri & VanderWeele 2013 and Valeri & VanderWeele 2015.
regmedint( data, yvar, avar, mvar, cvar, emm_ac_mreg = NULL, emm_ac_yreg = NULL, emm_mc_yreg = NULL, eventvar = NULL, a0, a1, m_cde, c_cond, mreg, yreg, interaction = TRUE, casecontrol = FALSE, na_omit = FALSE )
regmedint( data, yvar, avar, mvar, cvar, emm_ac_mreg = NULL, emm_ac_yreg = NULL, emm_mc_yreg = NULL, eventvar = NULL, a0, a1, m_cde, c_cond, mreg, yreg, interaction = TRUE, casecontrol = FALSE, na_omit = FALSE )
data |
Data frame containing the following relevant variables. |
yvar |
A character vector of length 1. Outcome variable name. It should be the time variable for the survival outcome. |
avar |
A character vector of length 1. Treatment variable name. |
mvar |
A character vector of length 1. Mediator variable name. |
cvar |
A character vector of length > 0. Covariate names. Use |
emm_ac_mreg |
A character vector of length > 0. Effect modifiers names. The covariate vector in treatment-covariate product term in the mediator model. |
emm_ac_yreg |
A character vector of length > 0. Effect modifiers names. The covariate vector in treatment-covariate product term in the outcome model. |
emm_mc_yreg |
A character vector of length > 0. Effect modifiers names. The covariate vector in mediator-covariate product term in outcome model. |
eventvar |
An character vector of length 1. Only required for survival outcome regression models. Note that the coding is 1 for event and 0 for censoring, following the R survival package convention. |
a0 |
A numeric vector of length 1. The reference level of treatment variable that is considered "untreated" or "unexposed". |
a1 |
A numeric vector of length 1. |
m_cde |
A numeric vector of length 1. Mediator level at which controlled direct effect is evaluated at. |
c_cond |
A numeric vector of the same length as |
mreg |
A character vector of length 1. Mediator regression type: |
yreg |
A character vector of length 1. Outcome regression type: |
interaction |
A logical vector of length 1. The presence of treatment-mediator interaction in the outcome model. Default to TRUE. |
casecontrol |
A logical vector of length 1. Default to FALSE. Whether data comes from a case-control study. |
na_omit |
A logical vector of length 1. Default to FALSE. Whether to remove NAs in the columns of interest before fitting the models. |
regmedint object, which is a list containing the mediator regression object, the outcome regression object, and the regression-based mediation results.
Use the regmedint function to fit models and set up regression-based causal mediation analysis.
Several methods are available to examine the regmedint object. print summary coef confint
library(regmedint) data(vv2015) 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) 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)
library(regmedint) data(vv2015) 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) 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)
Report the number of missing observations for each variables of interest relevant for the analysis
report_missing(data, yvar, avar, mvar, cvar, eventvar)
report_missing(data, yvar, avar, mvar, cvar, eventvar)
data |
Data frame containing the following relevant variables. |
yvar |
A character vector of length 1. Outcome variable name. It should be the time variable for the survival outcome. |
avar |
A character vector of length 1. Treatment variable name. |
mvar |
A character vector of length 1. Mediator variable name. |
cvar |
A character vector of length > 0. Covariate names. Use |
eventvar |
An character vector of length 1. Only required for survival outcome regression models. Note that the coding is 1 for event and 0 for censoring, following the R survival package convention. |
No return value, called for side effects.
Summarize the mreg_fit
, yreg_fit
, and the mediation analysis effect estimates.
## S3 method for class 'regmedint' summary( object, a0 = NULL, a1 = NULL, m_cde = NULL, c_cond = NULL, args_mreg_fit = list(), args_yreg_fit = list(), exponentiate = FALSE, level = 0.95, ... )
## S3 method for class 'regmedint' summary( object, a0 = NULL, a1 = NULL, m_cde = NULL, c_cond = NULL, args_mreg_fit = list(), args_yreg_fit = list(), exponentiate = FALSE, level = 0.95, ... )
object |
An object of the |
a0 |
A numeric vector of length 1 |
a1 |
A numeric vector of length 1 |
m_cde |
A numeric vector of length 1 The mediator value at which the controlled direct effect (CDE) conditional on the adjustment covariates is evaluated. If not provided, the default value supplied to the call to |
c_cond |
A numeric vector of the same length as |
args_mreg_fit |
A named list of argument to be passed to the method for the |
args_yreg_fit |
A named list of argument to be passed to the method for the |
exponentiate |
Whether to add exponentiated point and confidence limit estimates. When |
level |
Confidence level for the confidence intervals. |
... |
For compatibility with the generic. Ignored. |
A summary_regmedint
object, which is a list containing the summary objects of the mreg_fit
and the yreg_fit
as well as the mediation analysis results.
library(regmedint) data(vv2015) regmedint_obj <- 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 = 0.5, ## Model types mreg = "logistic", yreg = "survAFT_weibull", ## Additional specification interaction = TRUE, casecontrol = FALSE) ## Detailed result with summary summary(regmedint_obj) ## Add exponentiate results for non-linear outcome models summary(regmedint_obj, exponentiate = TRUE) ## Evaluate at different values summary(regmedint_obj, m_cde = 0, c_cond = 1) ## Change confidence level summary(regmedint_obj, m_cde = 0, c_cond = 1, level = 0.99)
library(regmedint) data(vv2015) regmedint_obj <- 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 = 0.5, ## Model types mreg = "logistic", yreg = "survAFT_weibull", ## Additional specification interaction = TRUE, casecontrol = FALSE) ## Detailed result with summary summary(regmedint_obj) ## Add exponentiate results for non-linear outcome models summary(regmedint_obj, exponentiate = TRUE) ## Evaluate at different values summary(regmedint_obj, m_cde = 0, c_cond = 1) ## Change confidence level summary(regmedint_obj, m_cde = 0, c_cond = 1, level = 0.99)
This is a version of summary.glm
modified to use the robust variance estimator sandwich
.
## S3 method for class 'regmedint_mod_poisson' summary(object, ...)
## S3 method for class 'regmedint_mod_poisson' summary(object, ...)
object |
A model object of the class |
... |
For compatibility with the generic. |
An object of the class summary.glm
This function extracts coef
from yreg_fit
and 3s with zeros appropriately to create a named vector consistently having the following elements:
(Intercept)
(a zero element is added for yreg = "survCox"
for which no intercept is estimated (the baseline hazard is left unspecified)),
avar
,
mvar
,
avar:mvar
(a zero element is added when interaction = FALSE
).
cvar
(this part is eliminated when cvar = NULL
),
emm_ac_yreg
(this part is eliminated when emm_ac_yreg = NULL
),
emm_mc_yreg
(this part is eliminated when emm_mc_yreg = NULL
).
theta_hat( yreg, yreg_fit, avar, mvar, cvar, emm_ac_yreg = NULL, emm_mc_yreg = NULL, interaction )
theta_hat( yreg, yreg_fit, avar, mvar, cvar, emm_ac_yreg = NULL, emm_mc_yreg = NULL, interaction )
yreg |
A character vector of length 1. Outcome regression type: |
yreg_fit |
Model fit object for yreg (outcome model). |
avar |
A character vector of length 1. Treatment variable name. |
mvar |
A character vector of length 1. Mediator variable name. |
cvar |
A character vector of length > 0. Covariate names. Use |
emm_ac_yreg |
A character vector of length > 0. Effect modifiers names. The covariate vector in treatment-covariate product term in the outcome model. |
emm_mc_yreg |
A character vector of length > 0. Effect modifiers names. The covariate vector in mediator-covariate product term in outcome model. |
interaction |
A logical vector of length 1. The presence of treatment-mediator interaction in the outcome model. Default to TRUE. |
A named numeric vector of coefficients.
Internal functions (usually) do not validate arguments, thus, we need to make sure informative errors are raised when the arguments are not safe for subsequent computation.
validate_args( data, yvar, avar, mvar, cvar, emm_ac_mreg, emm_ac_yreg, emm_mc_yreg, eventvar, a0, a1, m_cde, c_cond, mreg, yreg, interaction, casecontrol )
validate_args( data, yvar, avar, mvar, cvar, emm_ac_mreg, emm_ac_yreg, emm_mc_yreg, eventvar, a0, a1, m_cde, c_cond, mreg, yreg, interaction, casecontrol )
data |
Data frame containing the following relevant variables. |
yvar |
A character vector of length 1. Outcome variable name. It should be the time variable for the survival outcome. |
avar |
A character vector of length 1. Treatment variable name. |
mvar |
A character vector of length 1. Mediator variable name. |
cvar |
A character vector of length > 0. Covariate names. Use |
emm_ac_mreg |
A character vector of length > 0. Effect modifiers names. The covariate vector in treatment-covariate product term in the mediator model. |
emm_ac_yreg |
A character vector of length > 0. Effect modifiers names. The covariate vector in treatment-covariate product term in the outcome model. |
emm_mc_yreg |
A character vector of length > 0. Effect modifiers names. The covariate vector in mediator-covariate product term in outcome model. |
eventvar |
An character vector of length 1. Only required for survival outcome regression models. Note that the coding is 1 for event and 0 for censoring, following the R survival package convention. |
a0 |
A numeric vector of length 1. The reference level of treatment variable that is considered "untreated" or "unexposed". |
a1 |
A numeric vector of length 1. |
m_cde |
A numeric vector of length 1. Mediator level at which controlled direct effect is evaluated at. |
c_cond |
A numeric vector of the same length as |
mreg |
A character vector of length 1. Mediator regression type: |
yreg |
A character vector of length 1. Outcome regression type: |
interaction |
A logical vector of length 1. The presence of treatment-mediator interaction in the outcome model. Default to TRUE. |
casecontrol |
A logical vector of length 1. Default to FALSE. Whether data comes from a case-control study. |
No return value, called for side effects.
Check the structure of a proposed regmedint object for soundness.
validate_regmedint(x)
validate_regmedint(x)
x |
A |
No return value, called for side effects.
Extract variance estimates evaluated at a0
, a1
, m_cde
, and c_cond
.
## S3 method for class 'regmedint' vcov(object, a0 = NULL, a1 = NULL, m_cde = NULL, c_cond = NULL, ...)
## S3 method for class 'regmedint' vcov(object, a0 = NULL, a1 = NULL, m_cde = NULL, c_cond = NULL, ...)
object |
An object of the |
a0 |
A numeric vector of length 1 |
a1 |
A numeric vector of length 1 |
m_cde |
A numeric vector of length 1 The mediator value at which the controlled direct effect (CDE) conditional on the adjustment covariates is evaluated. If not provided, the default value supplied to the call to |
c_cond |
A numeric vector of the same length as |
... |
For compatibility with the generic. Ignored. |
A numeric matrix with the diagonals populated with variance estimates. Off-diagnonals are NA since these are not estimated.
library(regmedint) data(vv2015) regmedint_obj <- 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 = 0.5, ## Model types mreg = "logistic", yreg = "survAFT_weibull", ## Additional specification interaction = TRUE, casecontrol = FALSE) vcov(regmedint_obj) ## Evaluate at different values vcov(regmedint_obj, m_cde = 0, c_cond = 1)
library(regmedint) data(vv2015) regmedint_obj <- 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 = 0.5, ## Model types mreg = "logistic", yreg = "survAFT_weibull", ## Additional specification interaction = TRUE, casecontrol = FALSE) vcov(regmedint_obj) ## Evaluate at different values vcov(regmedint_obj, m_cde = 0, c_cond = 1)
Provide robust sandwich variance-covariance estimate using sandwich
.
## S3 method for class 'regmedint_mod_poisson' vcov(object, ...)
## S3 method for class 'regmedint_mod_poisson' vcov(object, ...)
object |
A model object of the class |
... |
For compatibility with the generic. |
A variance-covariance matrix using the sandwich
.
An example dataset from Valeri and VanderWeele (2015) <doi:10.1097/EDE.0000000000000253>.
vv2015
vv2015
A tibble with 100 rows and 7 variables:
Positive integer id.
Binary treatment assignment variable.
Binary mediator variable.
Time to event outcome variable.
Binary censoring indicator. Censored is 1.
Continuous confounder variable.
Binary event indicator. Event is 1.
https://www.hsph.harvard.edu/tyler-vanderweele/tools-and-tutorials/