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
)
A fitted model object (either a standard regression or a mixed model).
A second fitted model object (either a standard regression or a mixed model).
A data frame containing the variables used in the models.
The name of the response variable as a string.
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.
An optional vector of custom titles for the plots.
optional size for text annotation (default 5)
A list of two ggplot objects, each comparing the predictions of a model with the true response variable.
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
} # }