| Line 1... |
Line 1... |
| 1 |
% File src/library/stats/man/plot.lm.Rd
|
1 |
% File src/library/stats/man/plot.lm.Rd
|
| 2 |
% Part of the R package, https://www.R-project.org
|
2 |
% Part of the R package, https://www.R-project.org
|
| 3 |
% Copyright 1995-2019 R Core Team
|
3 |
% Copyright 1995-2021 R Core Team
|
| 4 |
% Distributed under GPL 2 or later
|
4 |
% Distributed under GPL 2 or later
|
| 5 |
|
5 |
|
| 6 |
\name{plot.lm}
|
6 |
\name{plot.lm}
|
| 7 |
\alias{plot.lm}
|
7 |
\alias{plot.lm}
|
| 8 |
% \alias{plot.mlm} %which is .NotYetImplemented()
|
8 |
% \alias{plot.mlm} %which is .NotYetImplemented()
|
| Line 10... |
Line 10... |
| 10 |
\usage{
|
10 |
\usage{
|
| 11 |
\method{plot}{lm}(x, which = c(1,2,3,5), %% was which = 1:4
|
11 |
\method{plot}{lm}(x, which = c(1,2,3,5), %% was which = 1:4
|
| 12 |
caption = list("Residuals vs Fitted", "Normal Q-Q",
|
12 |
caption = list("Residuals vs Fitted", "Normal Q-Q",
|
| 13 |
"Scale-Location", "Cook's distance",
|
13 |
"Scale-Location", "Cook's distance",
|
| 14 |
"Residuals vs Leverage",
|
14 |
"Residuals vs Leverage",
|
| 15 |
expression("Cook's dist vs Leverage " * h[ii] / (1 - h[ii]))),
|
15 |
expression("Cook's dist vs Leverage* " * h[ii] / (1 - h[ii]))),
|
| 16 |
panel = if(add.smooth) function(x, y, ...)
|
16 |
panel = if(add.smooth) function(x, y, ...)
|
| 17 |
panel.smooth(x, y, iter=iter.smooth, ...) else points,
|
17 |
panel.smooth(x, y, iter=iter.smooth, ...) else points,
|
| 18 |
sub.caption = NULL, main = "",
|
18 |
sub.caption = NULL, main = "",
|
| 19 |
ask = prod(par("mfcol")) < length(which) && dev.interactive(),
|
19 |
ask = prod(par("mfcol")) < length(which) && dev.interactive(),
|
| 20 |
\dots,
|
20 |
\dots,
|
| Line 26... |
Line 26... |
| 26 |
cex.caption = 1, cex.oma.main = 1.25)
|
26 |
cex.caption = 1, cex.oma.main = 1.25)
|
| 27 |
}
|
27 |
}
|
| 28 |
\arguments{
|
28 |
\arguments{
|
| 29 |
\item{x}{\code{lm} object, typically result of \code{\link{lm}} or
|
29 |
\item{x}{\code{lm} object, typically result of \code{\link{lm}} or
|
| 30 |
\code{\link{glm}}.}
|
30 |
\code{\link{glm}}.}
|
| 31 |
\item{which}{if a subset of the plots is required, specify a subset of
|
31 |
\item{which}{a subset of the numbers \code{1:6}, by default \code{1:3, 5},
|
| - |
|
32 |
referring to \enumerate{
|
| 32 |
the numbers \code{1:6}, see \code{caption} below (and the
|
33 |
\item "Residuals vs Fitted", aka \sQuote{Tukey-Anscombe} plot. % 1
|
| - |
|
34 |
\item "Normal Q-Q" plot, an enhanced \code{\link{qqnorm}(resid(.))} % 2
|
| - |
|
35 |
\item "Scale-Location" % 3
|
| - |
|
36 |
\item "Cook's distance" % 4
|
| - |
|
37 |
\item "Residuals vs Leverage" % 5
|
| - |
|
38 |
\item "Cook's dist vs Lev./(1-Lev.)" % 6
|
| - |
|
39 |
},
|
| 33 |
\sQuote{Details}) for the different kinds.}
|
40 |
see also \sQuote{Details} below.}
|
| 34 |
\item{caption}{captions to appear above the plots;
|
41 |
\item{caption}{captions to appear above the plots;
|
| 35 |
\code{\link{character}} vector or \code{\link{list}} of valid
|
42 |
\code{\link{character}} vector or \code{\link{list}} of valid
|
| 36 |
graphics annotations, see \code{\link{as.graphicsAnnot}}, of length
|
43 |
graphics annotations, see \code{\link{as.graphicsAnnot}}, of length
|
| 37 |
6, the j-th entry corresponding to \code{which[j]}. Can be set to
|
44 |
6, the j-th entry corresponding to \code{which[j]}, see also the
|
| - |
|
45 |
default vector in \sQuote{Usage}. Can be set to
|
| 38 |
\code{""} or \code{NA} to suppress all captions.
|
46 |
\code{""} or \code{NA} to suppress all captions.
|
| 39 |
}
|
47 |
}
|
| 40 |
\item{panel}{panel function. The useful alternative to
|
48 |
\item{panel}{panel function. The useful alternative to
|
| 41 |
\code{\link{points}}, \code{\link{panel.smooth}} can be chosen
|
49 |
\code{\link{points}}, \code{\link{panel.smooth}} can be chosen
|
| 42 |
by \code{add.smooth = TRUE}.}
|
50 |
by \code{add.smooth = TRUE}.}
|
| Line 85... |
Line 93... |
| 85 |
\code{sub.caption}---by default the function call---is shown as
|
93 |
\code{sub.caption}---by default the function call---is shown as
|
| 86 |
a subtitle (under the x-axis title) on each plot when plots are on
|
94 |
a subtitle (under the x-axis title) on each plot when plots are on
|
| 87 |
separate pages, or as a subtitle in the outer margin (if any) when
|
95 |
separate pages, or as a subtitle in the outer margin (if any) when
|
| 88 |
there are multiple plots per page.
|
96 |
there are multiple plots per page.
|
| 89 |
|
97 |
|
| 90 |
The \sQuote{Scale-Location} plot, also called \sQuote{Spread-Location} or
|
98 |
The \sQuote{Scale-Location} plot (\code{which=3}), also called \sQuote{Spread-Location} or
|
| 91 |
\sQuote{S-L} plot, takes the square root of the absolute residuals in
|
99 |
\sQuote{S-L} plot, takes the square root of the absolute residuals in
|
| 92 |
order to diminish skewness (\eqn{\sqrt{| E |}}{sqrt(|E|)} is much less skewed
|
100 |
order to diminish skewness (\eqn{\sqrt{| E |}}{sqrt(|E|)} is much less skewed
|
| 93 |
than \eqn{| E |} for Gaussian zero-mean \eqn{E}).
|
101 |
than \eqn{| E |} for Gaussian zero-mean \eqn{E}).
|
| 94 |
|
102 |
|
| 95 |
The \sQuote{S-L}, the Q-Q, and the Residual-Leverage plot, use
|
103 |
The \sQuote{S-L}, the Q-Q, and the Residual-Leverage (\code{which=5}) plot use
|
| 96 |
\emph{standardized} residuals which have identical variance (under the
|
104 |
\emph{standardized} residuals which have identical variance (under the
|
| 97 |
hypothesis). They are given as
|
105 |
hypothesis). They are given as
|
| 98 |
\eqn{R_i / (s \times \sqrt{1 - h_{ii}})}{R[i] / (s * sqrt(1 - h.ii))}
|
106 |
\eqn{R_i / (s \times \sqrt{1 - h_{ii}})}{R[i] / (s * sqrt(1 - h.ii))}
|
| 99 |
where \eqn{h_{ii}}{h.ii} are the diagonal entries of the hat matrix,
|
107 |
where the \emph{\sQuote{leverages}} \eqn{h_{ii}}{h.ii} are the diagonal entries
|
| - |
|
108 |
of the hat matrix,
|
| 100 |
\code{\link{influence}()$hat} (see also \code{\link{hat}}), and
|
109 |
\code{\link{influence}()$hat} (see also \code{\link{hat}}), and
|
| 101 |
where the Residual-Leverage plot uses standardized Pearson residuals
|
110 |
where the Residual-Leverage plot uses the standardized Pearson residuals
|
| 102 |
(\code{\link{residuals.glm}(type = "pearson")}) for \eqn{R[i]}.
|
111 |
(\code{\link{residuals.glm}(type = "pearson")}) for \eqn{R[i]}.
|
| 103 |
|
112 |
|
| 104 |
The Residual-Leverage plot shows contours of equal Cook's distance,
|
113 |
The Residual-Leverage plot (\code{which=5}) shows contours of equal Cook's distance,
|
| 105 |
for values of \code{cook.levels} (by default 0.5 and 1) and omits
|
114 |
for values of \code{cook.levels} (by default 0.5 and 1) and omits
|
| 106 |
cases with leverage one with a warning. If the leverages are constant
|
115 |
cases with leverage one with a warning. If the leverages are constant
|
| 107 |
(as is typically the case in a balanced \code{\link{aov}} situation)
|
116 |
(as is typically the case in a balanced \code{\link{aov}} situation)
|
| 108 |
the plot uses factor level combinations instead of the leverages for
|
117 |
the plot uses factor level combinations instead of the leverages for
|
| 109 |
the x-axis. (The factor levels are ordered by mean fitted value.)
|
118 |
the x-axis. (The factor levels are ordered by mean fitted value.)
|
| 110 |
|
119 |
|
| 111 |
In the Cook's distance vs leverage/(1-leverage) plot, contours of
|
120 |
In the Cook's distance vs leverage/(1-leverage) (= \dQuote{leverage*}), contours of
|
| 112 |
standardized residuals (\code{\link{rstandard}(.)}) that are equal in
|
121 |
standardized residuals (\code{\link{rstandard}(.)}) that are equal in
|
| 113 |
magnitude are lines through the origin. The contour lines are
|
122 |
magnitude are lines through the origin. These lines are labelled with
|
| - |
|
123 |
the magnitudes. The x-axis is labeled with the (non equidistant)
|
| 114 |
labelled with the magnitudes.
|
124 |
leverages \eqn{h_{ii}}{h.ii}.
|
| 115 |
|
125 |
|
| 116 |
Notice that some plots may not make much sense for the \code{glm}
|
126 |
Notice that some plots may not make much sense for the \code{glm}
|
| 117 |
case; e.g., the normal Q-Q plot only makes sense if the distribution
|
127 |
case; e.g., the normal Q-Q plot only makes sense if the distribution
|
| 118 |
is approximately normal.
|
128 |
is approximately normal.
|
| 119 |
|
- |
|
| 120 |
}
|
129 |
}
|
| - |
|
130 |
|
| 121 |
\references{
|
131 |
\references{
|
| 122 |
Belsley, D. A., Kuh, E. and Welsch, R. E. (1980).
|
132 |
Belsley, D. A., Kuh, E. and Welsch, R. E. (1980).
|
| 123 |
\emph{Regression Diagnostics}.
|
133 |
\emph{Regression Diagnostics}.
|
| 124 |
New York: Wiley.
|
134 |
New York: Wiley.
|
| 125 |
|
135 |
|