Description Usage Arguments Details Value Note Author(s) References See Also Examples
View source: R/test_mediation.R
Perform (robust) mediation analysis via a (fast and robust) bootstrap test or Sobel's test.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19  test_mediation(data, ...)
## Default S3 method:
test_mediation(data, x, y, m, covariates = NULL,
test = c("boot", "sobel"), alternative = c("twosided", "less",
"greater"), R = 5000, level = 0.95, type = c("bca", "perc"),
method = c("regression", "covariance"), robust = TRUE,
median = FALSE, control, ...)
## S3 method for class 'fit_mediation'
test_mediation(data, test = c("boot", "sobel"),
alternative = c("twosided", "less", "greater"), R = 5000,
level = 0.95, type = c("bca", "perc"), ...)
robmed(..., test = "boot", method = "regression", robust = TRUE,
median = FALSE)
indirect(..., test = "boot", method = "regression", robust = FALSE,
median = FALSE)

data 
a data frame containing the variables. Alternatively, this can
be a mediation model fit as returned by 
... 
additional arguments to be passed down. For the bootstrap
tests, those can be used to specify arguments of 
x 
a character string, an integer or a logical vector specifying the
column of 
y 
a character string, an integer or a logical vector specifying the
column of 
m 
a character, integer or logical vector specifying the columns of

covariates 
optional; a character, integer or logical vector
specifying the columns of 
test 
a character string specifying the test to be performed for
the indirect effect. Possible values are 
alternative 
a character string specifying the alternative hypothesis
in the test for the indirect effects. Possible values are 
R 
an integer giving the number of bootstrap replicates. The default is to use 5000 bootstrap replicates. 
level 
numeric; the confidence level of the confidence interval in the bootstrap test. The default is to compute a 95% confidence interval. 
type 
a character string specifying the type of confidence interval
to be computed in the bootstrap test. Possible values are 
method 
a character string specifying the method of estimation for
the mediation model. Possible values are 
robust 
a logical indicating whether to perform a robust test
(defaults to 
median 
a logical indicating if the effects should be estimated via
median regression (defaults to 
control 
a list of tuning parameters for the corresponding robust
method. For robust regression ( 
If method
is "regression"
, robust
is TRUE
and
median
is FALSE
(the defaults), the tests are based on robust
regressions with lmrob
. The bootstrap test is
thereby performed via the fast and robust bootstrap.
Note that the regression estimator 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.
If method
is "regression"
, robust
is TRUE
and
median
is TRUE
, the tests are based on median regressions with
rq
and the standard bootstrap (). 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.
If method
is "covariance"
and robust
is TRUE
,
the tests are based on a Huber Mestimator of location and scatter. For the
bootstrap test, the Mestimates are used to first clean the data via a
transformation. Then the standard bootstrap is performed with the cleaned
data. Note that this covariancebased 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.
indirect
is a wrapper function for performing nonrobust mediation
analysis via regressions and the bootstrap (inspired by Preacher & Hayes'
SPSS
macro INDIRECT
).
An object inheriting from class "test_mediation"
(class
"boot_test_mediation"
if test
is "boot"
or
"sobel_test_mediation"
if test
is "sobel"
) with the
following components:
ab 
a numeric vector containing the point estimates of the indirect effects. 
ci 
a numeric vector of length two or a matrix of two columns
containing the bootstrap confidence intervals for the indirect effects
(only 
reps 
an object of class 
se 
numeric; the standard error of the indirect effect according
to Sobel's formula (only 
statistic 
numeric; the test statistic for Sobel's test (only

p_value 
numeric; the pvalue from Sobel's test (only

alternative 
a character string specifying the alternative hypothesis in the test for the indirect effects. 
R 
an integer giving the number of bootstrap replicates (only

level 
numeric; the confidence level of the bootstrap confidence
interval (only 
type 
a character string specifying the type of bootstrap
confidence interval (only 
fit 
an object inheriting from class

For the fast and robust bootstrap, the simpler correction of SalibianBarrera & Van Aelst (2008) is used rather than the originally proposed correction of SalibianBarrera & Zamar (2002).
Andreas Alfons
Alfons, A., Ates, N.Y. and Groenen, P.J.F. (2018) A robust bootstrap test for mediation analysis. ERIM Report Series in Management, Erasmus Research Institute of Management. URL https://hdl.handle.net/1765/109594.
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.
SalibianBarrera, M. and Van Aelst, S. (2008) Robust model selection using fast and robust bootstrap. Computational Statistics & Data Analysis, 52(12), 5121–5135
SalibianBarrera, 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.
coef
,
confint
,
fortify
and
plot
methods, p_value
boot
, lmrob
,
lm
, cov_Huber
, cov_ML
1 2 3 4 5 6  data("BSG2014")
test < test_mediation(BSG2014,
x = "ValueDiversity",
y = "TeamCommitment",
m = "TaskConflict")
summary(test)

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.