How to use pred ()
You want to predict the value, but this is clearly not a solution. I am doing a multiple choice test and 0.304 ... is not the answer. How to use the predictive function () 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
+3
source to share
1 answer
The function predict()
for Poisson regression (for GLM in general) will by default calculate values ββon the scale of linear predictors, i.e. the scale of the log in this case (see the help file for predict.glm
).
predict(fit, newdata=data.frame(Width=c(22)))
1
0.3042347
To get the predicted values ββat the scale of the response variable, you must add an argument type="response"
to the function predict()
.
predict(fit, newdata=data.frame(Width=c(22)),type="response")
1
1.355587
+12
source to share