Returns graphViz code and graph for (multiple) mediation model.
Coefficients and significance values for paths need to be provided,
based on the format returned by run_moderation()
plot_mediation(
IV,
DV,
Ms,
data,
digits = 2,
coef_offset = length(Ms),
filename = NULL,
ind_p_values = FALSE
)
Character. Name of predictor
Character. Name of dependent variable
Character vector. Names of mediator variables
Dataframe with coefficients and significance values. See details.
Number of digits for rounding
Tibble with values to position mediators. If not provided, the function will align mediators automatically, which is unlikely to provide a well-aligned chart (except for cases when the offset has been explicitly implemented for that number of mediators, currently 1 and 3). However, the returned code can still be edited. See timesaveR:::.coef_offset_3 for an example of an offset tibble.
If provided, graph will be saved as .svg file.
Should significance stars be shown for indirect effects, based on pvalues passed in data? If FALSE, indirect effects with confidence intervals that do not include zero are bolded
A list of a the graph and the associated code.
if (FALSE) { # \dontrun{
# Estimate mediation model (usually with bootstraps > 1000!)
res <- run_mediation(ess_health, fltdpr, health, dosprt, agea, bootstraps = 50)
# Run plot command
plot <- plot_mediation(
IV = "Frequency of <br /> feeling depressed",
DV = "Self-reported <br /> poor health", Ms = "Frequency of <br /> physical activity",
data = res
)
# Show the graph
plot$graph
# Show the code
plot$code
# To create the graph again (e.g., after you edit its code)
DiagrammeR::grViz(plot$code)
} # }