levelComparePlot: Plots comparison of accounting for nesting vs. not accounting...

View source: R/levelComparePlot.R

levelComparePlotR Documentation

Plots comparison of accounting for nesting vs. not accounting for nesting

Description

Plots the line of best for the relationship between two variables accounting for nesting and not accounting for nesting.

Usage

levelComparePlot(
  model,
  x,
  y,
  grouping,
  dataset,
  paneled = TRUE,
  select = c("select"),
  center = FALSE,
  xlab = x,
  ylab = y,
  glab = grouping,
  plot_titles = c("Scatter Plot", "Scatter Plot by Group")
)

Arguments

model

A linear mixed-effects model of class lmerMod or lmerModLmerTest.

x

Predictor variable.

y

Outcome variable.

grouping

Grouping variable.

dataset

A dataset containing the predictor, outcome, and grouping variables.

paneled

A logical value indicating whether the plot accounting for nesting should be split into panels.

select

A vector indicating the index of the groups to be included in the plots.

center

A logical value indicating whether the x variable should be centered

xlab

Character vector specifying the horizontal axis label.

ylab

Character vector specifying the vertical axis label.

glab

Character vector specifying the legend title for the plot accounting for nesting.

plot_titles

Character vectors specifying the titles for the plots.

Examples

# Gaussian
## Read in data
data(instruction)
## Create model
mod <- lme4::lmer(mathgain ~ mathkind + (1 | classid), data = instruction)
## Generate plots
levelComparePlot(mod, x = "mathkind", y = "mathgain", grouping = "classid", dataset = instruction)

# Logistic
## Read in data
data(reporting)
reporting$final.sample.size <- scale(as.numeric(reporting$final.sample.size))
reporting$mention.outliers <- ifelse(reporting$mention.outliers=="No",0,1)
mod <- lme4::glmer(mention.outliers ~ final.sample.size +
(1 | Journal), data = reporting, family = "binomial")
levelComparePlot(mod, x = "final.sample.size", y = "mention.outliers",
grouping = "Journal", dataset = reporting, paneled = FALSE)



lj5yn/mlmtools documentation built on March 10, 2023, 8:37 p.m.