\Header{plot.lm}{Plot Diagnostics for an lm Object}
\alias{plot.mlm}{plot.lm}
\keyword{hplot}{plot.lm}
\keyword{regression}{plot.lm}
\begin{Description}\relax
Four plots (selectable by \code{which}) are currently provided: a plot
of residuals against fitted values, a Scale-Location plot of
\eqn{\sqrt{| residuals |}}{} against fitted values, a Normal Q-Q plot,
and a plot of Cook's distances versus row labels.
\end{Description}
\begin{Usage}
\begin{verbatim}
## S3 method for class 'lm':
plot(x, which = 1:4,
     caption = c("Residuals vs Fitted", "Normal Q-Q plot",
                 "Scale-Location plot", "Cook's distance plot"),
     panel = points,
     sub.caption = deparse(x$call), main = "",
     ask = prod(par("mfcol")) < length(which) && dev.interactive(),
     ...,
     id.n = 3, labels.id = names(residuals(x)), cex.id = 0.75)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] \code{lm} object, typically result of \code{\Link{lm}} or
\code{\Link{glm}}.
\item[\code{which}] If a subset of the plots is required, specify a subset of
the numbers \code{1:4}.
\item[\code{caption}] Captions to appear above the plots
\item[\code{panel}] Panel function.  A useful alternative to
\code{\Link{points}} is \code{\Link{panel.smooth}}.
\item[\code{sub.caption}] common title---above figures if there are multiple;
used as \code{sub} (s.\code{\Link{title}}) otherwise.
\item[\code{main}] title to each plot---in addition to the above
\code{caption}.
\item[\code{ask}] logical; if \code{TRUE}, the user is \emph{ask}ed before
each plot, see \code{\Link{par}(ask=.)}.
\item[\code{...}] other parameters to be passed through to plotting
functions.
\item[\code{id.n}] number of points to be labelled in each plot, starting
with the most extreme.
\item[\code{labels.id}] vector of labels, from which the labels for extreme
points will be chosen.  \code{NULL} uses observation numbers.
\item[\code{cex.id}] magnification of point labels.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
\code{sub.caption}---by default the function call---is shown as
a subtitle (under the x-axis 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 \dQuote{Scale-Location} plot, also called \dQuote{Spread-Location} or
\dQuote{S-L} plot, takes the square root of the absolute residuals in
order to diminish skewness (\eqn{\sqrt{| E |}}{} is much less skewed
than \eqn{| E |}{} for Gaussian zero-mean \eqn{E}{}).

This \sQuote{S-L} and the Q-Q plot use \emph{standardized} residuals
which have identical variance (under the hypothesis).  They are given
as \eqn{R_i / (s \times \sqrt{1 - h_{ii}})}{R[i] / (s*sqrt(1 - h.ii))}
where \eqn{h_{ii}}{h.ii} are the diagonal entries of the hat matrix,
\code{\Link{influence}()}\code{\$hat}, see also \code{\Link{hat}}.
\end{Details}
\begin{Author}\relax
John Maindonald and Martin Maechler.
\end{Author}
\begin{References}\relax
Belsley, D. A., Kuh, E. and Welsch, R. E. (1980)
\emph{Regression Diagnostics.}  New York: Wiley.

Cook, R. D. and Weisberg, S. (1982)
\emph{Residuals and Influence in Regression.}
London: Chapman and Hall.

Hinkley, D. V. (1975) On power transformations to
symmetry. \emph{Biometrika} \bold{62}, 101--111.

McCullagh, P. and Nelder, J. A. (1989)
\emph{Generalized Linear Models.}
London: Chapman and Hall.
\end{References}
\begin{SeeAlso}\relax
\code{\Link{termplot}}, \code{\Link{lm.influence}},
\code{\Link{cooks.distance}}.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
## Analysis of the life-cycle savings data
## given in Belsley, Kuh and Welsch.
data(LifeCycleSavings)
plot(lm.SR <- lm(sr ~ pop15 + pop75 + dpi + ddpi, data = LifeCycleSavings))

## 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

## 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")
\end{ExampleCode}
\end{Examples}

