View source: R/lmerPredictionPlot.R
lmerPredictionPlot | R Documentation |
lmerPredictionPlot is a function for creating plots of predicted intervals from lme4 models using ggplot2. It provides flexibility in specifying the variables for the x-axis, y-axis, and grouping, and allows customization of plot appearance through additional parameters.
lmerPredictionPlot(model, x = NULL, y = NULL, grp = NULL, size = NULL, ...)
model |
A lme4 model object. |
x |
The name of the x variable (independent variable). Defaults to NULL. If not provided, the function attempts to guess the name by examining the formula of the model. |
y |
The name of the y variable (dependent variable). Defaults to NULL. If not provided, the function isolates the first variable from the second formula term. |
grp |
A categorical variable of the model. Defaults to NULL. If not provided, the function isolates the second variable from the second formula term. |
size |
The size of the data. By default, the size is set to the number of rows in the model frame. |
... |
Additional parameters for the function merTools::predictInterval(); see the reference documentation for the function. |
A ggplot object.
merTools::predictInterval
, ggplot2
d <- data.frame(
Type = rep(c("Forest", "Regeneration", "Restoration"), each = 12),
Landscape = rep(paste0("L", 1:12), times = 3),
Mean_NDVI_SD_500 = rnorm(36, mean = 0.2, sd = 0.02),
hill_q0 = sample(5:14, 36, replace = TRUE),
Abundance = sample(5:50, 36, replace = TRUE)
)
modelX <- lme4::lmer(formula = hill_q0 ~ Mean_NDVI_SD_500 * Type+(1|Landscape), data=d)
lmerPredictionPlot(model = modelX, type = "linear.prediction")
lmerPredictionPlot(model = modelX) +
scico::scale_color_scico_d(palette = "batlow", begin = 0.1, end = 0.7) +
scico::scale_fill_scico_d(palette = "batlow", begin = 0.1, end = 0.7)
lmerPredictionPlot(model = modelX) +
scico::scale_color_scico_d(palette = "batlow", begin = 0.1, end = 0.7) +
scico::scale_fill_scico_d(palette = "batlow", begin = 0.1, end = 0.7) +
ggplot2::facet_wrap(~Type)
modelY <- lme4::glmer.nb(formula = Abundance ~ Mean_NDVI_SD_500 * Type+(1|Landscape), data=d)
lmerPredictionPlot(model = modelY, type = "probability")
lmerPredictionPlot(model = modelY) +
scico::scale_color_scico_d(palette = "batlow", begin = 0.1, end = 0.7) +
scico::scale_fill_scico_d(palette = "batlow", begin = 0.1, end = 0.7)
lmerPredictionPlot(model = modelY) +
scico::scale_color_scico_d(palette = "batlow", begin = 0.1, end = 0.7) +
scico::scale_fill_scico_d(palette = "batlow", begin = 0.1, end = 0.7) +
ggplot2::facet_wrap(~Type)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.