plot.lm                package:stats                R Documentation

_P_l_o_t _D_i_a_g_n_o_s_t_i_c_s _f_o_r _a_n _l_m _O_b_j_e_c_t

_D_e_s_c_r_i_p_t_i_o_n:

     Four plots (selectable by 'which') are currently provided: a plot
     of residuals against fitted values, a Scale-Location plot of
     sqrt{| residuals |} against fitted values, a Normal Q-Q plot, and
     a plot of Cook's distances versus row labels.

_U_s_a_g_e:

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

_A_r_g_u_m_e_n_t_s:

       x: 'lm' object, typically result of 'lm' or 'glm'.

   which: If a subset of the plots is required, specify a subset of the
          numbers '1:4'.

 caption: Captions to appear above the plots

   panel: Panel function.  A useful alternative to 'points' is
          'panel.smooth'.

sub.caption: common title-above figures if there are multiple; used as
          'sub' (s.'title') otherwise.

    main: title to each plot-in addition to the above 'caption'.

     ask: logical; if 'TRUE', the user is _ask_ed before each plot, see
          'par(ask=.)'.

     ...: 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.  'NULL' uses observation numbers.

  cex.id: magnification of point labels.

_D_e_t_a_i_l_s:

     '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 "Scale-Location" plot, also called "Spread-Location" or "S-L"
     plot, takes the square root of the absolute residuals in order to
     diminish skewness (sqrt{| E |} is much less skewed than | E | for
     Gaussian zero-mean E).

     This 'S-L' and the Q-Q 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'.

_A_u_t_h_o_r(_s):

     John Maindonald and Martin Maechler.

_R_e_f_e_r_e_n_c_e_s:

     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.

     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.

_S_e_e _A_l_s_o:

     'termplot', 'lm.influence', 'cooks.distance'.

_E_x_a_m_p_l_e_s:

     ## 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'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")

