Rspacer
Rspacer

Reputation: 2429

How to extract confidence intervals from a poisson distribution in glm R?

I want to try and predict the confidence intervals for a glm poisson() distribution. I tried to use the predict function to extract the upper and lower limits..but it dosent' appear to work. Any suggestions on what I could change?

temp <- rnorm(100,20,2)
plant <- rnorm(100,5,1.5)
df <- data.frame(temp, plant)
mod <- glm(plant~temp + I(temp^2), df, family = poisson)
predicted.plant <- predict(mod, type = "response")
predict(predicted.plant, interval="confidence", level=.95)

Upvotes: 2

Views: 1098

Answers (1)

Otto K&#228;ssi
Otto K&#228;ssi

Reputation: 3083

investr::predFit provides these out of the box.

library(investr)    
predFit(mod, interval='confidence', level=.95)

         fit       lwr      upr
1   1.385749 0.8536210 1.917877
2   1.595374 1.4652265 1.725522
3   1.578423 1.4590180 1.697828
4   1.616518 1.5044858 1.728551
5   1.607251 1.4874250 1.727076
6   1.614135 1.4987750 1.729494
7   1.613123 1.5045601 1.721687
8   1.608245 1.4891049 1.727384
9   1.608494 1.5017123 1.715275
10  1.605561 1.4845113 1.726612

Upvotes: 1

Related Questions