plot.regr: Diagnostic Plots for Regr Objects

Description Usage Arguments Details Value Note Author(s) See Also Examples

Description

Diagnostic plots for fitted regression models: Residuals versus fit (Tukey-Anscombe plot) and/or target variable versus fit; Absolute residuals versus fit to assess equality of error variances; Normal Q-Q plot (for ordinary regression models); Residuals versus leverages to identify influential observations; Residuals versus sequence (if requested); and residuals versus explanatory variables. These plots are adjusted to the type of regression model.

Usage

1
2
3
4
5
6
7
8
## S3 method for class 'regr'
plot(x, data = NULL, plotselect = NULL, xvars = TRUE,
  rawvars = TRUE, sequence = FALSE, weights = NULL, addcomp = FALSE,
  smooth.legend = FALSE, ...)

plresx(x, data = NULL, xvars = NULL, formula = NULL,
  rawvars = TRUE, sequence = FALSE, weights = NULL, addcomp = FALSE,
  smooth.legend = FALSE, ...)

Arguments

x

regr object (result of a call to regr). Thiw iw the only argument that is needed. All others have useful defaults.

data

data set where explanatory variables and the following possible arguments are found: weights, plweights, pch, plabs

plotselect

which plots should be shown? See Details

xvars

if TRUE, residuals will be plotted versus all (raw) explanatory variables in the model (by calling plresx). If it is a formula, it contains the variables to be used. These need not be contained in the model. The model formula is updated by such a formula. Whence, the use of \~{}.+ adds variables to those in the model.

formula

same as xvars. If both arguments are given, formula is used.

rawvars

logical: should residuals be shown against raw explanatory variables? If FALSE, the variables are transformed as implied by the model.

sequence

if TRUE, residuals will be plotted versus the sequence as they appear in the data. If another explanatory variable is monotone increasing or decreasing, the plot is not shown, but a warning is given.

weights

if TRUE, residuals will be plotted versus x$weights. Alternatively, a vector of weights can be specified

addcomp

logical: should component effects be added to residuals for residuals versus input variables plots?

smooth.legend

When a grouping factor is used (argument smooth.group, see below), this argument determines whether and where the legend for identifying the groups should be shown, see Details

...

Many further arguments are available to customize the plots, see below for some of the most useful ones, and plotregr.control for a complete list.

Details

Argument plotselect is used to determine which plots will be shown. It should be a named vector of numbers indicating

0

do not show

1

show without smooth

2

show with smooth (not for qq nor leverage)

3

show with smooth and smooth band (only for resfit in plot.regr and in plresx)

The default is c( yfit=0, resfit=smdef, absresfit = NA, absresweights = NA, qq = NA, leverage = 2, resmatrix = 1, qqmult = 3), where smdef is 3 (actually argument smooth of plotregr.control plus 1) for normal random deviations and one less (no band) for others.

Modify this vector to change the selection and the sequence in which the plots appear. Alternatively, provide a named vector defining all plots that should be shown on a different level than the default indicates, like plotselect = c(resfit = 2, leverage = 1). Adding an element default = 0 suppresses all plots not mentioned. This is useful to select single plots, like plotselect = c(resfit = 3, default = 0)

The names of plotselect refer to:

yfit

response versus fitted values

resfit

residuals versus fitted values (Tukey-Anscombe plot)

absresfit

residuals versus fitted values, defaults to TRUE for ordinary regression, FALSE for glm and others

absresweights

residuals versus weights

qq

normal Q-Q plot, defaults to TRUE for ordinary regression, FALSE for glm and others

leverage

residuals versus leverage (hat diabgonal)

resmatrix

scatterplot matrix of residuals for multivariate regression

qqmult

qq plot for Mahlanobis lengths versus sqrt of chisquare quantiles.

In the 'resfit' (Tukey-Anscombe) plot, the reference line indicates a "contour" line with constant values of the response variable, Y=\widehat y+r= constant. It has slope -1. It is useful to judge whether any curvature shown by the smooth might disappear after a nonlinear, monotone transformation of the response.

If smresid is true, the 'absresfit' plot uses modified residuals: differences between the ordinary residuals and the smooth appearing in the 'resfit' plot. Analogously, the 'qq' plot is then based on yet another modification of these modified residuals: they are scaled by the smoothed scale shown in the 'absresfit' plot, after these scales have been standardized to have a median of 0.674 (=qnorm(0.75)).

The smoothing function used by default is smoothRegr, which calls loess. This can be changed by setting userOptions(smoothFunction=<func>), which must have the same arguments as smoothRegr.

The arguments lty, lwd, colors characterize how the graphical elements in the plot are shown. They should be three vectors of length 9 each, defining the line types, line widths, and colors to be used for ...

[1]

observations;

[2]

reference lines;

[3]

smooth;

[4]

simulated smooths;

[5]

component effects in plresx;

[6]

confidence bands of component effects.

In the case of glm.restype="cond.quant"

[7]

(random) observations;

[8]

conditional medians;

[9]

bars showing conditional quantiles.

If smooths are shown according to groups (given in smooth.group), then a legend can be required and positioned in the respecive plots by using the argument smooth.legend. If it is TRUE, then the legend will be placed in the "bottomright" corner. Alternatively, the corner can be specified as "bottomright", "bottomleft", "topleft", or "topright". A coordinate pair may also be given. These possibilities can be used individually for each plot by giving a named vector or a named list, where the names are one of "yfit", "resfit", "absresfit", "absresweight", "(xvars)" or names of x variables provided by the xvars argument. A component "(xvars)" selects the first x variable.

Value

The list of the evaluations of all arguments and some more useful items is returned invisibly.

Note

This is a function under development. Future versions may behave differently and may not be compatible with this version.

Author(s)

Werner A. Stahel, ETH Zurich

See Also

plotregr.control, plot.lm

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
  r.savings <- regr(sr ~ pop15 + pop75 + dpi + ddpi, data = LifeCycleSavings)
  plot(r.savings)

  data(d.blast)
  r.blast <-
       regr(log10(tremor)~location+log10(distance)+log10(charge),
            data=d.blast)
  plot(r.blast, sequence=TRUE, rawvars=FALSE) 

  data(d.fossiles)
  r.foss <-
    regr(cbind(sAngle,lLength,rWidth)~SST.Mean+Salinity+lChlorophyll+region+N,
    data=d.fossiles)
  plot(r.foss, plotselect=c(resfit=3, resmatrix=1, qqmult=1),xvars=FALSE)

regr0 documentation built on May 2, 2019, 4:52 p.m.

Related to plot.regr in regr0...