(Robustly) estimate the effects in a mediation model.
fitMediation(x, y, m, covariates = NULL, data, method = c("covariance",
"regression"), robust = TRUE, control, ...)
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 method of
estimation. 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 robustly estimate the effects
(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 can be used to specify tuning parameters
directly instead of via control
.
An object inheriting from class "fitMediation"
(class
"regFitMediation"
if method
is "regression"
or
"covFitMediation"
if method
is "covariance"
) with
the following components:
numeric; the point estimate of the effect of the independent variable on the proposed mediator variable.
numeric; the point estimate of the direct effect of the proposed mediator variable on the dependent variable.
numeric; the point estimate of the direct effect of the independent variable on the dependent variable.
numeric; the point estimate of the total effect of the independent variable on the dependent variable.
a logical indicating whether the effects were estimated robustly.
an object of class "lm"
containing the
estimation results from the regression of the proposed mediator variable
on the independent variable (only "regFitMediation"
).
an object of class "lm"
containing the
estimation results from the regression of the dependent variable on the
proposed mediator and independent variables (only "regFitMediation"
).
an object of class "lm"
containing the
estimation results from the regression of the dependent variable on the
independent variable (only "regFitMediation"
).
an object of class "covHuber"
or
"covML"
containing the covariance matrix estimates (only
"covFitMediation"
).
a data frame containing the independent, dependent and proposed mediator variables.
If method
is "covariance"
and robust
is TRUE
(the default), the effects are estimated based on a Huber M-estimator of
location and scatter.
A much more robust method based on robust regression will be available
soon. Currently, least squares regression is always performed if
method
is "regression"
.
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
# fit mediation model
fitMediation(x, y, m)
# }
Run the code above in your browser using DataLab