plot.lm {stats}  R Documentation 
Six plots (selectable by which
) are currently available: a plot
of residuals against fitted values, a ScaleLocation plot of
sqrt( residuals )
against fitted values, a Normal QQ plot, a
plot of Cook's distances versus row labels, a plot of residuals
against leverages, and a plot of Cook's distances against
leverage/(1leverage). By default, the first three and 5
are provided.
## S3 method for class 'lm' plot(x, which = c(1:3, 5), caption = list("Residuals vs Fitted", "Normal QQ", "ScaleLocation", "Cook's distance", "Residuals vs Leverage", expression("Cook's dist vs Leverage " * h[ii] / (1  h[ii]))), panel = if(add.smooth) panel.smooth else points, sub.caption = NULL, main = "", ask = prod(par("mfcol")) < length(which) && dev.interactive(), ..., id.n = 3, labels.id = names(residuals(x)), cex.id = 0.75, qqline = TRUE, cook.levels = c(0.5, 1.0), add.smooth = getOption("add.smooth"), label.pos = c(4,2), cex.caption = 1)
x 

which 
if a subset of the plots is required, specify a subset of
the numbers 
caption 
captions to appear above the plots;

panel 
panel function. The useful alternative to

sub.caption 
common title—above the figures if there are more
than one; used as 
main 
title to each plot—in addition to 
ask 
logical; if 
... 
other parameters to be passed through to plotting functions. 
id.n 
number of points to be labelled in each plot, starting with the most extreme. 
labels.id 
vector of labels, from which the labels for extreme
points will be chosen. 
cex.id 
magnification of point labels. 
qqline 
logical indicating if a 
cook.levels 
levels of Cook's distance at which to draw contours. 
add.smooth 
logical indicating if a smoother should be added to
most plots; see also 
label.pos 
positioning of labels, for the left half and right half of the graph respectively, for plots 13. 
cex.caption 
controls the size of 
sub.caption
—by default the function call—is shown as
a subtitle (under the xaxis title) on each plot when plots are on
separate pages, or as a subtitle in the outer margin (if any) when
there are multiple plots per page.
The ‘ScaleLocation’ plot, also called ‘SpreadLocation’ or ‘SL’ plot, takes the square root of the absolute residuals in order to diminish skewness (sqrt(E)) is much less skewed than  E  for Gaussian zeromean E).
The ‘SL’, the QQ, and the ResidualLeverage plot, use
standardized residuals which have identical variance (under the
hypothesis). They are given as
R[i] / (s * sqrt(1  h.ii))
where h.ii are the diagonal entries of the hat matrix,
influence()$hat
(see also hat
), and
where the ResidualLeverage plot uses standardized Pearson residuals
(residuals.glm(type = "pearson")
) for R[i].
The ResidualLeverage plot shows contours of equal Cook's distance,
for values of cook.levels
(by default 0.5 and 1) and omits
cases with leverage one with a warning. If the leverages are constant
(as is typically the case in a balanced aov
situation)
the plot uses factor level combinations instead of the leverages for
the xaxis. (The factor levels are ordered by mean fitted value.)
In the Cook's distance vs leverage/(1leverage) plot, contours of standardized residuals that are equal in magnitude are lines through the origin. The contour lines are labelled with the magnitudes.
John Maindonald and Martin Maechler.
Belsley, D. A., Kuh, E. and Welsch, R. E. (1980) Regression Diagnostics. New York: Wiley.
Cook, R. D. and Weisberg, S. (1982) Residuals and Influence in Regression. London: Chapman and Hall.
Firth, D. (1991) Generalized Linear Models. In Hinkley, D. V. and Reid, N. and Snell, E. J., eds: Pp. 5582 in Statistical Theory and Modelling. In Honour of Sir David Cox, FRS. London: Chapman and Hall.
Hinkley, D. V. (1975) On power transformations to symmetry. Biometrika 62, 101–111.
McCullagh, P. and Nelder, J. A. (1989) Generalized Linear Models. London: Chapman and Hall.
termplot
, lm.influence
,
cooks.distance
, hatvalues
.
require(graphics) ## Analysis of the lifecycle savings data ## given in Belsley, Kuh and Welsch. lm.SR < lm(sr ~ pop15 + pop75 + dpi + ddpi, data = LifeCycleSavings) plot(lm.SR) ## 4 plots on 1 page; ## allow room for printing model formula in outer margin: par(mfrow = c(2, 2), oma = c(0, 0, 2, 0)) plot(lm.SR) plot(lm.SR, id.n = NULL) # no id's plot(lm.SR, id.n = 5, labels.id = NULL) # 5 id numbers ## Was default in R <= 2.1.x: ## Cook's distances instead of ResidualLeverage plot plot(lm.SR, which = 1:4) ## Fit a smooth curve, where applicable: plot(lm.SR, panel = panel.smooth) ## Gives a smoother curve plot(lm.SR, panel = function(x, y) panel.smooth(x, y, span = 1)) par(mfrow = c(2,1)) # same oma as above plot(lm.SR, which = 1:2, sub.caption = "Saving Rates, n=50, p=5")