Testing Linearity with Residuals

Stat 203 Lecture 10

Author

Dr. Janssen

Residual Plots

Linearity: plot residuals against \(x_j\)

When considering the linearity assumption in an exploratory data analysis, we typically plot the response variable against each explanatory variable. But such a plot is not sophisticated enough to detect competing effects of multiple explanatory variables.

On the other hand, a plot of residuals against a covariate \(x_j\) can more easily detect deviations from linearity, as the linear effects of all explanatory variables have been removed. If the model fits well, the residuals should show no pattern. If a systematic trend exists in the residuals, we may need to transform the covariate or include extra terms in the model.

Example 1 We’ll use scatter.smooth() in place of plot() to add a smoothing curve and make it easier to see trends.

library(GLMsData); data(lungcap);
lungcap$Smoke <- factor(lungcap$Smoke,
                         levels=c(0, 1),
                         labels=c("Non-smoker","Smoker"))
LC.lm <- lm( FEV ~ Ht + Gender + Smoke, data=lungcap)
scatter.smooth (rstandard( LC.lm ) ~ lungcap$Ht, col="grey", las=1, ylab="Standardized residuals", xlab="Height (inches)")