Package 'gglm'

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]
Maintainer: Grayson White <[email protected]>
License: CC0
Version: 1.0.3.9000
Built: 2025-03-12 04:01:36 UTC
Source: https://github.com/graysonwhite/gglm

Help Index


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()

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()