plot_predictions_vs_residuals: Create a Plot of Predictions vs Residuals

View source: R/linreg-plots.R

plot_predictions_vs_residualsR Documentation

Create a Plot of Predictions vs Residuals

Description

A predictors vs residuals plot is useful for visually inspecting if a linear regression model violates both the Linear and Equal Variance assumptions of its residuals. The plot plots predicted values on the x-axis and residuals on the y-axis. If the resulting scatterplot shows a discernible pattern, then either or both of the assumptions are likely violated.

Usage

plot_predictions_vs_residuals(.data, .hline = "dashed")

## S3 method for class 'data.frame'
plot_predictions_vs_residuals(.data, .hline = "dashed")

Arguments

.data

The output of calculate_residuals().

.hline

(Optional) The linetype of the line drawn at y = 0.

Value

A ggplot object.

References

Kutner, M., Nachtsheim, C., Neter, J. and Li, W. (2005). Applied Linear Statistical Models. ISBN: 0-07-238688-6. McGraw-Hill/Irwin.

See Also

calculate_residuals()

Examples

library(tidytest)

mod_lm_fit <- lm(mpg ~ disp + wt + hp, data = mtcars)

pred_vs_resid_tbl <- calculate_residuals(mod_lm_fit)

plot_predictions_vs_residuals(pred_vs_resid_tbl)


RobbyLankford/tidytest documentation built on Jan. 27, 2024, 7:36 a.m.