stack_bpg {multilevelmediation}R Documentation

Stacks data in the style of Bauer-Preacher-Gil for multilevel mediation

Description

Stacks data in the style of Bauer-Preacher-Gil for multilevel mediation

Usage

stack_bpg(data, L2ID, X, Y, M,
  moderator = NULL,
  covars.m = NULL,
  covars.y = NULL)

Arguments

data

Data frame in long format.

L2ID

(String) Name of column that contains grouping variable in data (e.g., "SubjectID").

X

(String) Name of column that contains the X independent variable in data.

Y

(String) Name of column that contains the Y dependent variable in data.

M

(String) Name of column that contains the M mediating variable in data.

moderator

Optional Character that contains name of column that contains the moderator variable in data

covars.m

(Character vector) Optional covariates to include in the model for M.

covars.y

(Character vector) Optional covariates to include in the model for Y.

Details

This is a convenience function used primarily internally by the package to restructure data in the style of Bauer, Preacher, and Gil (2006). The point is to allow both Y and M to be outcomes in a single column ("Z"), so that both mediator and outcome models can be fit at the same time. This is necessary to estimate the covariance between "a" and "b" paths at the same time when both have random effects. Two selector variables, "Sy" and "Sm" toggle whether each row corresponds to the outcome or the mediator, respectively.

Value

An object that is a subclass of data.frame is returned. In particular a tbl_df or "tibble."

So that coefficients extracted later from modmed.mlm hopefully make more sense, the below lists all variables (i.e., typical column names) for the data frame.

When modmed.mlm is used, any output with an "re" prefix will correspond to a random effect. Note that estimation with brms will result in slightly different output than listed here. Coefficients typically have a "b_" prefix, and random effects are parameterized not such that we end up with covariances, but using correlations and standard deviations for each effect.

References

Bauer, D. J., Preacher, K. J., & Gil, K. M. (2006). Conceptualizing and testing random indirect effects and moderated mediation in multilevel models: new procedures and recommendations. Psychological Methods, 11(2), 142-163. doi:10.1037/1082-989X.11.2.142

Examples



# restructure BPG data
data(BPG06dat)

dat <- stack_bpg(BPG06dat,
  "id", "x", "m", "y"
)

head(dat)

# restructure simulated data w/ moderator
data(simdat)
dat2 <- stack_bpg(simdat,
  "L2id", "X", "M", "Y",
  moderator = "mod"
)

head(dat2)



[Package multilevelmediation version 0.3.1 Index]