Estimate quantities for causal mediation analysis using an instrumental variable estimator.
mediate_tsls(model.m, model.y, treat = "treat.name", conf.level = 0.95,
robustSE = FALSE, cluster = NULL, boot = FALSE, sims = 1000,
est_se = TRUE, ...)
mediate
returns an object of class "mediate
",
"mediate.tsls
", a list that contains the components listed below.
The function summary
can be used to obtain a table of the results.
point estimate for average causal mediation effects.
confidence intervals for average causal mediation effect. The confidence level is set at the value specified in 'conf.level'.
point estimates for average direct effect.
confidence intervals for average direct effect.
two-sided p-values for average causal direct effect.
the "proportions mediated", or the size of the average causal mediation effect relative to the total effect.
confidence intervals for the proportion mediated.
two-sided p-values for proportion mediated.
point estimate for total effect.
confidence interval for total effect.
two-sided p-values for total effect.
logical, the boot
argument used.
a character string indicating the name of the 'treat' variable used.
a character string indicating the name of the 'mediator' variable used.
a logical value indicating whether the model specification allows the effects to differ between the treatment and control conditions.
the confidence level used.
the outcome model used.
the mediator model used.
number of observations in the model frame for 'model.m' and 'model.y'. May differ from the numbers in the original models input to 'mediate' if 'dropobs' was 'TRUE'.
the clusters used.
a fitted model object for mediator, of class lm
.
a fitted model object for outcome, of class lm
.
a character string indicating the name of the treatment variable used in the models.
level of the returned two-sided confidence intervals. Default is to return the 2.5 and 97.5 percentiles of the simulated quantities.
a logical value. If 'TRUE', heteroskedasticity-consistent standard errors will be used. Default is 'FALSE'.
a variable indicating clusters for standard errors. Note that this should be a vector of cluster indicators itself, not a character string for the name of the variable.
a logical value. if FALSE
analytic confidence intervals
based on Aroian (1947) will be used; if TRUE
nonparametric
bootstrap will be used. Default is FALSE
.
number of Monte Carlo draws for nonparametric bootstrap.
estimate standard errors. Primarily for internal use. Default is TRUE
.
other arguments passed to vcovCL in the sandwich package:
typically the type
argument for heteroskedasticity-consistent
standard errors.
Aroian, L. A. 1947. The probability function of the product of two normally distributed variables. *Annals of Mathematical Statistics,* 18, 265-271.
# Generate data. We use TSLS to address unobserved confounding (n).
set.seed(123)
sims <- 1000
dat <- data.frame(z = sample(0:1, sims, replace = TRUE),
t = sample(0:1, sims, replace = TRUE))
dat$n <- rnorm(sims, mean = 1)
dat$m <- rnorm(sims, mean = dat$z * 0.3 + dat$t * 0.2 + dat$n * 0.7, sd = 0.2)
dat$y <- rnorm(sims, mean = 5 + dat$t + dat$m * (-3) + dat$n, sd = 1)
model.m <- lm(m ~ t + z, data = dat)
model.y <- lm(y ~ t + m, data = dat)
cluster <- factor(sample(1:3, sims, replace = TRUE))
med <- mediate_tsls(model.m, model.y, cluster = cluster, treat = "t")
summary(med)
Run the code above in your browser using DataLab