9
$\begingroup$

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

$\endgroup$
2
  • $\begingroup$ 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? $\endgroup$ Commented Dec 15, 2012 at 16:55
  • $\begingroup$ Faraway's Extending the linear model (...) has some GLM diagnostics in 6.4 (page 135). $\endgroup$ Commented Dec 16, 2012 at 10:00

1 Answer 1

11
$\begingroup$

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

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())
summary(glm.D93)
# In the following, resid(glm.D93) extracts residuals of the fitted model glm.D93 
SSE=sum(resid(glm.D93))^2
SSE
[1] 0.04638682
$\endgroup$
1
  • $\begingroup$ is there a faster way instead of this leuk.diag <- glm.diag(leuk.mod) it is taking for ever with my data to execute. $\endgroup$ Commented Dec 19, 2012 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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