Learn R Programming

robmed (version 0.9.0)

fit_mediation: (Robustly) fit a mediation model

Description

(Robustly) estimate the effects in a mediation model.

Usage

fit_mediation(object, ...)

# S3 method for formula fit_mediation(formula, data, ...)

# S3 method for default fit_mediation( object, x, y, m, covariates = NULL, method = c("regression", "covariance"), robust = TRUE, family = "gaussian", contrast = FALSE, fit_yx = TRUE, control = NULL, ... )

Arguments

object

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.

additional arguments to be passed down. For the default method, this can be used to specify tuning parameters directly instead of via control.

formula

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

data

for the formula method, a data frame containing the variables.

x

a character, integer or logical vector specifying the columns of object containing the independent variables.

y

a character string, an integer or a logical vector specifying the column of object containing the dependent variable.

m

a character, integer or logical vector specifying the columns of object containing the hypothesized mediator variables.

covariates

optional; a character, integer or logical vector specifying the columns of object containing additional covariates to be used as control variables.

method

a character string specifying the method of estimation. 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.

robust

a logical indicating whether to robustly estimate the effects (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.

family

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 ‘Details’). This is only relevant if method = "regression" and robust = FALSE.

contrast

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, and "absolute" for computing the pairwise differences of the absolute values of the indirect effects. This is only relevant for models with multiple indirect effects, which are currently only implemented for estimation via regressions (method = "regression").

fit_yx

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.

control

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

Value

An object inheriting from class "fit_mediation" (class "reg_fit_mediation" if method = "regression" or "cov_fit_mediation" if method = "covariance") with the following components:

a

a numeric vector containing the point estimates of the effects of the independent variables on the proposed mediator variables.

b

a numeric vector containing the point estimates of the direct effects of the proposed mediator variables on the dependent variable.

direct

a numeric vector containing the point estimates of the direct effects of the independent variables on the dependent variable.

total

a numeric vector containing the point estimates of the total effects of the independent variables on the dependent variable.

ab

a numeric vector containing the point estimates of the indirect effects.

fit_mx

an object of class "lmrob", "rq", "lm" or "lmse" containing the estimation results from the regression of the proposed mediator variable on the independent variables, or a list of such objects in case of more than one hypothesized mediator (only "reg_fit_mediation").

fit_ymx

an object of class "lmrob", "rq", "lm" or "lmse" containing the estimation results from the regression of the dependent variable on the proposed mediator and independent variables (only "reg_fit_mediation").

fit_yx

an object of class "lm" or "lmse" containing the estimation results from the regression of the dependent variable on the independent variables (only "reg_fit_mediation" if arguments robust = FALSE and fit_yx = TRUE were used).

cov

an object of class "cov_Huber" or "cov_ML" containing the covariance matrix estimates (only "cov_fit_mediation").

x, y, m, covariates

character vectors specifying the respective variables used.

data

a data frame containing the independent, dependent and proposed mediator variables, as well as covariates.

robust

either a logical indicating whether the effects were estimated robustly, or one of the character strings "MM" and "median" specifying the type of robust regressions.

contrast

either a logical indicating whether contrasts of the indirect effects were computed, or one of the character strings "estimates" and "absolute" specifying the type of contrasts of the indirect effects (only "reg_fit_mediation").

control

a list of tuning parameters used (if applicable).

Details

With method = "regression", and robust = TRUE or robust = "MM", the effects are computed via the robust MM-estimator of regression from lmrob(). This is the default behavior.

With method = "regression" and robust = "median", the effects are estimated via median regressions with rq(). Unlike the robust MM-regressions above, median regressions are not robust against outliers in the explanatory variables.

With method = "regression", robust = FALSE and family = "select", the error distribution to be used in maximum likelihood estimation of the regression models is selected via BIC. The following error distributions are included in the selection procedure: a normal distribution, a skew-normal distribution, Student's t distribution, and a skew-t distribution. Note that the parameters of those distributions are estimated as well. The skew-normal and skew-t distributions thereby use a centered parametrization such that the residuals are (approximately) centered around 0. Moreover, the skew-t distribution is only evaluated in the selection procedure if both the skew-normal and Student's t distribution yield an improvement in BIC over the normal distribution. Otherwise the estimation with a skew-t error distribution can be unstable. Furthermore, this saves a considerable amount of computation time in a bootstrap test, as estimation with those error distributions is orders of magnitude slower than any other estimation procedure in package robmed.

With method = "covariance" and robust = TRUE, the effects are estimated based on a Huber M-estimator of location and scatter. Note that this covariance-based approach is less robust than the approach based on robust MM-regressions described above.

References

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.

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.

See Also

test_mediation()

lmrob(), lm(), cov_Huber(), cov_ML()

Examples

Run this code
# 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)
fit1 <- fit_mediation(TeamCommitment ~ m(TaskConflict) + ValueDiversity,
                      data = BSG2014)
test1 <- test_mediation(fit1)
summary(test1)

# default method
set.seed(seed)
fit2 <- fit_mediation(BSG2014,
                      x = "ValueDiversity",
                      y = "TeamCommitment",
                      m = "TaskConflict")
test2 <- test_mediation(fit2)
summary(test2)

# }

Run the code above in your browser using DataLab