mediate: Performing mediation analysis based on the interventional...

Description Usage Arguments Value Examples

View source: R/mediate.R

Description

Performing mediation analysis based on the interventional effect

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
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
)

Arguments

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

Value

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, individual is a list containing the models for the outcome and mediators, and also the draws for the direct and indirect effect and other relevant estimates from each of the simulation. If multiple imputation is used for the analysis, individual is a vector of lists containing these information from the mediation analysis conducted on each imputed dataset. Each list contains the following items.

indirect1, indirect2, indirect3

Elements of the individual list. Vectors of draws for the indirect effect through mediators 1, 2 and 3.

direct

Element of the individual list. Vector of draws for the direct effect of exposure.

dependence

Element of the individual list. This is only available when there are two mediators. Vector of draws for the effect mediated through the dependence of the mediators.

interaction

Element of the individual list. This is only available when there are two mediators. Vector of draws for the effect mediated through the interaction of the mediators.

total

Element of the individual list. Vector of draws for total causal effect of the exposure.

prop1, prop2, prop3

Elements of the individual list. Vector of draws for the proportion of effects mediated through mediator 1, 2 and 3.

ymodel

Element of the individual list. An object of the class lm or glm, a R object containing the fit and estimate of the outcome model.

ymodel_te

Element of the individual list. Similar to ymodel, but did not have the mediators as predictors in the model.

m1_model, m2_model, m3_model

Elements of the individual list. Objects of the class lm or glm containing the fit and estimates of the mediator models.

m2_model_cond

Element of the individual list. Only available when there are more than one mediator. Object of the class lm or glm similar to m2_model, but included mediator 1 as a predictor.

m3_model_cond_m1, m3_model_cond_m2, m3_model_cond_m1m2

Element of the individual list. Only available where there are more than two mediators. Object of the class lm or glm similar to m3_model, but with mediator 1, mediator 2 and both as predictors respectively.

combined

If multiple imputation is used for the analysis, combined is a list containing estimates for the direct/indirect effect and relevant estimates from all simulations across all imputed datasets. If there is no missing data, it contains lists of draws for the direct and indirect effect and relevant estimates from each of the simulation.

direct

Element of the combined list. A vector of estimates of direct effect from all simulations in all imputed datasets. If multiple imputation is not performed, it is a list of estimates of direct effect from all simulations.

indirect

Element of the combined list. A list containing vectors of draws of indirect effect through mediator 1, 2 and 3 from all simulations in all imputed datasets. If multiple imputation is not performed, it is a list of estimates of direct effect from all simulations.

total

Element of the combined list. A vector of draws of total effect of exposure from all simulations in all imputed datasets. If multiple imputation is not performed, it is a list of estimates of direct effect from all simulations.

prop

Element of the combined list. A list containing vectors of draws of proportion of effects mediated through mediator 1, 2 and 3 from all simulations in all imputed datasets. If multiple imputation is not performed, it is a list of estimates of direct effect from all simulations.

interaction

Element of the combined list. Only available when there are two mediators. A vector of draws of effect mediated through the interaction between mediators from all simulations in all imputed datasets. If multiple imputation is not performed, it is a list of estimates of direct effect from all simulations.

dependence

Element of the combined list. Only available when there are two mediators. A vector of draws of effect mediated through the dependence between mediators from all simulations in all imputed dataset. If multiple imputation is not performed, it is a list of estimates of direct effect from all simulations.

mids

Only available if multiple imputation is used. This is the mids object from mice, the multiple imputation package by Stef van Buuren.

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.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#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)

intmed documentation built on Aug. 28, 2020, 1:10 a.m.