Skip to content

Plot residuals vs fitted values

Source: R/plotDiagnostics.R ยท Help: ?plotResidualsFitted

Generates a simple scatter plot of residuals against fitted values from a linear model. A horizontal reference line at zero is added.

Usage

plotResidualsFitted(model, enhanced = FALSE)

Arguments

model
A fitted model of class lm.
enhanced
Logical. FALSE, the default, draws the simple plot; TRUE the plot with influential observations marked.

Value

A ggplot object.

Details

For a weighted fit the Pearson residuals \(\sqrt{w_i}\, e_i\) are plotted, as in plot.lm(): those are the residuals that have constant variance when the weights are right. The other residual plots in the package do the same.

With enhanced = TRUE the plot marks influential observations (Cook's distance above \(4/n\)) in red, sizes the points by the absolute residual and adds the standard-error band of the LOESS smooth. This is what the deprecated plotResidualsFittedEnhanced() drew.

Examples

data(mtcars)
m <- lm(mpg ~ wt + qsec, data = mtcars)
plotResidualsFitted(m)
plotResidualsFitted(m, enhanced = TRUE)