Learn R Programming

alr3 (version 1.1.12)

residual.plots: Residual plots and curvature tests for linear model fits

Description

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.

Usage

### This is a generic function with only one required argument:

residual.plots (m, ...)

### When the first argument is a linear model (of class lm), the form of the
### function is

## S3 method for class 'lm':
residual.plots(m,vars=~.,fitted=TRUE,plot=TRUE,
     layout=NULL,ask,...)

### The following are three related functions:    

resplot(m,varname="tukey",type="pearson",
                    plot=TRUE,add.quadratic=TRUE,
                    ylab=paste(string.capitalize(type),"Residuals"),...)
                    
resid.curv.test(m,varname)

tukey.nonadd.test(m)

Arguments

m
lm regression object
vars
A one-sided formula that specifies a subset of the predictors. One residual plot is drawn for each column specified. The default ~. is to plot against all predictors. For example, the specification vars = ~.-X3 would
fitted
If TRUE, the default, plot against fitted values.
tukey
If TRUE, draw plot of residuals versus fitted values and compute Tukey's test of non-additivity.
layout
If set to a value like c(1,1) or c(4,3), the layout of the graph will have this many rows and columns. If not set, the program will select an appropriate layout. If the number of graphs exceed nine, you must select th
ask
If TRUE, ask the user before drawing the next plot; FALSE if don't ask.
...
residual.plots passes these arguments to resplot. resplot passes them to plot.
varname
Quoted variable name for the horizontal axis, "tukey" by default for Tukey's test and the plot versus fitted values.
type
Type of residuals to be used. Pearson residuals are appropriate for lm objects since there are equivalent to ordinary residuals with ols and correctly weighted residuals with wls.
ylab
Label for the yaxis. The default is the residual type.
add.quadratic
if TRUE, fits the quadratic regression of the vertical axis on the horizontal axis.
plot
If TRUE, draw the plot(s).

Value

  • 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.

Details

residual.plots draws all residuals plots, versus each term specified first-order term in the model (interactions are automatically skipped) and versus fitted values, and returns all the curvature tests. resplot, which is called by residual.plots, should be viewed as an internal function, and is included here to display its arguments, which can be used with residual.plots as well. resid.curv.test computes the curvature test only. For any factors a boxplot will be drawn.

References

S. Weisberg (2005), Applied Linear Regression, third edition, Wiley, Chapter 8

See Also

See Also lm

Examples

Run this code
data(highway)
highway$Sigs <- (round(highway$Sigs*highway$Len)+1)/highway$Len
attach(highway)
d <- data.frame(Rate=Rate,logLen=logb(Len,2),
                logADT=logb(ADT,2),logTrks=logb(Trks,2),
                Slim=Slim,Shld=Shld,logSigs1=logb(Sigs,2))
attach(d)
m2 <- lm(Rate~logLen+logADT+logTrks+Slim+Shld+logSigs1,d)
residual.plots(m2)

Run the code above in your browser using DataLab