index_of_mome: Index of Moderated Mediation and Index of Moderated Moderated...

View source: R/index_mome.R

index_of_momeR Documentation

Index of Moderated Mediation and Index of Moderated Moderated Mediation

Description

It computes the index of moderated mediation and the index of moderated moderated mediation proposed by Hayes (2015, 2018).

Usage

index_of_mome(
  x,
  y,
  m = NULL,
  w = NULL,
  fit = NULL,
  boot_ci = FALSE,
  level = 0.95,
  boot_out = NULL,
  R = 100,
  seed = NULL,
  progress = TRUE,
  mc_ci = FALSE,
  mc_out = NULL,
  ci_type = NULL,
  ci_out = NULL,
  boot_type = c("perc", "bc"),
  ...
)

index_of_momome(
  x,
  y,
  m = NULL,
  w = NULL,
  z = NULL,
  fit = NULL,
  boot_ci = FALSE,
  level = 0.95,
  boot_out = NULL,
  R = 100,
  seed = NULL,
  progress = TRUE,
  mc_ci = FALSE,
  mc_out = NULL,
  ci_type = NULL,
  ci_out = NULL,
  boot_type = c("perc", "bc"),
  ...
)

Arguments

x

Character. The name of the predictor at the start of the path.

y

Character. The name of the outcome variable at the end of the path.

m

A vector of the variable names of the mediator(s). The path goes from the first mediator successively to the last mediator. If NULL, the default, the path goes from x to y.

w

Character. The name of the moderator.

fit

The fit object. Can be a lavaan::lavaan-class object, a list of lm() outputs, or an object created by lm2list(). It can also be a lavaan.mi object returned by semTools::runMI() or its wrapper, such as semTools::sem.mi().

boot_ci

Logical. Whether bootstrap confidence interval will be formed. Default is FALSE.

level

The level of confidence for the bootstrap confidence interval. Default is .95.

boot_out

If boot_ci is TRUE, users can supply pregenerated bootstrap estimates. This can be the output of do_boot(). For indirect_effect() and cond_indirect_effects(), this can be the output of a previous call to cond_indirect_effects(), indirect_effect(), or cond_indirect() with bootstrap confidence intervals requested. These stored estimates will be reused such that there is no need to do bootstrapping again. If not supplied, the function will try to generate them from fit.

R

Integer. If boot_ci is TRUE, boot_out is NULL, and bootstrap standard errors not requested if fit is a lavaan-class object, this function will do bootstrapping on fit. R is the number of bootstrap samples. Default is 100. For Monte Carlo simulation, this is the number of replications.

seed

If bootstrapping or Monte Carlo simulation is conducted, this is the seed for the bootstrapping or simulation. Default is NULL and seed is not set.

progress

Logical. Display bootstrapping progress or not. Default is TRUE.

mc_ci

Logical. Whether Monte Carlo confidence interval will be formed. Default is FALSE.

mc_out

If mc_ci is TRUE, users can supply pregenerated Monte Carlo estimates. This can be the output of do_mc(). For indirect_effect() and cond_indirect_effects(), this can be the output of a previous call to cond_indirect_effects(), indirect_effect(), or cond_indirect() with Monte Carlo confidence intervals requested. These stored estimates will be reused such that there is no need to do Monte Carlo simulation again. If not supplied, the function will try to generate them from fit.

ci_type

The type of confidence intervals to be formed. Can be either "boot" (bootstrapping) or "mc" (Monte Carlo). If not supplied or is NULL, will check other arguments (e.g, boot_ci and mc_ci). If supplied, will override boot_ci and mc_ci.

ci_out

If ci_type is supplied, this is the corresponding argument. If ci_type is "boot", this argument will be used as boot_out. If ci_type is "mc", this argument will be used as mc_out.

boot_type

If bootstrap confidence interval is to be formed, the type of bootstrap confidence interval. The supported types are "perc" (percentile bootstrap confidence interval, the default and recommended type) and "bc" (bias-corrected, or BC, bootstrap confidence interval).

...

Arguments to be passed to cond_indirect_effects()

z

Character. The name of the second moderator, for computing the index of moderated moderated mediation.

Details

The function index_of_mome() computes the index of moderated mediation proposed by Hayes (2015). It supports any path in a model with one (and only one) component path moderated. For example, x->m1->m2->y with x->m1 moderated by w. It measures the change in indirect effect when the moderator increases by one unit.

The function index_of_momome() computes the index of moderated moderated mediation proposed by Hayes (2018). It supports any path in a model, with two component paths moderated, each by one moderator. For example, x->m1->m2->y with x->m1 moderated by w and m2->y moderated by z. It measures the change in the index of moderated mediation of one moderator when the other moderator increases by one unit.

Value

It returns a cond_indirect_diff-class object. This class has a print method (print.cond_indirect_diff()), a coef method for extracting the index (coef.cond_indirect_diff()), and a confint method for extracting the confidence interval if available (confint.cond_indirect_diff()).

Functions

  • index_of_mome(): Compute the index of moderated mediation.

  • index_of_momome(): Compute the index of moderated moderated mediation.

References

Hayes, A. F. (2015). An index and test of linear moderated mediation. Multivariate Behavioral Research, 50(1), 1-22. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1080/00273171.2014.962683")}

Hayes, A. F. (2018). Partial, conditional, and moderated moderated mediation: Quantification, inference, and interpretation. Communication Monographs, 85(1), 4-40. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1080/03637751.2017.1352100")}

See Also

cond_indirect_effects()

Examples


library(lavaan)
dat <- modmed_x1m3w4y1
dat$xw1 <- dat$x * dat$w1
mod <-
"
m1 ~ a * x  + f * w1 + d * xw1
y  ~ b * m1 + cp * x
ind_mome := d * b
"
fit <- sem(mod, dat,
           meanstructure = TRUE, fixed.x = FALSE,
           se = "none", baseline = FALSE)
est <- parameterEstimates(fit)

# R should be at least 2000 or even 5000 in real research.
# parallel is set to TRUE by default.
# Therefore, in research, the argument parallel can be omitted.
out_mome <- index_of_mome(x = "x", y = "y", m = "m1", w = "w1",
                          fit = fit,
                          boot_ci = TRUE,
                          R = 42,
                          seed = 4314,
                          parallel = FALSE,
                          progress = FALSE)
out_mome
coef(out_mome)
# From lavaan
print(est[19, ], nd = 8)
confint(out_mome)



library(lavaan)
dat <- modmed_x1m3w4y1
dat$xw1 <- dat$x * dat$w1
dat$m1w4 <- dat$m1 * dat$w4
mod <-
"
m1 ~ a * x  + f1 * w1 + d1 * xw1
y  ~ b * m1 + f4 * w4 + d4 * m1w4 + cp * x
ind_momome := d1 * d4
"
fit <- sem(mod, dat,
           meanstructure = TRUE, fixed.x = FALSE,
           se = "none", baseline = FALSE)
est <- parameterEstimates(fit)

# See the example of index_of_mome on how to request
# bootstrap confidence interval.
out_momome <- index_of_momome(x = "x", y = "y", m = "m1",
                              w = "w1", z = "w4",
                              fit = fit)
out_momome
coef(out_momome)
print(est[32, ], nd = 8)


manymome documentation built on Oct. 4, 2024, 5:10 p.m.