Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use predict()

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 
like image 802
Roland Kofler Avatar asked Dec 15 '22 14:12

Roland Kofler


1 Answers

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 
like image 125
Didzis Elferts Avatar answered Jan 03 '23 12:01

Didzis Elferts