Description Usage Arguments Details Value Author(s) References See Also Examples
View source: R/testMediation.R
Perform (robust) mediation analysis via a bootstrap test or Sobel's test.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15  testMediation(x, ...)
## Default S3 method:
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 class '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)

x 
either a numeric vector containing the independent variable, or
(if 
y 
either a numeric vector containing the dependent variable, or
(if 
m 
either a numeric vector containing the proposed mediator variable,
or (if 
covariates 
optional; either a numeric vector or data frame
containing additional covariates to be used as control variables, or (if

data 
an optional 
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 effect. 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 
control 
if 
... 
additional arguments to be passed to 
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 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 nonrobust mediation
analysis via regressions (inspired by Preacher & Hayes' SPSS
macro
INDIRECT
).
An object inheriting from class "testMediation"
(class
"bootTestMediation"
if test
is "boot"
or
"sobelTestMediation"
if test
is "sobel"
) with the
following components:
ab 
numeric; the point estimate of the indirect effect. 
ci 
a numeric vector of length two containing the bootstrap
confidence interval for the indirect effect (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

pValue 
numeric; the pValue from Sobel's test (only

alternative 
a character string specifying the alternative hypothesis in the test for the indirect effect. 
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

Andreas Alfons
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.
coef
,
confint
,
fortify
and
plot
methods
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18  # 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)

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