Title: | Mediation Analysis using Interventional Effects |
---|---|
Description: | Implementing the interventional effects for mediation analysis for up to 3 mediators. The methods used are based on VanderWeele, Vansteelandt and Robins (2014) <doi:10.1097/ede.0000000000000034>, Vansteelandt and Daniel (2017) <doi:10.1097/ede.0000000000000596> and Chan and Leung (2020; unpublished manuscript, available on request from the author of this package). Linear regression, logistic regression and Poisson regression are used for continuous, binary and count mediator/outcome variables respectively. |
Authors: | Gary Chan [aut, cre, cph] |
Maintainer: | Gary Chan <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.2 |
Built: | 2025-02-24 04:03:19 UTC |
Source: | https://github.com/cran/intmed |
This package estimates mediation effect using the interventional effect approach and Monte Carlo simulation.
Performing mediation analysis based on the interventional effect
mediate( y, med, treat, c = NULL, ymodel, mmodel, treat_lv = 1, control_lv = 0, incint = NULL, inc_mmint = FALSE, data, sim = 1000, conf.level = 0.95, complete_analysis = FALSE, digits = 2, HTML_report = TRUE, summary_report = TRUE, cores = NULL, imputed_data = FALSE )
mediate( y, med, treat, c = NULL, ymodel, mmodel, treat_lv = 1, control_lv = 0, incint = NULL, inc_mmint = FALSE, data, sim = 1000, conf.level = 0.95, complete_analysis = FALSE, digits = 2, HTML_report = TRUE, summary_report = TRUE, cores = NULL, imputed_data = FALSE )
y |
The outcome variable. |
med |
A vector of the mediators. |
treat |
The exposure variable. |
c |
A vector of covariates. |
ymodel |
A character string specifying the outcome model. Current options are "regression" (for continuous variable), "logistic regression" (for binary variable), and "poisson regression" (for count variable) |
mmodel |
A vector of character string specifying the mediator models. Current options are "regression" (for continuous variable), "logistic regression" (for binary variable), and "poisson regression" (for count variable) |
treat_lv |
Value of the treatment variable used as the treatment condition. Default is 1. |
control_lv |
Value of the treatment variable used as the control condition. Default is 0. |
incint |
A vector of boolean specifying if the exposure-mediator interactions are included into the outcome model. Default is NULL. |
inc_mmint |
A boolean value specifying if the mediator-mediator interactions are included. Default is FALSE. |
data |
A data frame containing all the analysis variables. |
sim |
A numerical value specifying the number of simulation. Default is 1000. |
conf.level |
A numerical value specifying the confidence interval the the estimates. Default is 0.95 |
complete_analysis |
Multiple imputation will be used to fill in missing value. Setting this flag to FALSE will force the analysis to be conducted on complete data. |
digits |
Number of digits shown in the HTML report. |
HTML_report |
A boolean specifying if the HTML will be saved in the R working directory. |
summary_report |
A boolean specifying if a summary report will be printed. |
cores |
A numeric value specifying the number of cores to be used for the Monte Carlo simulation. If this is set to NULL (default), it will auto-detect the number of cores to be used. |
imputed_data |
A boolean specifiying if the data is an imputed data in long format. The dataset much contains .imp (to identify the imputed data) and .id (to identify each observ3ation in each imputed data). |
mediate
generates a report in HTML format based on results from the mediation analysis. This report is saved in the working directory.
The followings will returned by mediate
individual |
If there is no missing data or complete data analysis is performed, |
indirect1 , indirect2 , indirect3
|
Elements of the |
direct |
Element of the |
dependence |
Element of the |
interaction |
Element of the |
total |
Element of the |
prop1 , prop2 , prop3
|
Elements of the |
ymodel |
Element of the |
ymodel_te |
Element of the |
m1_model , m2_model , m3_model
|
Elements of the |
m2_model_cond |
Element of the |
m3_model_cond_m1 , m3_model_cond_m2 , m3_model_cond_m1m2
|
Element of the |
combined |
If multiple imputation is used for the analysis, |
direct |
Element of the |
indirect |
Element of the |
total |
Element of the |
prop |
Element of the |
interaction |
Element of the |
dependence |
Element of the |
mids |
Only available if multiple imputation is used. This is the |
y_pooled_res |
Only available if multiple imputation is used. This contains the pooled model estimates from the outcome model. |
m_pooled_res |
Only available if multiple imputation is used. This contains the pooled model estimates from the mediator model(s). |
model_summary |
This is a formatted table for the results from the mediator and outcome models. |
res_html |
This is the HTML code for the result report. |
summary_text |
This is the formatted text of the result summary. |
#One mediator, no HTML report. #Set HTML_report = TRUE if a HTML report is needed. med_res <- mediate(y = "y", med = c("m"), treat = "x", ymodel = "regression", mmodel = c("regression"), treat_lv = 1, control_lv = 0, incint = FALSE, inc_mmint = FALSE, conf.level = 0.9, data = sim_data, sim = 20, complete_analysis = TRUE, HTML_report = FALSE, digits = 3, cores = 2) #One mediator with exposure-mediator interaction #Results presented in a HTML report (This is the default). med_res <- mediate(y = "y", med = c("m"), treat = "x", ymodel = "regression", mmodel = c("regression"), treat_lv = 1, control_lv = 0, incint = TRUE, inc_mmint = FALSE, conf.level = 0.9, data = sim_data, sim = 1000, complete_analysis = TRUE, digits = 3, cores = 2) #Two mediators, complete data analysis and no HTML report. med_res <- mediate(y = "sub_misuse", med = c("dev_peer","sub_exp"), treat = "fam_int", c = c("conflict","gender"), ymodel = "logistic regression", mmodel = c("logistic regression", "logistic regression"), treat_lv = 1, control_lv = 0, conf.level = 0.9, data = substance, sim = 20, complete_analysis = TRUE, HTML_report = FALSE, digits = 3, cores = 2) #Two mediators with multiple imputation (missing data are imputed by default) #Results presented in a HTML report. med_res <- mediate(y = "sub_misuse", med = c("dev_peer","sub_exp"), treat = "fam_int", c = c("conflict","gender"), ymodel = "logistic regression", mmodel = c("logistic regression", "logistic regression"), treat_lv = 1, control_lv = 0, conf.level = 0.9, data = substance, sim = 1000, digits = 3, cores = 2)
#One mediator, no HTML report. #Set HTML_report = TRUE if a HTML report is needed. med_res <- mediate(y = "y", med = c("m"), treat = "x", ymodel = "regression", mmodel = c("regression"), treat_lv = 1, control_lv = 0, incint = FALSE, inc_mmint = FALSE, conf.level = 0.9, data = sim_data, sim = 20, complete_analysis = TRUE, HTML_report = FALSE, digits = 3, cores = 2) #One mediator with exposure-mediator interaction #Results presented in a HTML report (This is the default). med_res <- mediate(y = "y", med = c("m"), treat = "x", ymodel = "regression", mmodel = c("regression"), treat_lv = 1, control_lv = 0, incint = TRUE, inc_mmint = FALSE, conf.level = 0.9, data = sim_data, sim = 1000, complete_analysis = TRUE, digits = 3, cores = 2) #Two mediators, complete data analysis and no HTML report. med_res <- mediate(y = "sub_misuse", med = c("dev_peer","sub_exp"), treat = "fam_int", c = c("conflict","gender"), ymodel = "logistic regression", mmodel = c("logistic regression", "logistic regression"), treat_lv = 1, control_lv = 0, conf.level = 0.9, data = substance, sim = 20, complete_analysis = TRUE, HTML_report = FALSE, digits = 3, cores = 2) #Two mediators with multiple imputation (missing data are imputed by default) #Results presented in a HTML report. med_res <- mediate(y = "sub_misuse", med = c("dev_peer","sub_exp"), treat = "fam_int", c = c("conflict","gender"), ymodel = "logistic regression", mmodel = c("logistic regression", "logistic regression"), treat_lv = 1, control_lv = 0, conf.level = 0.9, data = substance, sim = 1000, digits = 3, cores = 2)
A simulated dataset with three variables.
sim_data
sim_data
A data frame with 1000 rows:
Exposure variable
Mediator
Outcome
A fictitious dataset about family intervention and youth substance misuse
substance
substance
A data frame with 553 rows:
Gender of the participants, Male/Female.
Level of family conflict. Higher value represents higher level of conflict.
Engagement with deviant peer groups. 1: Yes; 0: No
Experimentation with substance. 1: Yes; 0: No
Participation in family intervention during adolescence. 1: Yes; 0: No
Substance misuse in young adulthood. 1: Yes; 0: No