Plot population-level fitted values and X values, for M and Y.

mlm_spaghetti_plot(
  mod = NULL,
  d = NULL,
  id = "id",
  x = "x",
  m = "m",
  y = "y",
  level = 0.95,
  n = 12,
  binary_y = FALSE,
  mx = "fitted",
  fixed = TRUE,
  random = TRUE,
  h_jitter = 0,
  v_jitter = 0,
  bar_width = 0.2,
  bar_size = 0.75,
  n_samples = NA
)

Arguments

mod

A multilevel mediation model estimated with mlm().

d

A data.frame or a data_frame used in fitting model.

id

Name of id variable (identifying subjects) in data (d).

x

Name of X variable in data.

m

Name of M variable in data.

y

Name of Y variable in data.

level

X level for Credible Intervals. (Defaults to .95.)

n

Number of points along X to evaluate fitted values on. See details.

binary_y

Set to TRUE if the outcome variable (Y) is 0/1.

mx

Should the X axis of the M-Y figure be "fitted" values, or "data" values. Defaults to "fitted".

fixed

Should the population-level ("fixed") fitted values be shown?

random

Should the subject-level ("random") fitted values be shown?

h_jitter

Horizontal jitter of points. Defaults to 0.

v_jitter

Vertical jitter of points. Defaults to 0.

bar_width

Width of the error bars. Defaults to 0.2.

bar_size

Thickness of the error bars. Defaults to 0.75.

n_samples

Number of MCMC samples to use in calculating fitted values. See details.

Value

A list of two ggplot2 objects.

Details

If n = 2, the fitted values will be represented as points with X line with a Confidence Ribbon instead. If a very large model is fitted with a large number of MCMC iterations, the function might take a long time to run. In these cases, users can set n_samples to a smaller value (e.g. 1000), in which case the fitted values (and the CIs) will be based on a random subset of n_samples MCMC samples. The default value is NA, meaning that all MCMC samples are used.

Author

Matti Vuorre mv2521@columbia.edu