Rev 36637 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{plot.lm}\alias{plot.lm}\alias{plot.mlm}%which is .NotYetImplemented()\title{Plot Diagnostics for an lm Object}\usage{\method{plot}{lm}(x, which = c(1:3,5), %% was which = 1:4caption = c("Residuals vs Fitted", "Normal Q-Q","Scale-Location", "Cook's distance","Residuals vs Leverage", "Cook's distance vs Leverage"),panel = if(add.smooth) panel.smooth else points,sub.caption = NULL, main = "",ask = prod(par("mfcol")) < length(which) && dev.interactive(),\dots,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))}\arguments{\item{x}{\code{lm} object, typically result of \code{\link{lm}} or\code{\link{glm}}.}\item{which}{if a subset of the plots is required, specify a subset ofthe numbers \code{1:6}.}\item{caption}{captions to appear above the plots}\item{panel}{panel function. The useful alternative to\code{\link{points}}, \code{\link{panel.smooth}} can be chosenby \code{add.smooth = TRUE}.}\item{sub.caption}{common title---above figures if there are multiple;used as \code{sub} (s.\code{\link{title}}) otherwise. If \code{NULL},as by default, a possible shortened version of\code{deparse(x$call)} is used.}\item{main}{title to each plot---in addition to the above\code{caption}.}\item{ask}{logical; if \code{TRUE}, the user is \emph{ask}ed beforeeach plot, see \code{\link{par}(ask=.)}.}\item{\dots}{other parameters to be passed through to plottingfunctions.}\item{id.n}{number of points to be labelled in each plot, startingwith the most extreme.}\item{labels.id}{vector of labels, from which the labels for extremepoints will be chosen. \code{NULL} uses observation numbers.}\item{cex.id}{magnification of point labels.}\item{qqline}{logical indicating if a \code{\link{qqline}()} should beadded to the normal Q-Q plot.}\item{cook.levels}{levels of Cook's distance at which to draw contours.}\item{add.smooth}{logical indicating if a smoother should be added tomost plots; see also \code{panel} above.}\item{label.pos}{positioning of labels, for the left half and righthalf of the graph respectively, for plots 1-3.}}\description{Six plots (selectable by \code{which}) are currently available: a plotof residuals against fitted values, a Scale-Location plot of\eqn{\sqrt{| residuals |}} against fitted values, a Normal Q-Q plot, aplot of Cook's distances versus row labels, a plot of residualsagainst leverages, and a plot of Cook's distances againstleverage/(1-leverage). By default, the first% four of these are provided.three and \code{5} are provided.}\details{\code{sub.caption}---by default the function call---is shown asa subtitle (under the x-axis title) on each plot when plots are onseparate pages, or as a subtitle in the outer margin (if any) whenthere 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 inorder to diminish skewness (\eqn{\sqrt{| E |}} is much less skewedthan \eqn{| E |} for Gaussian zero-mean \eqn{E}).The \sQuote{S-L}, the Q-Q, and the Residual-Leverage plot, use\emph{standardized} residuals which have identical variance (under thehypothesis). 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,% bug in Rdconv: "$" and \link inside \code fails; '\$' doesn't help :\code{\link{influence}()}\code{$hat}, see also \code{\link{hat}}.The Residual-Leverage plot shows contours of equal Cook's distance,for values of \code{cook.levels} (by default 0.5 and 1) and omitscases with leverage one.If the leverages are constant, as typically in a balanced \code{\link{aov}}situation, the plot uses factor level combinations instead of theleverages for the x-axis.In the Cook's distance vs leverage/(1-leverage) plot, contours ofstandardized residuals that are equal in magnitude are lines throughthe origin. The contour lines are labeled with the magnitudes.}\references{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.Firth, D. (1991) Generalized Linear Models. In Hinkley, D. V. andReid, N. and Snell, E. J., eds: Pp. 55-82 in Statistical Theory andModelling. In Honour of Sir David Cox, FRS. London: Chapman and Hall.Hinkley, D. V. (1975) On power transformations tosymmetry. \emph{Biometrika} \bold{62}, 101--111.McCullagh, P. and Nelder, J. A. (1989)\emph{Generalized Linear Models.}London: Chapman and Hall.}\author{John Maindonald and Martin Maechler.}\seealso{\code{\link{termplot}}, \code{\link{lm.influence}},\code{\link{cooks.distance}}, \code{\link{hatvalues}}.}\examples{## Analysis of the life-cycle savings data## given in Belsley, Kuh and Welsch.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'splot(lm.SR, id.n = 5, labels.id = NULL)# 5 id numbers% ## Replace Cook's distance plot by Residual-Leverage plot% plot(lm.SR, which=c(1:3, 5))## Was default in R <= 2.1.x: Cook's distances instead of Residual-Leverage plotplot(lm.SR, which = 1:4)## Fit a smooth curve, where applicable:plot(lm.SR, panel = panel.smooth)## Gives a smoother curveplot(lm.SR, panel = function(x,y) panel.smooth(x, y, span = 1))par(mfrow=c(2,1))# same oma as aboveplot(lm.SR, which = 1:2, sub.caption = "Saving Rates, n=50, p=5")\dontshow{## An example with *long* formula that needs abbreviation:for(i in 1:5) assign(paste("long.var.name",i,sep="."), runif(10))plot(lm(long.var.name.1 ~long.var.name.2 + long.var.name.3 + long.var.name.4 + long.var.name.5))}}\keyword{hplot}\keyword{regression}