residualPlots {car} | R Documentation |
Plots the residuals versus each term in a mean function and versus fitted values. Also computes a curvature test for each of the plots by adding a quadratic term and testing the quadratic to be zero. This is Tukey's test for nonadditivity when plotting against fitted values.
### This is a generic function with only one required argument: residualPlots (model, ...) ## Default S3 method: residualPlots(model, terms = ~., layout = NULL, ask, main = "", fitted = TRUE, AsIs=TRUE, plot = TRUE, tests = TRUE, ...) ## S3 method for class 'lm' residualPlots(model, ...) ## S3 method for class 'glm' residualPlots(model, ...) ### residualPlots calls residualPlot, so these arguments can be ### used with either function residualPlot(model, ...) ## Default S3 method: residualPlot(model, variable = "fitted", type = "pearson", plot = TRUE, quadratic = TRUE, smooth = FALSE, span = 1/2, smooth.lwd=lwd, smooth.lty=lty, smooth.col=col.lines, labels, id.method = "y", id.n = if(id.method[1]=="identify") Inf else 0, id.cex=1, id.col=palette()[1], col = palette()[1], col.lines = palette()[2], xlab, ylab, lwd = 1, lty=1, grid=TRUE, ...) ## S3 method for class 'lm' residualPlot(model, ...) ## S3 method for class 'glm' residualPlot(model, variable = "fitted", type = "pearson", plot = TRUE, quadratic = FALSE, smooth = TRUE, ...)
model |
A regression object. |
terms |
A one-sided formula that specifies a subset of the predictors. One
residual plot is drawn for each specified. The default
|
layout |
If set to a value like |
ask |
If |
main |
Main title for the graphs. The default is |
fitted |
If |
AsIs |
If |
plot |
If |
tests |
If |
... |
Additional arguments passed to |
variable |
Quoted variable name for the horizontal axis, or
|
type |
Type of residuals to be used. Pearson residuals are
appropriate for |
quadratic |
if |
smooth |
if TRUE fits a loess smooth using the settings given below. Defaults to FALSE for lm objects and TRUE for glm objects. |
span, smooth.lwd, smooth.lty, smooth.col |
Should a lowess smooth be added to the figure? The |
id.method,labels,id.n,id.cex,id.col |
Arguments for the labelling of
points. The default is |
col |
default color for points |
col.lines |
default color for lines |
xlab |
X-axis label. If not specified, a useful label is constructed by the function. |
ylab |
Y-axis label. If not specified, a useful label is constructed by the function. |
lwd |
line width for lines. |
lty |
line type for quadratic. |
grid |
If TRUE, the default, a light-gray background grid is put on the graph |
residualPlots
draws one or more residuals plots depending on the
value of the terms
and fitted
arguments. If terms = ~ .
,
the default, then a plot is produced of residuals versus each first-order
term in the formula used to create the model. Interaction terms, spline terms,
and polynomial terms of more than one predictor are
skipped. In addition terms that use the “as-is” function, e.g., I(X^2)
,
will also be skipped unless you set the argument AsIs=TRUE
. A plot of
residuals versus fitted values is also included unless fitted=FALSE
.
In addition to plots, a table of curvature tests is displayed. For plots
against a term in the model formula, say X1
, the test displayed is
the t-test for for I(X^2)
in the fit of update, model, ~. + I(X^2))
.
Econometricians call this a specification test. For factors, the displayed
plot is a boxplot, and no curvature test is computed.
For fitted values, the test is Tukey's one-degree-of-freedom test for
nonadditivity. You can suppress the tests with the argument tests=FALSE
.
residualPlot
, which is called by residualPlots
,
should be viewed as an internal function, and is included here to display its
arguments, which can be used with residualPlots
as well. The
residualPlot
function returns the curvature test as an invisible result.
residCurvTest
computes the curvature test only. For any factors a
boxplot will be drawn. For any polynomials, plots are against the linear term.
Other non-standard predictors like B-splines are skipped.
For lm
objects,
returns a data.frame with one row for each plot drawn, one column for
the curvature test statistic, and a second column for the corresponding
p-value. This function is used primarily for its side effect of drawing
residual plots.
Sanford Weisberg, sandy@stat.umn.edu
Fox, J. and Weisberg, S. (2011) An R Companion to Applied Regression, Second Edition. Sage.
Weisberg, S. (2005) Applied Linear Regression, Third Edition, Wiley, Chapter 8
See Also lm
, identify
,
showLabels
residualPlots(lm(longley))