random_interaction: Plot cross-level interactions for mer objects

random_interactionR Documentation

Plot cross-level interactions for mer objects

Description

Takes an object produced by lme4::lmer() function, and returns interaction plot(s).

Usage

random_interaction(
  x,
  real = TRUE,
  z.levels = c("1SD", "2SD", "1.2SD", "all"),
  scatter = FALSE,
  labs = NULL,
  x.levels = NULL,
  silent = T,
  ...
)

Arguments

x

A mer object produced by lmer function

real

Logical. Whether real groups should be used to predict random effects, or extrapolate using means and standard deviations?

z.levels

String, indicating what levels of moderating group-level variable should be computed. Can take (only) the following values:

  • "1SD". Default. Computes group-level mean and standard deviation of moderating variable and finds groups with similar values, so prediction of slopes and values is made based on three real groups.

  • "1SD" Computes group-level mean and standard deviation of moderating variable.

  • "2SD" Computes group-level mean and doubled standard deviation of moderating variable.

  • "12SD" Computes group-level mean and plots both standard deviation and doubled standard deviation of moderating variable.

scatter

Logical. Should scatterplot be created in addition?

labs

List of arguments passed to +labs() PLUS elements named "line1", "line2"... which are used to name lines on the plot. If there are more or less "line" elements than lines on the plot, they are ignored.

x.levels

desired x-axis coordinates, individual-level term. If NULL (default) are defined automatically.

...

Arguments passed to effect function of effects package.

Details

It somehow repeats functionality of 'sjPlot::sjp.int', but differs in being able to select real groups close to +/- 1 sd and mean of moderating variable; makes prettier and customizable plots.

Value

Returns one or several ggplots. In case one plot is returned it can be appended with +theme(), +geom_(), etc.

See Also

random_plot lmer_table

Examples

data("Orthodont",package="nlme")
m1 = lmer(distance ~ age*Sex + (age|Subject), data=Orthodont)
random_interaction2(m1)

MaksimRudnev/LittleHelpers documentation built on Nov. 5, 2024, 10:16 p.m.