Perform (robust) mediation analysis via a bootstrap test or Sobel's test.
testMediation(x, ...)# S3 method for default
testMediation(x, y, m, covariates = NULL, data,
test = c("boot", "sobel"), alternative = c("twosided", "less", "greater"),
R = 5000, level = 0.95, type = c("bca", "perc"),
method = c("covariance", "regression"), robust = TRUE, control, ...)
# S3 method for fitMediation
testMediation(x, test = c("boot", "sobel"),
alternative = c("twosided", "less", "greater"), R = 5000, level = 0.95,
type = c("bca", "perc"), ...)
indirect(..., test = c("boot", "sobel"), method = "regression",
robust = FALSE)
either a numeric vector containing the independent variable, or
(if data
is supplied) a character string, an integer or a logical
vector specifying the corresponding column of data
.
either a numeric vector containing the dependent variable, or
(if data
is supplied) a character string, an integer or a logical
vector specifying the corresponding column of data
.
either a numeric vector containing the proposed mediator variable,
or (if data
is supplied) a character string, an integer or a logical
vector specifying the corresponding column of data
.
optional; either a numeric vector or data frame
containing additional covariates to be used as control variables, or (if
data
is supplied) a character, integer or logical vector specifying
the corresponding column of data
.
an optional data.frame
.
a character string specifying the test to be performed for
the indirect effect. Possible values are "boot"
(the default) for
the bootstrap, or "sobel"
for Sobel's test.
a character string specifying the alternative hypothesis
in the test for the indirect effect. Possible values are "twosided"
(the default), "less"
or "greater"
.
an integer giving the number of bootstrap replicates. The default is to use 5000 bootstrap replicates.
numeric; the confidence level of the confidence interval in the bootstrap test. The default is to compute a 95% confidence interval.
a character string specifying the type of confidence interval
to be computed in the bootstrap test. Possible values are "bca"
(the
default) for the bias-corrected and accelerated bootstrap, or "perc"
for the percentile bootstrap.
a character string specifying the method of estimation for
the mediation model. Possible values are "covariance"
(the default)
to estimate the effects via the covariance matrix, or "regression"
to estimate the effects via regressions. Note that the effects are always
estimated via regressions if control variables are specified via
covariates
.
a logical indicating whether to perform a robust test
(defaults to TRUE
). This is currently ignored if method
is
"regression"
.
if robust
is TRUE
and method
is
"covariance"
, a list of tuning parameters for covHuber
as generated by covControl
.
additional arguments to be passed to boot
in case of a bootstrap test.
An object inheriting from class "testMediation"
(class
"bootTestMediation"
if test
is "boot"
or
"sobelTestMediation"
if test
is "sobel"
) with the
following components:
numeric; the point estimate of the indirect effect.
a numeric vector of length two containing the bootstrap
confidence interval for the indirect effect (only
"bootTestMediation"
).
an object of class "boot"
containing
the bootstrap replicates of the indirect effect (only
"bootTestMediation"
).
numeric; the standard error of the indirect effect according
to Sobel's formula (only "sobelTestMediation"
).
numeric; the test statistic for Sobel's test (only
"sobelTestMediation"
).
numeric; the p-Value from Sobel's test (only
"sobelTestMediation"
).
a character string specifying the alternative hypothesis in the test for the indirect effect.
an integer giving the number of bootstrap replicates (only
"bootTestMediation"
).
numeric; the confidence level of the bootstrap confidence
interval (only "bootTestMediation"
).
a character string specifying the type of bootstrap
confidence interval (only "bootTestMediation"
).
an object inheriting from class
"fitMediation"
containing the estimation results for the
direct effect and the total effect in the mediation model.
If method
is "covariance"
and robust
is TRUE
,
the tests are based on a Huber M-estimator of location and scatter. For the
bootstrap test, the M-estimates are used to first clean the data via a
transformation. Then the standard bootstrap is performed with the cleaned
data. Note that this does not account for the variability from cleaning the
data.
A much more robust method based on robust regression will be available
soon. Currently, least squares regression is always performed if
method
is "regression"
.
indirect
is a wrapper function for performing non-robust mediation
analysis via regressions (inspired by Preacher & Hayes' SPSS
macro
INDIRECT
).
Preacher, K.J. and Hayes, A.F. (2004) SPSS and SAS procedures for estimating indirect effects in simple mediation models. Behavior Research Methods, Instruments, & Computers, 36(4), 717--731.
Sobel, M.E. (1982) Asymptotic confidence intervals for indirect effects in structural equation models. Sociological Methodology, 13, 290--312.
Zu, J. and Yuan, K.-H. (2010) Local influence and robust procedures for mediation analysis. Multivariate Behavioral Research, 45(1), 1--44.
# NOT RUN {
# control parameters
n <- 250 # number of observations
a <- b <- c <- 0.2 # true effects
t <- 2 # number of observations to contaminate
# draw clean observations
set.seed(20160911)
x <- rnorm(n)
m <- a * x + rnorm(n)
y <- b * m + c * x + rnorm(n)
# contaminate the first t observations
m[1:t] <- m[1:t] - 6
y[1:t] <- y[1:t] + 6
# perform mediation analysis
test <- testMediation(x, y, m)
summary(test)
# }
Run the code above in your browser using DataLab