mediation | R Documentation |
Mediation analysis A Monte Carlo simulation method to assess mediation based on Selig & Preacher (2008).
mediation(
model_med,
model_y,
model_med2 = NULL,
x,
med,
med2 = NULL,
mod = NULL,
mod_stage = NULL,
mod_level = NULL,
conf = 95,
rep = 20000,
verbose = TRUE,
digits = 3
)
model_med |
a fitted model object for mediator. |
model_y |
a fitted model object for outcome |
model_med2 |
a fitted model object for the second mediator for serial mediation |
x |
a character string indicating the name of the independent variable used in the models. |
med |
a character string indicating the name of the mediator used in the models. |
med2 |
a character string indicating the name of the second mediator used in the models (for serial mediations) |
mod |
a character string indicating the name of the moderator used in the models. |
mod_stage |
a character string specifying the stage at which the moderating effect occurs. For instance, in a first-stage moderated mediation, where the moderator influences the effect of X on the mediator (Med), set this to "model_med". In a second-stage moderated mediation, where the moderator affects the relationship between the mediator (Med) and the outcome variable (Y), set this to "model_y".#' |
mod_level |
The default is -1 SD and +1 SD for a continuous variable, and it is the two levels for a binary variable. |
conf |
level of the returned two-sided confidence intervals. Default is to return the 2.5 and 97.5 percentiles of the simulated quantities (i.e., 95%). |
rep |
number of Monte Carlo draws |
verbose |
deafult is |
digits |
number of digits to round to |
Nothing to return. Print the indirect effect.
Selig, J. P., & Preacher, K. J. (2008, June). Monte Carlo method for assessing mediation: An interactive tool for creating confidence intervals for indirect effects. http://quantpsy.org/.
new_dat = iris %>%
dplyr::rename(x = Petal.Length) %>%
dplyr::rename(m = Sepal.Length) %>%
dplyr::rename(moderator = Sepal.Width) %>%
dplyr::rename(y = Petal.Width)
model_1 = lm(data = new_dat, m ~ x)
model_2 = lm(data = new_dat, y ~ x*moderator + m)
mediation(model_med = model_1,
model_y = model_2,
rep = 20000,
x = 'x',
med = 'm',
mod = 'moderator',
mod_stage = 'model_y',
digits = 3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.