Type: | Package |
Title: | Grammar of Graphics for Linear Model Diagnostic Plots |
Version: | 1.0.4 |
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. |
License: | CC0 |
Date: | 2025-04-01 |
Encoding: | UTF-8 |
Depends: | ggplot2 |
Imports: | broom, broom.mixed, cli, dplyr, metafor, nlme, patchwork, purrr, tibble, tidyr, utils, rlang, vctrs |
Suggests: | lme4, testthat (≥ 3.0.0) |
URL: | https://github.com/graysonwhite/gglm, https://graysonwhite.com/gglm/ |
BugReports: | https://github.com/graysonwhite/gglm/issues |
RoxygenNote: | 7.2.3 |
Config/testthat/edition: | 3 |
NeedsCompilation: | no |
Packaged: | 2025-04-01 19:27:44 UTC; graysonwhite |
Author: | Grayson White |
Maintainer: | Grayson White <graysonwhite13@gmail.com> |
Repository: | CRAN |
Date/Publication: | 2025-04-01 19:40:02 UTC |
gglm
Description
Provides four standard visual model diagnostic plots with 'ggplot2'.
Usage
gglm(data, theme = ggplot2::theme_gray(), ...)
Arguments
data |
A model object of type 'lm' or 'glm'. |
theme |
The theme of the 'ggplot's to be produced. |
... |
Currently ignored. For extendability. |
Value
A a 'ggplot2' object for visual diagnostic of model validity.
Examples
data(mtcars)
m1 <- lm(mpg ~ cyl + disp + hp, data = mtcars)
gglm(m1)
list_model_classes
Description
Returns the possible model classes that 'gglm' works with.
Usage
list_model_classes(...)
Arguments
... |
Currently ignored. For extendability. |
Value
A character vector containing the possible model classes that 'gglm' works with.
Note
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".
Examples
list_model_classes()
Objects exported from other packages
Description
These objects are imported from other packages. Follow the links below to see their documentation.
- broom
stat_cooks_leverage
Description
Cook's Distance vs. Leverage
Usage
stat_cooks_leverage(
alpha = 0.5,
method = "loess",
color = "steelblue",
se = FALSE,
...
)
Arguments
alpha |
Adjust transparency of points. |
method |
Method for fitting the line to the points. |
color |
Color of the line. |
se |
Keep standard error bands around line? |
... |
Currently ignored. For extendability. |
Value
A ‘ggplot2' layer for plotting Cook’s Distance vs. Leverage.
Examples
data(mtcars)
model <- lm(mpg ~ cyl + disp + hp, data = mtcars)
ggplot2::ggplot(data = model) + stat_cooks_leverage()
stat_cooks_obs
Description
‘ggplot2' layer for plotting cook’s distance by observation number.
Usage
stat_cooks_obs(...)
Arguments
... |
Currently ignored. For extendability. |
Value
A ‘ggplot2' layer for plotting cook’s distance by observation number.
Examples
data(mtcars)
model <- lm(mpg ~ cyl + disp + hp, data = mtcars)
ggplot2::ggplot(data = model) + stat_cooks_obs()
stat_fitted_resid
Description
'ggplot2' layer for plotting a fitted vs. residual scatter plot.
Usage
stat_fitted_resid(alpha = 0.5, ...)
Arguments
alpha |
Adjust transparency of points. |
... |
Currently ignored. For extendability. |
Value
A 'ggplot2' layer for plotting a fitted vs. residual scatter plot.
Examples
data(mtcars)
model <- lm(mpg ~ cyl + disp + hp, data = mtcars)
ggplot2::ggplot(data = model) + stat_fitted_resid()
stat_normal_qq
Description
Normal QQ plot.
Usage
stat_normal_qq(alpha = 0.5, ...)
Arguments
alpha |
Adjust transparency of points. |
... |
Currently ignored. For extendability. |
Value
A 'ggplot2' layer for plotting a Normal Q-Q plot.
Examples
data(mtcars)
model <- lm(mpg ~ cyl + disp + hp, data = mtcars)
ggplot2::ggplot(data = model) + stat_normal_qq()
stat_resid_hist
Description
Visualize the distribution of the residuals of a model.
Usage
stat_resid_hist(bins = 30, ...)
Arguments
bins |
Adjust the number of bins. |
... |
Currently ignored. For extendability. |
Value
A 'ggplot2' layer for plotting a histogram of residuals.
Examples
data(mtcars)
model <- lm(mpg ~ cyl + disp + hp, data = mtcars)
ggplot2::ggplot(data = model) + stat_resid_hist()
stat_resid_leverage
Description
Residual vs. leverage plot.
Usage
stat_resid_leverage(
alpha = 0.5,
method = "loess",
se = FALSE,
color = "steelblue",
...
)
Arguments
alpha |
Adjust transparency of points. |
method |
Method for fitting the line to the points. |
se |
Keep standard error bands around line? |
color |
Color of the line. |
... |
Currently ignored. For extendability. |
Value
A 'ggplot2' layer for plotting a fitted vs. residual scatter plot.
Examples
data(mtcars)
model <- lm(mpg ~ cyl + disp + hp, data = mtcars)
ggplot2::ggplot(data = model) + stat_resid_leverage()
stat_scale_location
Description
Scale location diagnostic plot.
Usage
stat_scale_location(
alpha = 0.5,
na.rm = TRUE,
se = FALSE,
method = "loess",
color = "steelblue",
...
)
Arguments
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. |
color |
Color of the line. |
... |
Currently ignored. For extendability. |
Value
A 'ggplot2' layer for plotting the scale location diagnostic plot.
Examples
data(mtcars)
model <- lm(mpg ~ cyl + disp + hp, data = mtcars)
ggplot2::ggplot(data = model) + stat_scale_location()