ivmediate(model.t, model.m, model.y, ci = TRUE, sims = 1000, boot = TRUE,
enc = "enc.name", treat = "treat.name", mediator = "med.name",
conf.level = .95, long = TRUE, dropobs = FALSE,
multicore = FALSE, mc.cores = getOption("mc.cores", 2L))mclapply).ivmediate returns an object of class 'ivmediate', a list that contains the components listed below. Some of these elements are not available depending on the values of the 'ci' and 'long' options.The function summary (i.e., summary.ivmediate) can be used to obtain a table of the results. The function plot (i.e., plot.ivmediate) can be used to produce a plot of the estimated effects along with their confidence intervals.
integrate encountered computational problems when calculating dc0 and dc1, respectively.Although the method is quite general and accommodate various types of mediator and outcome variables, the current function can only handle binary variables (modeled via glm with family=binomial) and continuous variables (modeled via lm). In addition, when the mediator is continuous and its model contains any predictor other than the encouragement and actual treatment, computation of confidence intervals is extremely slow because it requires numerical integration via integrate for each observation in each simulation iteration. Users are advised to use a powerful computer (preferably equipped with multiple CPU cores and a non-Windows operating system) for such calculation, especially if the data contain many rows and/or the desired number of simulations is large.
Yamamoto, T. (2013). Identification and Estimation of Causal Mediation Effects with Treatment Noncompliance. Unpublished manuscript.
plot.ivmediate, summary.ivmediate# Examples with JOBS II Field Experiment
# ** For illustration purposes a small number of simulations are used **
require(parallel)
require(MASS)
data(jobs)
a <- lm(comply ~ treat + sex + age + marital + nonwhite + educ + income,
data = jobs)
b <- glm(job_dich ~ comply + treat + sex + age + marital + nonwhite + educ + income,
data = jobs, family = binomial)
c <- lm(depress2 ~ job_dich * (comply + treat) + sex + age + marital + nonwhite + educ + income,
data = jobs)
out <- ivmediate(a, b, c, sims = 50, boot = FALSE,
enc = "treat", treat = "comply", mediator = "job_dich")
summary(out)
plot(out)Run the code above in your browser using DataLab