EVOLUTION-MANAGER
Edit File: plot.lm.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Plot Diagnostics for an lm Object</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for plot.lm {stats}"><tr><td>plot.lm {stats}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Plot Diagnostics for an lm Object</h2> <h3>Description</h3> <p>Six plots (selectable by <code>which</code>) are currently available: a plot of residuals against fitted values, a Scale-Location plot of <i>sqrt(| residuals |)</i> against fitted values, a Normal Q-Q 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/(1-leverage). By default, the first three and <code>5</code> are provided. </p> <h3>Usage</h3> <pre> ## S3 method for class 'lm' plot(x, which = c(1,2,3,5), caption = list("Residuals vs Fitted", "Normal Q-Q", "Scale-Location", "Cook's distance", "Residuals vs Leverage", expression("Cook's dist vs Leverage " * h[ii] / (1 - h[ii]))), panel = if(add.smooth) function(x, y, ...) panel.smooth(x, y, iter=iter.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"), iter.smooth = if(isGlm && binomialLike) 0 else 3, label.pos = c(4,2), cex.caption = 1, cex.oma.main = 1.25) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p><code>lm</code> object, typically result of <code><a href="lm.html">lm</a></code> or <code><a href="glm.html">glm</a></code>.</p> </td></tr> <tr valign="top"><td><code>which</code></td> <td> <p>if a subset of the plots is required, specify a subset of the numbers <code>1:6</code>, see <code>caption</code> below (and the ‘Details’) for the different kinds.</p> </td></tr> <tr valign="top"><td><code>caption</code></td> <td> <p>captions to appear above the plots; <code><a href="../../base/html/character.html">character</a></code> vector or <code><a href="../../base/html/list.html">list</a></code> of valid graphics annotations, see <code><a href="../../grDevices/html/as.graphicsAnnot.html">as.graphicsAnnot</a></code>, of length 6, the j-th entry corresponding to <code>which[j]</code>. Can be set to <code>""</code> or <code>NA</code> to suppress all captions. </p> </td></tr> <tr valign="top"><td><code>panel</code></td> <td> <p>panel function. The useful alternative to <code><a href="../../graphics/html/points.html">points</a></code>, <code><a href="../../graphics/html/panel.smooth.html">panel.smooth</a></code> can be chosen by <code>add.smooth = TRUE</code>.</p> </td></tr> <tr valign="top"><td><code>sub.caption</code></td> <td> <p>common title—above the figures if there are more than one; used as <code>sub</code> (s.<code><a href="../../graphics/html/title.html">title</a></code>) otherwise. If <code>NULL</code>, as by default, a possible abbreviated version of <code>deparse(x$call)</code> is used.</p> </td></tr> <tr valign="top"><td><code>main</code></td> <td> <p>title to each plot—in addition to <code>caption</code>.</p> </td></tr> <tr valign="top"><td><code>ask</code></td> <td> <p>logical; if <code>TRUE</code>, the user is <em>ask</em>ed before each plot, see <code><a href="../../graphics/html/par.html">par</a>(ask=.)</code>.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>other parameters to be passed through to plotting functions.</p> </td></tr> <tr valign="top"><td><code>id.n</code></td> <td> <p>number of points to be labelled in each plot, starting with the most extreme.</p> </td></tr> <tr valign="top"><td><code>labels.id</code></td> <td> <p>vector of labels, from which the labels for extreme points will be chosen. <code>NULL</code> uses observation numbers.</p> </td></tr> <tr valign="top"><td><code>cex.id</code></td> <td> <p>magnification of point labels.</p> </td></tr> <tr valign="top"><td><code>qqline</code></td> <td> <p>logical indicating if a <code><a href="qqnorm.html">qqline</a>()</code> should be added to the normal Q-Q plot.</p> </td></tr> <tr valign="top"><td><code>cook.levels</code></td> <td> <p>levels of Cook's distance at which to draw contours.</p> </td></tr> <tr valign="top"><td><code>add.smooth</code></td> <td> <p>logical indicating if a smoother should be added to most plots; see also <code>panel</code> above.</p> </td></tr> <tr valign="top"><td><code>iter.smooth</code></td> <td> <p>the number of robustness iterations, the argument <code>iter</code> in <code><a href="../../graphics/html/panel.smooth.html">panel.smooth</a>()</code>; the default uses no such iterations for <code><a href="glm.html">glm</a>(*, family=binomial)</code> fits which is particularly desirable for the (predominant) case of binary observations.</p> </td></tr> <tr valign="top"><td><code>label.pos</code></td> <td> <p>positioning of labels, for the left half and right half of the graph respectively, for plots 1-3.</p> </td></tr> <tr valign="top"><td><code>cex.caption</code></td> <td> <p>controls the size of <code>caption</code>.</p> </td></tr> <tr valign="top"><td><code>cex.oma.main</code></td> <td> <p>controls the size of the <code>sub.caption</code> only if that is <em>above</em> the figures when there is more than one.</p> </td></tr> </table> <h3>Details</h3> <p><code>sub.caption</code>—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. </p> <p>The ‘Scale-Location’ plot, also called ‘Spread-Location’ or ‘S-L’ plot, takes the square root of the absolute residuals in order to diminish skewness (<i>sqrt(|E|)</i> is much less skewed than <i>| E |</i> for Gaussian zero-mean <i>E</i>). </p> <p>The ‘S-L’, the Q-Q, and the Residual-Leverage plot, use <em>standardized</em> residuals which have identical variance (under the hypothesis). They are given as <i>R[i] / (s * sqrt(1 - h.ii))</i> where <i>h.ii</i> are the diagonal entries of the hat matrix, <code><a href="lm.influence.html">influence</a>()$hat</code> (see also <code><a href="influence.measures.html">hat</a></code>), and where the Residual-Leverage plot uses standardized Pearson residuals (<code><a href="glm.summaries.html">residuals.glm</a>(type = "pearson")</code>) for <i>R[i]</i>. </p> <p>The Residual-Leverage plot shows contours of equal Cook's distance, for values of <code>cook.levels</code> (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 <code><a href="aov.html">aov</a></code> situation) the plot uses factor level combinations instead of the leverages for the x-axis. (The factor levels are ordered by mean fitted value.) </p> <p>In the Cook's distance vs leverage/(1-leverage) plot, contours of standardized residuals (<code><a href="influence.measures.html">rstandard</a>(.)</code>) that are equal in magnitude are lines through the origin. The contour lines are labelled with the magnitudes. </p> <h3>Author(s)</h3> <p>John Maindonald and Martin Maechler. </p> <h3>References</h3> <p>Belsley, D. A., Kuh, E. and Welsch, R. E. (1980). <em>Regression Diagnostics</em>. New York: Wiley. </p> <p>Cook, R. D. and Weisberg, S. (1982). <em>Residuals and Influence in Regression</em>. London: Chapman and Hall. </p> <p>Firth, D. (1991) Generalized Linear Models. In Hinkley, D. V. and Reid, N. and Snell, E. J., eds: Pp. 55-82 in Statistical Theory and Modelling. In Honour of Sir David Cox, FRS. London: Chapman and Hall. </p> <p>Hinkley, D. V. (1975). On power transformations to symmetry. <em>Biometrika</em>, <b>62</b>, 101–111. doi: <a href="https://doi.org/10.2307/2334491">10.2307/2334491</a>. </p> <p>McCullagh, P. and Nelder, J. A. (1989). <em>Generalized Linear Models</em>. London: Chapman and Hall. </p> <h3>See Also</h3> <p><code><a href="termplot.html">termplot</a></code>, <code><a href="lm.influence.html">lm.influence</a></code>, <code><a href="influence.measures.html">cooks.distance</a></code>, <code><a href="influence.measures.html">hatvalues</a></code>. </p> <h3>Examples</h3> <pre> require(graphics) ## Analysis of the life-cycle 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 Residual-Leverage 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") </pre> <hr /><div style="text-align: center;">[Package <em>stats</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>