Perform (robust) mediation analysis via a (fast and robust) bootstrap test or Sobel's test.
test_mediation(object, ...)# S3 method for formula
test_mediation(
formula,
data,
test = c("boot", "sobel"),
alternative = c("twosided", "less", "greater"),
R = 5000,
level = 0.95,
type = c("bca", "perc"),
order = c("first", "second"),
method = c("regression", "covariance"),
robust = TRUE,
family = "gaussian",
contrast = FALSE,
fit_yx = TRUE,
control = NULL,
...
)
# S3 method for default
test_mediation(
object,
x,
y,
m,
covariates = NULL,
test = c("boot", "sobel"),
alternative = c("twosided", "less", "greater"),
R = 5000,
level = 0.95,
type = c("bca", "perc"),
order = c("first", "second"),
method = c("regression", "covariance"),
robust = TRUE,
family = "gaussian",
contrast = FALSE,
fit_yx = TRUE,
control = NULL,
...
)
# S3 method for fit_mediation
test_mediation(
object,
test = c("boot", "sobel"),
alternative = c("twosided", "less", "greater"),
R = 5000,
level = 0.95,
type = c("bca", "perc"),
order = c("first", "second"),
...
)
robmed(..., test = "boot", method = "regression", robust = TRUE)
the first argument will determine the method of the generic
function to be dispatched. For the default method, this should be a data
frame containing the variables. There is also a method for a mediation
model fit as returned by fit_mediation()
.
additional arguments to be passed down. For the bootstrap
tests, those can be used to specify arguments of boot()
,
for example for parallel computing.
an object of class "formula" (or one that can be coerced to
that class): a symbolic description of the model to be fitted. Hypothesized
mediator variables should be wrapped in a call to m()
(see
examples), and any optional control variables should be wrapped in a call to
covariates()
.
for the formula
method, a data frame containing the
variables.
a character string specifying the test to be performed for
the indirect effects. Possible values are "boot"
(the default) for
the bootstrap, or "sobel"
for Sobel's test. Currently, Sobel's test
is not implemented for models with multiple indirect effects.
a character string specifying the alternative hypothesis
in the test for the indirect effects. 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 order of approximation of
the standard error in Sobel's test. Possible values are "first"
(the default) for a first-order approximation, and "second"
for a
second-order approximation.
a character string specifying the method of estimation for
the mediation model. Possible values are "regression"
(the default)
to estimate the effects via regressions, or "covariance"
to estimate
the effects via the covariance matrix. Note that the effects are
always estimated via regressions if more than one independent variable or
hypothesized mediator is specified, or if control variables are supplied.
a logical indicating whether to perform a robust test
(defaults to TRUE
). For estimation via regressions
(method = "regression"
), this can also be a character string, with
"MM"
specifying the MM-estimator of regression, and "median"
specifying median regression.
a character string specifying the error distribution to be
used in maximum likelihood estimation of regression models. Possible values
are "gaussian"
for a normal distribution (the default),
skewnormal
for a skew-normal distribution, "student"
for
Student's t distribution, "skewt"
for a skew-t distribution, or
"select"
to select among these four distributions via BIC (see
fit_mediation()
for details). This is only relevant if
method = "regression"
and robust = FALSE
.
a logical indicating whether to compute pairwise contrasts
of the indirect effects (defaults to FALSE
). This can also be a
character string, with "estimates"
for computing the pairwise
differences of the indirect effects (such that it is tested whether two
indirect effects are equal), and "absolute"
for computing the
pairwise differences of the absolute values of the indirect effects
(such that it is tested whether two indirect effects are equal in
magnitude). This is only relevant for models with multiple indirect
effects, which are currently only implemented for estimation via
regressions (method = "regression"
).
a logical indicating whether to fit the regression model
y ~ x + covariates
to estimate the total effect (the default is
TRUE
). This is only relevant if method = "regression"
and
robust = FALSE
.
a list of tuning parameters for the corresponding robust
method. For robust regression (method = "regression"
, and
robust = TRUE
or robust = "MM"
), a list of tuning
parameters for lmrob()
as generated by
reg_control()
. For winsorized covariance matrix estimation
(method = "covariance"
and robust = TRUE
), a list of tuning
parameters for cov_Huber()
as generated by
cov_control()
. No tuning parameters are necessary for median
regression (method = "regression"
and robust = "median"
).
a character, integer or logical vector specifying the columns of
object
containing the independent variables.
a character string, an integer or a logical vector specifying the
column of object
containing the dependent variable.
a character, integer or logical vector specifying the columns of
object
containing the hypothesized mediator variables.
optional; a character, integer or logical vector
specifying the columns of object
containing additional covariates to
be used as control variables.
An object inheriting from class "test_mediation"
(class
"boot_test_mediation"
if test = "boot"
or
"sobel_test_mediation"
if test = "sobel"
) with the
following components:
a numeric vector containing the bootstrap point estimates of the
effects of the independent variables on the proposed mediator variables
(only "boot_test_mediation"
).
a numeric vector containing the bootstrap point estimates of the
direct effects of the proposed mediator variables on the dependent variable
(only "boot_test_mediation"
).
a numeric vector containing the bootstrap point estimates of
the direct effects of the independent variables on the dependent variable
(only "boot_test_mediation"
).
a numeric vector containing the bootstrap point estimates of
the total effects of the independent variables on the dependent variable
(only "boot_test_mediation"
).
a numeric vector containing the bootstrap point estimates of the
indirect effects (only "boot_test_mediation"
).
a numeric vector of length two or a matrix of two columns
containing the bootstrap confidence intervals for the indirect effects
(only "boot_test_mediation"
).
an object of class "boot"
containing
the bootstrap replicates of the effects (only "boot_test_mediation"
).
numeric; the standard error of the indirect effect according
to Sobel's formula (only "sobel_test_mediation"
).
numeric; the test statistic for Sobel's test (only
"sobel_test_mediation"
).
numeric; the p-value from Sobel's test (only
"sobel_test_mediation"
).
a character string specifying the alternative hypothesis in the test for the indirect effects.
an integer giving the number of bootstrap replicates (only
"boot_test_mediation"
).
numeric; the confidence level of the bootstrap confidence
interval (only "boot_test_mediation"
).
a character string specifying the type of bootstrap
confidence interval (only "boot_test_mediation"
).
an object inheriting from class
"fit_mediation"
containing the estimation results of the
mediation model on the original data.
With method = "regression"
, and robust = TRUE
or
robust = "MM"
, the tests are based on robust regressions with the
MM-estimator from lmrob()
. The bootstrap test is
thereby performed via the fast and robust bootstrap. This is the default
behavior.
Note that the MM-estimator of regression implemented in
lmrob()
can be seen as weighted least squares
estimator, where the weights are dependent on how much an observation is
deviating from the rest. The trick for the fast and robust bootstrap is
that on each bootstrap sample, first a weighted least squares estimator
is computed (using those robustness weights from the original sample)
followed by a linear correction of the coefficients. The purpose of this
correction is to account for the additional uncertainty of obtaining the
robustness weights.
With method = "regression"
and robust = "median"
, the tests
are based on median regressions with rq()
. Note
that the bootstrap test is performed via the standard bootstrap, as the
fast and robust bootstrap is not applicable. Unlike the robust regressions
described above, median regressions are not robust against outliers in
the explanatory variables, and the standard bootstrap can suffer from
oversampling of outliers in the bootstrap samples.
With method = "covariance"
and robust = 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 covariance-based approach is less robust than the
approach based on robust regressions described above. Furthermore, the
bootstrap does not account for the variability from cleaning the data.
robmed()
is a wrapper function for performing robust mediation
analysis via regressions and the fast and robust bootstrap.
Alfons, A., Ates, N.Y. and Groenen, P.J.F. (2021) A robust bootstrap test for mediation analysis. Organizational Research Methods, 10.1177/1094428121999096.
Azzalini, A. and Arellano-Valle, R. B. (2013) Maximum penalized likelihood estimation for skew-normal and skew-t distributions. Journal of Statistical Planning and Inference, 143(2), 419--433.
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.
Preacher, K.J. and Hayes, A.F. (2008) Asymptotic and resampling strategies for assessing and comparing indirect effects in multiple mediator models. Behavior Research Methods, 40(3), 879--891.
Salibian-Barrera, M. and Van Aelst, S. (2008) Robust model selection using fast and robust bootstrap. Computational Statistics & Data Analysis, 52(12), 5121--5135
Salibian-Barrera, M. and Zamar, R. (2002) Bootstrapping robust estimates of regression. The Annals of Statistics, 30(2), 556--582.
Sobel, M.E. (1982) Asymptotic confidence intervals for indirect effects in structural equation models. Sociological Methodology, 13, 290--312.
Yuan, Y. and MacKinnon, D.P. (2014) Robust mediation analysis based on median regression. Psychological Methods, 19(1), 1--20.
Zu, J. and Yuan, K.-H. (2010) Local influence and robust procedures for mediation analysis. Multivariate Behavioral Research, 45(1), 1--44.
# NOT RUN {
data("BSG2014")
## The results in Alfons et al. (2021) were obtained with an
## older version of the random number generator. To reproduce
## those results, uncomment the call to RNGversion() below.
# RNGversion("3.5.3")
seed <- 20150601
# formula interface
set.seed(seed)
test1 <- test_mediation(TeamCommitment ~ m(TaskConflict) + ValueDiversity,
data = BSG2014)
summary(test1)
# default method
set.seed(seed)
test2 <- test_mediation(BSG2014,
x = "ValueDiversity",
y = "TeamCommitment",
m = "TaskConflict")
summary(test2)
# }
Run the code above in your browser using DataLab