
Panel of Interactive Versions of Diagnostic Residual Plots.
Source:R/resid_interact.R
resid_interact.RdCreates a panel of interactive residual diagnostic plots given a model. Currently accepts models of type "lm", "glm", "lmerMod", "lmerModLmerTest", "lme", and "glmerMod".
Usage
resid_interact(
model,
plots = "default",
type = NA,
bins = 30,
smoother = TRUE,
qqline = TRUE,
scale = 0.9,
theme = "bw",
axis.text.size = 10,
title.text.size = 12,
title.opt = TRUE,
nrow = NULL,
alpha = 0.6,
coordfix = FALSE
)Arguments
- model
Model fit using either
lm,glm,lmer,lmerTest,lme, orglmer.- plots
Plots chosen to include in the panel of plots. The default panel includes a residual plot, a normal quantile plot, an index plot, and a histogram of the residuals. (See details in the help file for
resid_panelfor the options available.)- type
Type of residuals to use in the plot. If not specified, the default residual type for each model type is used. (See details in the help file for
resid_panelfor the options available.)- bins
Number of bins to use when creating a histogram of the residuals. Default is set to 30.
- smoother
Indicates whether or not to include a smoother on the residual vs fitted and index plots. Specify TRUE or FALSE. Default is set to TRUE.
- qqline
Indicates whether to include a 1-1 line on the qq-plot. Specify TRUE or FALSE. Default is set to TRUE. (The option of
qqbandshas not been implemented in plotly, so it is not available as an option withresid_interact.)- scale
Scales the size of the graphs in the panel. Takes values in (0,1].
- theme
ggplot2 theme to be used. Current options are
"bw","classic", and"grey"(or"gray"). Default is"bw".- axis.text.size
Specifies the size of the text for the axis labels of all plots in the panel.
- title.text.size
Specifies the size of the text for the titles of all plots in the panel.
- title.opt
Indicates whether or not to include a title on the plots in the panel. Specify TRUE or FALSE. Default is set to TRUE.
- nrow
Sets the number of rows in the panel.
- alpha
Sets the alpha level for displays with points. Default is set to 0.6.
- coordfix
Uses fixed aspect ratio for QQ-plots and yvp. Default is FALSE.
Details
Details on the creation of the plots can be found in the details section of
the help file for resid_panel.
Examples
# Fit a model to the penguin data
penguin_model <- lme4::lmer(heartrate ~ depth + duration + (1|bird), data = penguins)
# Create the default interactive panel
resid_interact(penguin_model)
#> Warning: The following aesthetics were dropped during statistical transformation: label.
#> ℹ This can happen when ggplot fails to infer the correct grouping structure in
#> the data.
#> ℹ Did you forget to specify a `group` aesthetic or to convert a numerical
#> variable into a factor?
#> Warning: The following aesthetics were dropped during statistical transformation: label.
#> ℹ This can happen when ggplot fails to infer the correct grouping structure in
#> the data.
#> ℹ Did you forget to specify a `group` aesthetic or to convert a numerical
#> variable into a factor?
#> Warning: The following aesthetics were dropped during statistical transformation: label.
#> ℹ This can happen when ggplot fails to infer the correct grouping structure in
#> the data.
#> ℹ Did you forget to specify a `group` aesthetic or to convert a numerical
#> variable into a factor?
# Select only the residual plot and qq-plot to be included in the panel,
# set the number of rows to 2, change the theme to classic
resid_interact(penguin_model, plots = c("resid", "qq"), nrow = 2, theme = "classic")
#> Warning: The following aesthetics were dropped during statistical transformation: label.
#> ℹ This can happen when ggplot fails to infer the correct grouping structure in
#> the data.
#> ℹ Did you forget to specify a `group` aesthetic or to convert a numerical
#> variable into a factor?
#> Warning: The following aesthetics were dropped during statistical transformation: label.
#> ℹ This can happen when ggplot fails to infer the correct grouping structure in
#> the data.
#> ℹ Did you forget to specify a `group` aesthetic or to convert a numerical
#> variable into a factor?