Skip to main content
added 3 characters in body
Source Link
StupidWolf
  • 5.2k
  • 3
  • 14
  • 28

You have that error because the response or dependent variable for a poisson regression should be counts. The independent variables need not be counts. Based on what you have described, most of your dependent variables are rates, and you usedcan use an offset, like discussed in this post.

You have that error because the response or dependent variable for a poisson regression should be counts. The independent variables need not be counts. Based on what you have described, most of your dependent variables are rates, and you used an offset, like discussed in this post.

You have that error because the response or dependent variable for a poisson regression should be counts. The independent variables need not be counts. Based on what you have described, most of your dependent variables are rates, and you can use an offset, like discussed in this post.

Source Link
StupidWolf
  • 5.2k
  • 3
  • 14
  • 28

You have that error because the response or dependent variable for a poisson regression should be counts. The independent variables need not be counts. Based on what you have described, most of your dependent variables are rates, and you used an offset, like discussed in this post.

Since you did not provide the data, I use an example data set from MASS,

data = MASS::Insurance

In this data, we want to regress the the rate of claims:

head(data)
  District  Group   Age Holders Claims
1        1    <1l   <25     197     38
2        1    <1l 25-29     264     35
3        1    <1l 30-35     246     20
4        1    <1l   >35    1680    156
5        1 1-1.5l   <25     284     63
6        1 1-1.5l 25-29     536     84

So we can do, with the denominater of rate being placed into offset=log(..):

fit = glm(Claims ~ Age+Group, data=data,offset=log(Holders),family="poisson")

summary(fit)

Call:
glm(formula = Claims ~ Age + Group, family = "poisson", data = data, 
    offset = log(Holders))

Deviance Residuals: 
     Min        1Q    Median        3Q       Max  
-2.61407  -0.59513  -0.07229   0.78529   2.71480  

Coefficients:
             Estimate Std. Error z value Pr(>|z|)    
(Intercept) -1.776382   0.026812 -66.253  < 2e-16 ***
Age.L       -0.387021   0.049262  -7.856 3.95e-15 ***
Age.Q       -0.001336   0.048914  -0.027    0.978    
Age.C       -0.017155   0.048476  -0.354    0.723    
Group.L      0.433991   0.049428   8.780  < 2e-16 ***

If you calculate the rate first, and regress that you get an error:

data$claim_rate = data$Claim/data$Holder
glm(claim_rate ~ Age+Group, data=data,offset=log(Holders),family="poisson")

warnings()
Warning messages:
1: In dpois(y, mu, log = TRUE) : non-integer x = 0.192893
2: In dpois(y, mu, log = TRUE) : non-integer x = 0.132576