fit <- lm(mpg ~ disp + hp, data = mtcars)
# Automatically bins both predictors:
binned_residuals(fit, breaks = 5)
# Just bin one predictor, selected with tidyselect syntax. Multiple could be
# selected with c().
binned_residuals(fit, disp, breaks = 5)
# Bin the fitted values:
binned_residuals(fit, predictors = .fitted)
# Bins are made using the predictor, not regressors derived from it, so here
# disp is binned, not its polynomial
fit2 <- lm(mpg ~ poly(disp, 2), data = mtcars)
binned_residuals(fit2)
Run the code above in your browser using DataLab