4

Want to predict a value but this is clearly not the solution. I am doing a multiple choice test and 0.304... is not an answer.How to use predict() correctly?

library(glm2)
data(crabs)
fit= glm(Satellites~Width,data=crabs, family="poisson")
plot(Satellites~Width,data=crabs)
abline(fit)
predict(fit, newdata=data.frame(Width=c(22)))
1 
0.3042347 
Roland Kofler
  • 1,332
  • 1
  • 16
  • 33

1 Answers1

12

Function predict() for Poisson regression (for GLM in general) by default will calculate the values on the scale of the linear predictors, i.e. the log scale in this case (see help file for predict.glm).

predict(fit, newdata=data.frame(Width=c(22)))
        1 
0.3042347 

To get the predicted values on the scale of the response variable, you should add argument type="response" to function predict().

predict(fit, newdata=data.frame(Width=c(22)),type="response")
       1 
1.355587 
Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
Didzis Elferts
  • 95,661
  • 14
  • 264
  • 201
  • +1!`preidct` looks sometimes clunky to use! but it is really a great workhorse! – agstudy Feb 19 '13 at 19:10
  • I am not sure what the scale linear predictors have to do with log() though... even more confused. – Roland Kofler Feb 19 '13 at 19:17
  • 4
    You fitted a poisson model. As `?poisson` will tell you, the default link function of the Poisson is the log (that shows up as `poisson(link = "log")` in the help file). "on the scale of the linear predictor" means on the log scale in this context. If this is totally unfamiliar to you, it might be helpful to do some more reading about Poisson GLMs ... – Ben Bolker Feb 19 '13 at 19:19
  • 1
    @Roo, Venables & Ripley's MASS book has an entire chapter explaining this: http://www.amazon.com/Modern-Applied-Statistics-W-N-Venables/dp/0387954570 – Ricardo Saporta Feb 19 '13 at 19:30