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
)

Arguments

IV

Character. Name of predictor

DV

Character. Name of dependent variable

Ms

Character vector. Names of mediator variables

data

Dataframe with coefficients and significance values. See details.

digits

Number of digits for rounding

coef_offset

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.

filename

If provided, graph will be saved as .svg file.

ind_p_values

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

Value

A list of a the graph and the associated code.

Examples

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)
} # }