Learn R Programming

robmed (version 0.1.1)

testMediation: (Robust) mediation analysis

Description

Perform (robust) mediation analysis via a bootstrap test or Sobel's test.

Usage

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)

Arguments

x

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.

y

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.

m

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.

covariates

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.

data

an optional data.frame.

test

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.

alternative

a character string specifying the alternative hypothesis in the test for the indirect effect. Possible values are "twosided" (the default), "less" or "greater".

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 "bca" (the default) for the bias-corrected and accelerated bootstrap, or "perc" for the percentile bootstrap.

method

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.

robust

a logical indicating whether to perform a robust test (defaults to TRUE). This is currently ignored if method is "regression".

control

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.

Value

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 "bootTestMediation").

reps

an object of class "boot" containing the bootstrap replicates of the indirect effect (only "bootTestMediation").

se

numeric; the standard error of the indirect effect according to Sobel's formula (only "sobelTestMediation").

statistic

numeric; the test statistic for Sobel's test (only "sobelTestMediation").

pValue

numeric; the p-Value from Sobel's test (only "sobelTestMediation").

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 "bootTestMediation").

level

numeric; the confidence level of the bootstrap confidence interval (only "bootTestMediation").

type

a character string specifying the type of bootstrap confidence interval (only "bootTestMediation").

fit

an object inheriting from class "fitMediation" containing the estimation results for the direct effect and the total effect in the mediation model.

Details

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).

References

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.

See Also

fitMediation

coef, confint, fortify and plot methods

boot, covHuber, covML, lm

Examples

Run this code
# 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