| 1 |
\name{p.res.2x} |
| 2 |
\title{Stahel's Residual Plot against 2 X's} |
| 3 |
\alias{p.res.2x} |
| 4 |
\alias{p.res.2x.default} |
| 5 |
\alias{p.res.2x.formula} |
| 6 |
\description{ |
| 7 |
Plot Residuals, e.g., of a multiple linear regression, against two |
| 8 |
(predictor) variables, using positively and negatively oriented line |
| 9 |
segments for positive and negative residuals. |
| 10 |
|
| 11 |
This is a (S3) \emph{generic} function with a \code{default} and a |
| 12 |
\code{\link{formula}} method. |
| 13 |
} |
| 14 |
\usage{ |
| 15 |
p.res.2x(x, \dots) |
| 16 |
|
| 17 |
\S3method{p.res.2x}{default}(x, y, z, restricted, size = 1, slwd = 1, scol = 2:3, |
| 18 |
xlab = NULL, ylab = NULL, main = NULL, |
| 19 |
xlim = range(x), ylim = range(y), \dots) |
| 20 |
|
| 21 |
\S3method{p.res.2x}{formula}(x = ~., data, main = deparse(substitute(data)), |
| 22 |
xlab = NULL, ylab = NULL, \dots) |
| 23 |
} |
| 24 |
\arguments{ |
| 25 |
\item{x, y}{numeric vectors of the same length specifying 2 |
| 26 |
covariates. For the \code{formula} method, \code{x} is a \code{\link{formula}}.} |
| 27 |
\item{z}{numeric vector of same length as \code{x} and \code{y}, |
| 28 |
typically residuals.} |
| 29 |
\item{restricted}{positive value which truncates the size. The |
| 30 |
corresponding symbols are marked by stars.} |
| 31 |
\item{size}{the symbols are scaled so that \code{size} is the size of |
| 32 |
the largest symbol in cm.} |
| 33 |
\item{slwd, scol}{line width and color(s) for the residual |
| 34 |
\code{\link{segments}}. If \code{scol} has length 2 as per default, |
| 35 |
the two colors are used for positive and negative \code{z} values, |
| 36 |
respectively.} |
| 37 |
\item{xlab, ylab, main}{axis labels, and title see \code{\link{title}}, |
| 38 |
each with a sensible default. To suppress, use, e.g., \code{main = ""}.} |
| 39 |
\item{xlim, ylim}{the basic x- and y- axis extents, see |
| 40 |
\code{\link{plot.default}}. Note that these will be slightly |
| 41 |
extended such that segments are not cut off.} |
| 42 |
\item{\dots}{further arguments passed to \code{plot}, or |
| 43 |
\code{p.res.2x.default()}, respectively.} |
| 44 |
|
| 45 |
\item{data}{(for the \code{\link{formula}} method:) a data frame or a fitted |
| 46 |
\code{"\link{lm}"} object.} |
| 47 |
} |
| 48 |
\details{ |
| 49 |
Each residual \code{zz[i]} is visualized as line segment centered at |
| 50 |
\eqn{(xx_i,yy_i)}{(xx[i], yy[i])}, \eqn{i=1,\dots,n}, where the |
| 51 |
\emph{length}s of the segments are proportional to the absolute |
| 52 |
values \eqn{\|zz_i\|}{|zz[i]|}. |
| 53 |
|
| 54 |
Positive residuals' line segments have slope \eqn{+1}, and negative ones |
| 55 |
slope \eqn{-1}, and \code{scol} is used to use different colors for |
| 56 |
negative and positive segments. |
| 57 |
|
| 58 |
The formula interface calls \code{\link{p.res.2fact}()} when |
| 59 |
\emph{both} \code{x} and \code{y} are \code{\link{factor}}s. |
| 60 |
} |
| 61 |
\references{ |
| 62 |
Stahel, W.~A. (2008) \emph{Statistische Datenanalyse: Eine |
| 63 |
\enc{Einführung für}{Einfuehrung fuer} Naturwissenschaftler}, |
| 64 |
5. Auflage, Vieweg, Wiesbaden; Paragraph 13.8.r and 13.8.v. |
| 65 |
} |
| 66 |
\author{Andreas Ruckstuhl in June 1991 and Martin Maechler, in 1992, '94, 2003-4.} |
| 67 |
\seealso{\code{\link{p.res.2fact}}, |
| 68 |
\code{\link{plot.lm}}, |
| 69 |
\code{\link{TA.plot}}. |
| 70 |
} |
| 71 |
\examples{ |
| 72 |
xx <- rep(1:10,7) |
| 73 |
yy <- rep(1:7, rep(10,7)) |
| 74 |
zz <- rnorm(70) |
| 75 |
p.res.2x(xx,yy,zz, restricted = 2, main = "i.i.d. N(0,1) random residuals") |
| 76 |
\dontshow{ |
| 77 |
p.res.2x(xx,yy,zz, restricted = 2, main = "p.res.2x(*, xlim, ylim)", |
| 78 |
xlim = c(2,8), ylim = c(1,4)) |
| 79 |
} |
| 80 |
example(lm.influence, echo = FALSE) |
| 81 |
|
| 82 |
op <- mult.fig(2, marP=c(-1,-1,-1,0), main="p.res.2x(*,*, residuals(lm.SR))")$old.par |
| 83 |
with(LifeCycleSavings, |
| 84 |
{ p.res.2x(pop15, ddpi, residuals(lm.SR), scol=c("red", "blue")) |
| 85 |
p.res.2x(pop75, dpi, residuals(lm.SR), scol=2:1) |
| 86 |
}) |
| 87 |
|
| 88 |
## with formula interface: |
| 89 |
p.res.2x(~ pop15 + ddpi, lm.SR, scol=c("red", "blue")) |
| 90 |
p.res.2x(~ pop75 + dpi, lm.SR, scol=2:1) |
| 91 |
|
| 92 |
par(op) # revert par() settings above |
| 93 |
} |
| 94 |
\keyword{hplot} |
| 95 |
\keyword{regression} |