# How to validate & diagnose a gamma GLM in R?

I am fitting a generalized linear model in R with the log link and I need to validate and diagnose my model. I have never worked with the GLM in the past.

• Is there an article or any references I can look for that would help me learn how to diagnose the model?
• Does anyone have any tips for me on how to do this or even just how to get started?
• What is the difference between the deviance and $r^2$?
• Can we calculate the SS error in the GLM?

(The best way for me to understand is to give formulas and explain what they are used for.)

-
Just out of curiosity, why are you using gamma? (It's a less frequently used model.) Can you say a little about your situation, data, and goals? Also, is there something specific that you are worried about (do you think there may be a certain problem w/ your model), or are you just wanting to do your due diligence? – gung Dec 15 '12 at 16:55
Faraway's Extending the linear model (...) has some GLM diagnostics in 6.4 (page 135). – Roman Luštrik Dec 16 '12 at 10:00

-Look at Chapter 6 or Section 6.3.4 in the book "Statistical Models in S" by Chambers and Hastie. Also you many want to check the package boot and function "glm.diag.plots" (Diagnostics plots for generalized linear models). Here are some code with gamma family and the plots from the help file.

library(boot)
data(leuk, package = "MASS")
leuk.mod <- glm(time ~ ag-1+log10(wbc), family = Gamma(log), data = leuk)
leuk.diag <- glm.diag(leuk.mod)
glm.diag.plots(leuk.mod, leuk.diag)


These plots are (upper left: residual vs linear predictor, upper right: normal scores plots of standardized deviance residuals, Lower left: approximate Cook statistics against leverage, Lower right: the plot of Cook statistic)
- See Introduction to Generalized Linear Models
- Have a look at the above reference, pages 42 and 44 to see the difference of deviance and $r^2$.
- The following code shows how to find SSE (but normally you don't need it!)

#Create a data set
counts <- c(18,17,15,20,10,20,25,13,12)
outcome <- gl(3,1,9)
treatment <- gl(3,3)