Learn R Programming

mediation (version 2.0)

mediate: Causal Mediation Analysis

Description

Function to estimate causal mediation effects.

Usage

mediate(model.m, model.y, sims=1000, boot=FALSE, INT=FALSE, treat="treat.name",
mediator="med.name", control=NULL)

Arguments

model.m
R model object for mediator. Can be of class lm, polr, glm, or gam.
model.y
R model object for outcome. Can be of class lm, glm, gam, or rq.
sims
Number of Monte Carlo draws for nonparametric bootstrap or quasi-Bayesian approximation.
boot
If FALSE a quasi-Bayesian approximation is used for confidence interval, if TRUE nonparametric bootstrap will be used.
INT
If TRUE this indicates that treatment is interacted with mediator in model.y object. Default is FALSE.
treat
Name of binary treatment indicator.
mediator
Name of mediator variable.
control
Name of binary treatment indicator for control. Only necessary for gam() object with interaction.

Value

  • mediate returns an object of class "mediate". The function summary is used to obtain a table of the results. The object mediate is a list that contains the following components. Some of these elements are not available depending on whether INT is specified as TRUE or FALSE by the user.
  • d0point estimate for mediation effect under control.
  • d1point estimate for mediation effect under treatment.
  • d0.ciconfidence interval for mediation effect under control. For all confidence intervals, the confidence level is set to 95 percent.
  • d1.ciconfidence interval for mediation effect under control.
  • tau.coefpoint estimate for total effect.
  • tau.ciconfidence interval for total effect.
  • z0point estimate for direct effect under control.
  • z1point estimate for direct effect under treatment.
  • z0.ciconfidence interval for direct effect under control.
  • z1.ciconfidence interval for direct effect under control.
  • pct.coefpercentage of total effect due to mediation.
  • pct.ciconfidence interval for percentage of total effect due to mediation.
  • bootthe boot argument used.
  • INTthe INT argument used.
  • treatname of the 'treat' variable used.
  • mediatorname of the 'mediator' variable used.
  • call.mcall of the mediator model used.
  • call.ycall of the outcome model used.
  • env.menvironment in which the mediator model was fitted.
  • env.yenvironment in which the outcome model was fitted.

Warning

These functions assume that all missing values have been removed from the data set. This can be done using the na.omit() command before the outcome and mediation models are fitted.

Details

This is the workhorse function for estimating mediation effects for a variety of data types. For a continuous mediator variable and a continuous outcome variable, the results will be identical to the usual Baron and Kenny method. The function can, however, accomodate other data types including binary outcomes and mediators and discrete mediators. Continuous variables can also be modeled nonparametrically or semiparametrically.

In fitting the model.y object with an interaction between treatment and mediator, the user must input the interation in the format treatment:mediator. Furthermore, the user must make sure to set the INT option to TRUE since the current function does not sense the existence of the interaction term automatically.

Users should note that use of the nonparametric bootstrap requires several minutes of computing time.

References

Imai, Kosuke, Luke Keele and Dustin Tingley (2009) A General Approach to Causal Mediation Analysis. Imai, Kosuke, Luke Keele and Teppei Yamamoto (2009) Identification, Inference, and Sensitivity Analysis for Causal Mediation Effects. Imai, Kosuke, Luke Keele, Dustin Tingley and Teppei Yamamoto (2009) Causal Mediation Analysis in R.

See Also

See also medsens

Examples

Run this code
#Example with JOBS II Field experiment

#**For illustration purposes simulations set to low number**

data(jobs)

####################################################
#Continuous Outcome and Continuous Mediator
####################################################

b <- lm(job_seek ~ treat + econ_hard + sex + age, data=jobs)
c <- lm(depress2 ~ treat + job_seek + depress1 + econ_hard + sex + age, data=jobs)

#Calculates quantities using quasi-Bayesian approximation
#The general format of the function is to record two model objects
#The first for the mediator the second for the outcome variable 
continuous <- mediate(b, c, sims=10, treat="treat", mediator="job_seek")
summary(continuous)

#Calculates quantities using the non-parametric bootstrap - This takes several minutes
continuous_boot <- mediate(b, c, boot=TRUE, sims=10, treat="treat", mediator="job_seek")
summary(continuous_boot)

#Interaction term between treatment and mediator is included in the model
b <- lm(job_seek ~ treat + depress1, data=jobs)
d <- lm(depress2 ~ treat + job_seek + treat:job_seek + depress1, data=jobs)
cont.int <- mediate(b, d, sims=10, INT=TRUE, treat="treat", mediator="job_seek")
summary(cont.int)

######################################################
#Binary Outcome
######################################################

b <- lm(job_seek ~ treat + depress1, data=jobs)
c <- glm(work1 ~ treat + job_seek + depress1, family=binomial(link="probit"), data=jobs)
binary <- mediate(b, c, sims=10, treat="treat", mediator="job_seek")
summary(binary)

Run the code above in your browser using DataLab