lm
.
plot.lm(x, residuals = NULL, smooths = F, rugplot = F, id.n = 3, ask = F, which.plots = NULL, ...)
lm
object.
residuals
is a vector with the same length as each fitted term in
x
,
then these are taken to be the residuals to be used in the plots.
TRUE
, smooth curves are approximated to the scatterplots
using
loess.smooth
and added to the appropriate plots.
TRUE
, a univariate histogram or
rugplot
is
displayed along the base of each plot, showing the
occurrence of each x-value; ties are broken by jittering.
id.n
largest points in absolute value. Set to
FALSE
if no identified points
are desired.
Default: 3.
TRUE
,
plot.lm
operates in interactive mode.
1: Residuals against Fitted Values
This is useful for diagnosing:
(1) whether the relationship between the response and explanatory variables is linear -- if any curvature is observed than the model might be improved by adding additional, nonlinear terms to the model,
(2) whether the conditional variance of the residuals depends on the explanatory variables -- if the residuals are larger (positive and negative) for larger predicted values, then a nonlinear transformation of the response such as a square-root or log transformation may be useful.
Though not provided here, it is also useful to plot the residuals against each explanatory variable.
2: Square Root of Absolute Residuals against Fitted Values
This is also useful for diagnosing whether the conditional variance of the residuals is constant. The square-root transformation reduces the visual impact of large residuals, but also undesirably inflates small differences in magnitudes for residuals near zero.
3: Response vs Fitted Values
4: Normal QQplot of Residuals
This is useful for diagnosing whether the distribution of the residuals is normal (Gaussian).
5: Residual-Fit (r-f) spread plot
Two panels, showing the spread of the fitted values and residuals. This is useful for visually judging the quality of the fit; if the model fits well then the residuals have a small spread relative to the fit.
6: Cook's Distances
The Cook's distances measures the influence of each observation on the overall fit, based on the leverage of each observation and the magnitude of the residuals.
Each of these plots can be adorned with smooth lines, a rugplot, or labels for
the
id.n
largest points (in absolute value),
depending on the options chosen.
This function is a method for the generic function for class lm. It can be invoked by calling for an object x of the appropriate class, or directly by calling regardless of the class of the object.
When
ask=T
, rather than produce each plot sequentially,
plot.lm
displays a menu listing all the plots that can be produced.
If the menu is not desired but a pause between plots is still wanted
one must set
par(ask=T)
before invoking this command with argument
ask=F
.
fit <- lm(Fuel ~ . , data = fuel.frame) plot(fit, ask=T) # interactive version plot(fit, smooths=T, rugplot=T) plot(fit, id.n=10)