This function takes in two models and produces two ggplots in a list that show the predictions of the models versus the true response variable. For mixed models, it allows the user to ignore random effects. It also displays the R-squared value and the difference in R-squared between the two models within each plot.

compare_model_predictions(
  model1,
  model2,
  data,
  response,
  re.form = NULL,
  custom_title = NULL,
  annot_size = 5
)

Arguments

model1

A fitted model object (either a standard regression or a mixed model).

model2

A second fitted model object (either a standard regression or a mixed model).

data

A data frame containing the variables used in the models.

response

The name of the response variable as a string.

re.form

A formula specifying which random effects to include in predictions, or NA to exclude them. Defaults to including all random effects. Only applies if the model is a mixed model.

custom_title

An optional vector of custom titles for the plots.

annot_size

optional size for text annotation (default 5)

Value

A list of two ggplot objects, each comparing the predictions of a model with the true response variable.

Examples

if (FALSE) { # \dontrun{
  mdl1 <- lm(Sepal.Length ~ Sepal.Width + Petal.Length, data = iris)
  mdl2 <- lm(Sepal.Length ~ Sepal.Width + Petal.Width, data = iris)
  plots <- compare_model_predictions(mdl1, mdl2, data = iris, response = "Sepal.Length")
  plots[[1]] # Plot for model 1
  plots[[2]] # Plot for model 2
} # }