R/00_package_information.R
, R/01_regmedint_class_ui.R
regmedint.Rd
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
)
Data frame containing the following relevant variables.
A character vector of length 1. Outcome variable name. It should be the time variable for the survival outcome.
A character vector of length 1. Treatment variable name.
A character vector of length 1. Mediator variable name.
A character vector of length > 0. Covariate names. Use NULL
if there is no covariate. However, this is a highly suspicious situation. Even if avar
is randomized, mvar
is not. Thus, there are usually some confounder(s) to account for the common cause structure (confounding) between mvar
and yvar
.
A character vector of length > 0. Effect modifiers names. The covariate vector in treatment-covariate product term in the mediator model.
A character vector of length > 0. Effect modifiers names. The covariate vector in treatment-covariate product term in the outcome model.
A character vector of length > 0. Effect modifiers names. The covariate vector in mediator-covariate product term in outcome model.
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.
A numeric vector of length 1. The reference level of treatment variable that is considered "untreated" or "unexposed".
A numeric vector of length 1.
A numeric vector of length 1. Mediator level at which controlled direct effect is evaluated at.
A numeric vector of the same length as cvar
. Covariate levels at which natural direct and indirect effects are evaluated at.
A character vector of length 1. Mediator regression type: "linear"
or "logistic"
.
A character vector of length 1. Outcome regression type: "linear"
, "logistic"
, "loglinear"
, "poisson"
, "negbin"
, "survCox"
, "survAFT_exp"
, or "survAFT_weibull"
.
A logical vector of length 1. The presence of treatment-mediator interaction in the outcome model. Default to TRUE.
A logical vector of length 1. Default to FALSE. Whether data comes from a case-control study.
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)
#> ### 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 4.3e-08
#> 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.
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)
#> ### Mediator model
#>
#> Call:
#> glm(formula = m ~ x + c + x:c, family = binomial(link = "logit"),
#> data = data)
#>
#> Deviance Residuals:
#> Min 1Q Median 3Q Max
#> -1.5689 -1.1585 0.8925 1.1242 1.4342
#>
#> Coefficients:
#> Estimate Std. Error z value Pr(>|z|)
#> (Intercept) -0.32727 0.34979 -0.936 0.349
#> x 0.30431 0.56789 0.536 0.592
#> c 0.24085 0.24688 0.976 0.329
#> x:c 0.09216 0.44624 0.207 0.836
#>
#> (Dispersion parameter for binomial family taken to be 1)
#>
#> Null deviance: 138.59 on 99 degrees of freedom
#> Residual deviance: 136.04 on 96 degrees of freedom
#> AIC: 144.04
#>
#> Number of Fisher Scoring iterations: 4
#>
#> ### Outcome model
#>
#> Call:
#> survival::survreg(formula = Surv(y, event) ~ x + m + x:m + c +
#> x:c + m:c, data = data, dist = "weibull")
#> Value Std. Error z p
#> (Intercept) -0.9959 0.2071 -4.81 1.5e-06
#> x 0.4185 0.3354 1.25 0.21
#> m -0.0216 0.3112 -0.07 0.94
#> c -0.1339 0.1405 -0.95 0.34
#> x:m 0.0905 0.4265 0.21 0.83
#> x:c 0.0327 0.2242 0.15 0.88
#> m:c 0.1275 0.1861 0.69 0.49
#> Log(scale) -0.0406 0.0814 -0.50 0.62
#>
#> Scale= 0.96
#>
#> Weibull distribution
#> Loglik(model)= -11.1 Loglik(intercept only)= -14.5
#> Chisq= 6.78 on 6 degrees of freedom, p= 0.34
#> Number of Newton-Raphson Iterations: 5
#> n= 100
#>
#> ### Mediation analysis
#> est se Z p lower upper
#> cde 0.60705735 0.52594922 1.1542128 0.2484129 -0.4237842 1.6378989
#> pnde 0.57902523 0.51447701 1.1254638 0.2603926 -0.4293312 1.5873816
#> tnie 0.05333600 0.10591830 0.5035579 0.6145721 -0.1542601 0.2609321
#> tnde 0.58889505 0.51488644 1.1437377 0.2527324 -0.4202638 1.5980539
#> pnie 0.04346618 0.09107534 0.4772552 0.6331804 -0.1350382 0.2219706
#> te 0.63236123 0.52776615 1.1981845 0.2308452 -0.4020414 1.6667639
#> pm 0.11082259 0.20960355 0.5287248 0.5969964 -0.2999928 0.5216380
#>
#> 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.