For decades, the standard diagnostic plots provided by plot.lm
included a normal QQ-plot, which likely—at least in part—prompted this question.
Interestingly, as of R version 4.3.0 (released Apil 2023), plot.lm
has been updated for GLMs:
The plot.lm() function no longer produces a normal Q-Q plot for GLMs. Instead it plots a half-normal Q-Q plot of the absolute value of the standardized deviance residuals.
Now, if you use plot
on a model fit with glm
, it returns the following four plots:
set.seed(2024)
n <- 100
x <- runif(n)
y <- rpois(n, exp(x))
DF <- data.frame(x, y)
GLM <- glm(y ~ x, family = "poisson", data = DF)
par(mfrow = c(2, 2))
plot(GLM)
par(mfrow = c(1, 1))
As you can see, this is still not great, as the model's assumptions perfectly hold, and yet a pattern appears in the QQ-plot... However, it might be useful to know that what appears in many videos, lecture slides, textbooks, and other places on this website, is now outdated.
I am a big fan of @FlorianHartig's package (+1) and recommend any future readers to use that. For non-R users, the package is based on randomized quantile residuals, which is fairly easy to implement and only requires you have a function for the cumulative distribution function and the quantile function.
Dunn, P. K., & Smyth, G. K. (1996). Randomized Quantile Residuals. Journal of Computational and Graphical Statistics, 5(3), 236–244. https://doi.org/10.1080/10618600.1996.10474708