Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

TA.plot

Tukey-Anscombe Plot (Residual vs. Fitted) of a Linear Model


Description

From a linear (or glm) model fitted, produce the so-called Tukey-Anscombe plot. Useful (optional) additions include: 0-line, lowess smooth, 2sigma lines, and automatic labeling of observations.

Usage

TA.plot(lm.res,
        fit= fitted(lm.res), res= residuals(lm.res, type="pearson"),
        labels= NULL, main= mk.main(), xlab = "Fitted values",
        draw.smooth= n >= 10, show.call = TRUE, show.2sigma= TRUE,
        lo.iter = NULL, lo.cex= NULL,
        par0line  = list(lty = 2, col = "gray"),
        parSmooth = list(lwd = 1.5, lty = 4, col = 2),
        parSigma  = list(lwd = 1.2, lty = 3, col = 4),
        verbose = FALSE,
        ...)

Arguments

lm.res

Result of lm(..), aov(..), glm(..) or a similar object.

fit

fitted values; you probably want the default here.

res

residuals to use. Default: Weighted ("Pearson") residuals if weights have been used for the model fit.

labels

strings to use as plotting symbols for each point. Default(NULL): extract observations' names or use its sequence number. Use, e.g., "*" to get simple * symbols.

main

main title to plot. Default: sophisticated, resulting in something like "Tukey-Anscombe Plot of : y \~ x" constructed from lm.res $ call.

xlab

x-axis label for plot.

draw.smooth

logical; if TRUE, draw a lowess smoother (with automatic smoothing fraction).

show.call

logical; if TRUE, write the "call"ing syntax with which the fit was done.

show.2sigma

logical; if TRUE, draw horizontal lines at +- 2 sigma where σ is mad(resid).

lo.iter

positive integer, giving the number of lowess robustness iterations. The default depends on the model and is 0 for non Gaussian glm's.

lo.cex

character expansion ("cex") for lowess and other marginal texts.

par0line

a list of arguments (with reasonable defaults) to be passed to abline(.) when drawing the x-axis, i.e., the y = 0 line.

parSmooth, parSigma

each a list of arguments (with reasonable default) for drawing the smooth curve (if draw.smooth is true), or the horizontal sigma boundaries (if show.2sigma is true) respectively.

verbose

logical indicating if some construction details should be reported (print()ed).

...

further graphical parameters are passed to n.plot(.).

Side Effects

The above mentioned plot is produced on the current graphic device.

Author(s)

Martin Maechler, Seminar fuer Statistik, ETH Zurich, Switzerland; maechler@stat.math.ethz.ch

See Also

plot.lm which also does a QQ normal plot and more.

Examples

data(stackloss)
TA.plot(lm(stack.loss ~ stack.x))

example(airquality)
summary(lmO <- lm(Ozone ~ ., data= airquality))
TA.plot(lmO)
TA.plot(lmO, label = "O") # instead of case numbers

if(FALSE) { 
 TA.plot(lm(cost ~ age+type+car.age, claims, weights=number, na.action=na.omit))
}

##--- for  aov(.) : -------------
data(Gun, package = "nlme")
TA.plot( aov(rounds ~ Method + Physique/Team, data = Gun))

##--- Not so clear what it means for GLM, but: ------
if(require(rpart)) { # for the two datasets only
 data(solder, package = "rpart")
 TA.plot(glm(skips ~ ., data = solder, family = poisson), cex= .6)

 data(kyphosis, package = "rpart")
 TA.plot(glm(Kyphosis ~ poly(Age,2) + Start, data=kyphosis, family = binomial),
	 cex=.75) # smaller title and plotting characters
}

sfsmisc

Utilities from 'Seminar fuer Statistik' ETH Zurich

v1.1-11
GPL (>= 2)
Authors
Martin Maechler [aut, cre] (<https://orcid.org/0000-0002-8685-9910>), Werner Stahel [ctb] (Functions: compresid2way(), f.robftest(), last(), p.scales(), p.dnorm()), Andreas Ruckstuhl [ctb] (Functions: p.arrows(), p.profileTraces(), p.res.2x()), Christian Keller [ctb] (Functions: histBxp(), p.tachoPlot()), Kjetil Halvorsen [ctb] (Functions: KSd(), ecdf.ksCI()), Alain Hauser [ctb] (Functions: cairoSwd(), is.whole(), toLatex.numeric()*), Christoph Buser [ctb] (to function Duplicated()), Lorenz Gygax [ctb] (to function p.res.2fact()), Bill Venables [ctb] (Functions: empty.dimnames(), primes()), Tony Plate [ctb] (to inv.seq()), Isabelle Fl<fc>ckiger [ctb], Marcel Wolbers [ctb], Markus Keller [ctb], Sandrine Dudoit [ctb], Jane Fridlyand [ctb], Greg Snow [ctb] (to loessDemo()), Henrik Aa. Nielsen [ctb] (to loessDemo()), Vincent Carey [ctb], Ben Bolker [ctb], Philippe Grosjean [ctb], Fr<e9>d<e9>ric Ibanez [ctb], Caterina Savi [ctb], Charles Geyer [ctb], Jens Oehlschl<e4>gel [ctb]
Initial release
2021-04-03

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.