Cross Validated is a question and answer site for people interested in statistics, machine learning, data analysis, data mining, and data visualization. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
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.

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)

enter image description here
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)
print(d.AD <- data.frame(treatment, outcome, counts))
#Fitting poisson GLM
glm.D93 <- glm(counts ~ outcome + treatment, family=poisson())
# In the following, resid(glm.D93) extracts residuals of the fitted model glm.D93 
[1] 0.04638682
share|improve this answer
is there a faster way instead of this leuk.diag <- glm.diag(leuk.mod) it is taking for ever with my data to execute. – user1834300 Dec 19 '12 at 15:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.