plot_mediation: Plot mediation model with one or more mediators

View source: R/med_mod_plots.R

plot_mediationR Documentation

Plot mediation model with one or more mediators

Description

Returns graphViz code and graph for (multiple) mediation model. Coefficients and significance values for paths need to be provided - see example for the format.

Usage

plot_mediation(
  IV,
  DV,
  Ms,
  df,
  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

df

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, function will align mediators automatically, which is unlikely to provide a well-aligned path (except for cases when offset has been implemented for that number of mediators, currently 1 and 3). However, returned code can still be edited. See rNuggets:::.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 DF? 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

## Not run: 
# Values for model
med_model <- tibble::tribble(
  ~type, ~mediator, ~est, ~pvalue, ~ci.lower, ~ci.upper,
  "a", "Empathy", 0.29, 0, 0.29, 0.29,
  "b", "Empathy", 0.18, 0, 0.18, 0.18,
  "direct", NA, -0.08, 0, -0.08, -0.08,
  "indirect", "Empathy", 0.05, 0, 0.05, 0.05,
  "total", NA, 0.41, 0, 0.41, 0.41
)

# Run plot command
rNuggets:::plot_mediation(
  IV = "Positive <br /> contact",
  DV = "Diversity <br /> policies", Ms = "Empathy", df = med_model
)

## End(Not run)

LukasWallrich/rNuggets documentation built on Aug. 26, 2022, 11:03 a.m.