| Title: | Grammar of Graphics for Linear Model Diagnostic Plots |
|---|---|
| Description: | Allows for easy creation of diagnostic plots for a variety of model objects using the Grammar of Graphics. Provides functionality for both individual diagnostic plots and an array of four standard diagnostic plots. |
| Authors: | Grayson White [aut, cre] (ORCID: <https://orcid.org/0000-0003-4993-2792>) |
| Maintainer: | Grayson White <[email protected]> |
| License: | CC0 |
| Version: | 1.1.0.9000 |
| Built: | 2026-10-12 13:16:05 UTC |
| Source: | https://github.com/graysonwhite/gglm |
Provides four standard visual model diagnostic plots with
ggplot2.
gglm(data, mapping = ggplot2::aes(), theme = ggplot2::theme_gray(), ...)gglm(data, mapping = ggplot2::aes(), theme = ggplot2::theme_gray(), ...)
data |
A model object. |
mapping |
Additional aesthetic mappings to add to each layer, e.g.
|
theme |
The theme of the |
... |
Additional arguments passed on to each |
A ggplot2 object for visual diagnostic of model validity.
data(mtcars) m1 <- lm(mpg ~ cyl + disp + hp, data = mtcars) gglm(m1)data(mtcars) m1 <- lm(mpg ~ cyl + disp + hp, data = mtcars) gglm(m1)
Launches a R Shiny-based applet for linear model diagnostics.
launch( data = NULL, example_datasets = list(penguins = palmerpenguins::penguins, candy = fivethirtyeight::candy_rankings, mtcars = datasets::mtcars), ... )launch( data = NULL, example_datasets = list(penguins = palmerpenguins::penguins, candy = fivethirtyeight::candy_rankings, mtcars = datasets::mtcars), ... )
data |
A |
example_datasets |
A named |
... |
Currently ignored. For extendability. |
None. Launches a shiny applet for point-and-click based model
diagnostics.
## Not run: launch() ## End(Not run)## Not run: launch() ## End(Not run)
Returns the possible model classes that gglm works with.
list_model_classes(...)list_model_classes(...)
... |
Currently ignored. For extendability. |
A character vector containing the possible model classes that
gglm works with.
Note that these are not always the exact name of the class that that
can be used. This is due to how some methods are written in the packages
gglm imports. For example, the model class "merMod" refers to a
variety of model outputs from lme4, even when the outputted class is
not called "merMod".
list_model_classes()list_model_classes()
Cook's Distance vs. Leverage
stat_cooks_leverage( mapping = ggplot2::aes(), alpha = 0.5, method = "loess", linecolor = "steelblue", se = FALSE, ... )stat_cooks_leverage( mapping = ggplot2::aes(), alpha = 0.5, method = "loess", linecolor = "steelblue", se = FALSE, ... )
mapping |
Additional aesthetic mappings to add to the layer, e.g.
|
alpha |
Adjust transparency of points. |
method |
Method for fitting the line to the points. |
linecolor |
Color of the line. |
se |
Keep standard error bands around line? |
... |
Additional arguments passed on to |
A ggplot2 layer for plotting Cook's Distance vs. Leverage.
data(mtcars) model <- lm(mpg ~ cyl + disp + hp, data = mtcars) ggplot2::ggplot(data = model) + stat_cooks_leverage()data(mtcars) model <- lm(mpg ~ cyl + disp + hp, data = mtcars) ggplot2::ggplot(data = model) + stat_cooks_leverage()
ggplot2 layer for plotting cook's distance by observation number.
stat_cooks_obs(mapping = ggplot2::aes(), ...)stat_cooks_obs(mapping = ggplot2::aes(), ...)
mapping |
Additional aesthetic mappings to add to the layer, e.g.
|
... |
Additional arguments passed on to |
A ggplot2 layer for plotting cook's distance by observation number.
data(mtcars) model <- lm(mpg ~ cyl + disp + hp, data = mtcars) ggplot2::ggplot(data = model) + stat_cooks_obs()data(mtcars) model <- lm(mpg ~ cyl + disp + hp, data = mtcars) ggplot2::ggplot(data = model) + stat_cooks_obs()
ggplot2 layer for plotting a fitted vs. residual scatter plot.
stat_fitted_resid(mapping = ggplot2::aes(), alpha = 0.5, ...)stat_fitted_resid(mapping = ggplot2::aes(), alpha = 0.5, ...)
mapping |
Additional aesthetic mappings to add to the layer, e.g.
|
alpha |
Adjust transparency of points. |
... |
Additional arguments passed on to |
A ggplot2 layer for plotting a fitted vs. residual scatter plot.
data(mtcars) model <- lm(mpg ~ cyl + disp + hp, data = mtcars) ggplot2::ggplot(data = model) + stat_fitted_resid()data(mtcars) model <- lm(mpg ~ cyl + disp + hp, data = mtcars) ggplot2::ggplot(data = model) + stat_fitted_resid()
Normal QQ plot.
stat_normal_qq(mapping = ggplot2::aes(), alpha = 0.5, ...)stat_normal_qq(mapping = ggplot2::aes(), alpha = 0.5, ...)
mapping |
Additional aesthetic mappings to add to the layer, e.g.
|
alpha |
Adjust transparency of points. |
... |
Additional arguments passed on to |
A ggplot2 layer for plotting a Normal Q-Q plot.
data(mtcars) model <- lm(mpg ~ cyl + disp + hp, data = mtcars) ggplot2::ggplot(data = model) + stat_normal_qq()data(mtcars) model <- lm(mpg ~ cyl + disp + hp, data = mtcars) ggplot2::ggplot(data = model) + stat_normal_qq()
Visualize the distribution of the residuals of a model.
stat_resid_hist(mapping = ggplot2::aes(), bins = 30, ...)stat_resid_hist(mapping = ggplot2::aes(), bins = 30, ...)
mapping |
Additional aesthetic mappings to add to the layer, e.g.
|
bins |
Adjust the number of bins. |
... |
Additional arguments passed on to |
A ggplot2 layer for plotting a histogram of residuals.
data(mtcars) model <- lm(mpg ~ cyl + disp + hp, data = mtcars) ggplot2::ggplot(data = model) + stat_resid_hist()data(mtcars) model <- lm(mpg ~ cyl + disp + hp, data = mtcars) ggplot2::ggplot(data = model) + stat_resid_hist()
Residual vs. leverage plot.
stat_resid_leverage( mapping = ggplot2::aes(), alpha = 0.5, method = "loess", se = FALSE, linecolor = "steelblue", ... )stat_resid_leverage( mapping = ggplot2::aes(), alpha = 0.5, method = "loess", se = FALSE, linecolor = "steelblue", ... )
mapping |
Additional aesthetic mappings to add to the layer, e.g.
|
alpha |
Adjust transparency of points. |
method |
Method for fitting the line to the points. |
se |
Keep standard error bands around line? |
linecolor |
Color of the line. |
... |
Additional arguments passed on to |
A ggplot2 layer for plotting a fitted vs. residual scatter plot.
data(mtcars) model <- lm(mpg ~ cyl + disp + hp, data = mtcars) ggplot2::ggplot(data = model) + stat_resid_leverage()data(mtcars) model <- lm(mpg ~ cyl + disp + hp, data = mtcars) ggplot2::ggplot(data = model) + stat_resid_leverage()
Scale location diagnostic plot.
stat_scale_location( mapping = ggplot2::aes(), alpha = 0.5, na.rm = TRUE, se = FALSE, method = "loess", linecolor = "steelblue", ... )stat_scale_location( mapping = ggplot2::aes(), alpha = 0.5, na.rm = TRUE, se = FALSE, method = "loess", linecolor = "steelblue", ... )
mapping |
Additional aesthetic mappings to add to the layer, e.g.
|
alpha |
Adjust the transparency of points. |
na.rm |
Remove points with value NA? |
se |
Keep standard error bands around line? |
method |
Method for fitting the line to the points. |
linecolor |
Color of the line. |
... |
Additional arguments passed on to |
A ggplot2 layer for plotting the scale location diagnostic plot.
data(mtcars) model <- lm(mpg ~ cyl + disp + hp, data = mtcars) ggplot2::ggplot(data = model) + stat_scale_location()data(mtcars) model <- lm(mpg ~ cyl + disp + hp, data = mtcars) ggplot2::ggplot(data = model) + stat_scale_location()