Frage

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 
War es hilfreich?

Lösung

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 
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top