I started digging a bit into the plot.lm function, this function gives six plots for lm, they are:
- a plot of residuals against fitted values
- a Scale-Location plot of sqrt(| residuals |) against fitted values
- a Normal Q-Q plot, a plot of Cook's distances versus row labels
- a plot of residuals against leverages
- a plot of Cook's distances against leverage/(1-leverage)
And I am wondering what other common/useful extensions of current plots exists for linear models, and how can they be done in R? (links to articles of packages are also welcomed)
So the boxcox function (from {MASS}) is an example of another useful diagnostic plot (and such an answer would be great), however, I am more curious about variations/extensions on existing default diagnostic plots for lm in R (although general other remarks on the topic are always welcomed).
Here are some simple examples of what I mean:
#Some example code for all of us to refer to
set.seed(2542)
x1 <- rnorm(100)
x2 <- runif(100, -2,2)
eps <- rnorm(100,0,2)
y <- 1 + 2*x1 + 3*x2 + eps
y[1:4] <- 14 # adding some contaminated points
fit <- lm(y~x1+x2)
#plot(y~x1+x2)
#summary(fit)
To plot the residuals vs each of the potential x
plot(resid(fit)~x1); abline (h = 0)
plot(resid(fit)~x2); abline (h = 0)
# plot(resid(fit)~x1+x2) # you can also use this, but then you wouldn't be able to use the abline on any plot but the last one
To add the the 0-1 line (how is this line called in English?!) to the qqplot so to see how much the qqline deviates from it
plot(fit, which = 2); abline(0,1, col = "green")
To plot the qq-plot using externally studentized residuals
# plot(fit, which = 2); abline(0,1, col = "green") # The next command is just like this one
qqnorm(rstandard(fit), ylim = c(-2.2,4.2)); qqline(rstudent(fit), lty = 2) ;abline(0,1, col = "green")
qqnorm(rstudent(fit), ylim = c(-2.2,4.2)); qqline(rstudent(fit), lty = 2) ;abline(0,1, col = "green")
# We can note how the "bad" points are more extreme when using the rstudent