# Error with numeric class in GLM with Poisson distribution [duplicate]

I am trying to run a GLM with a Poisson distribution. All my variables Y and X belong to the numeric class. When I run the GLM I always see this warning:

There were 50 or more warnings (use warnings() to see the first 50)

with this content:

1: In dpois(y, mu, log = TRUE) : non-integer x = 45.084920

2: In dpois(y, mu, log = TRUE) : non-integer x = 5.113924

3: In dpois(y, mu, log = TRUE) : non-integer x = 52.057026

4: In dpois(y, mu, log = TRUE) : non-integer x = 1.196172

5: In dpois(y, mu, log = TRUE) : non-integer x = 22.456140

6: In dpois(y, mu, log = TRUE) : non-integer x = 0.741133

7: In dpois(y, mu, log = TRUE) : non-integer x = 54.296875

8: In dpois(y, mu, log = TRUE) : non-integer x = 8.907789

9: In dpois(y, mu, log = TRUE) : non-integer x = 13.480779

...


If I turn my variables from numeric to integer the alarm no longer appears, but I noticed that in this way all the data is rounded to integer values. In this case, my data would lose a lot of information and so I would run a GLM with the original data in numeric class. However, if I try to run a GLM with numerical data and a GLM with integer data, I have two different outputs. I also tried to change the data by multiplying everything by 10^4, in this way I have all integer data without losing information: the result was a third different output.

This is data from a behavioral experiment on some kind of bird. My dataset consists of morphological variables (weight, tarsal length, wing length, staining, etc) and behavioural variables (number of attacks/minute, number of pecks/minute, percentage of seconds in which the individual remains in a given area, etc.). In particular, the morphological variables are X and the behavioral variables are Y. In this case, I want to see if the most aggressive individuals are also those with the best ornaments: for example, I want to see if the number of attacks/minute (Y) depends on staining (X)

Being biological data, it is important that they are used in original format, not rounded. I tried running a Shapiro Wilk test to see if my data has a normal distribution and also to transform it with logarithm, but in both cases the distribution was not normal. So when I ran a histogram, I realized that their distribution was very close to that of Poisson. How can I solve this problem? Thank you in advance

• can you be more specific in your question and provide an example of what is your X or Y instead of just showing an histogram which interpretation is hard because we don't know how it is plotted Nov 4, 2020 at 20:03
• for example, if your response variable (Y) is continuous, what is it exactly and why do you want to use a poisson? Poisson is meant for rate or count data Nov 4, 2020 at 20:03
• Ok, I changed the question, I hope I was more specific Nov 4, 2020 at 20:27
• you need to use an offset. see stats.stackexchange.com/questions/232666/… Nov 4, 2020 at 20:42
• @StupidWolf, is that close enough to use as a duplicate? Nov 4, 2020 at 22:52

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.

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


The Poisson describes the distribution of zero or positive integer values but it appears you are trying to model a continuous response variable.

What is the reason to chose Poisson? An alternative may be the Gamma distribution which is defined for zero or positive continuous data.

It's hard to tell what's best without seeing the data and the purpose of the analysis.

• The data is biological data, and I want to use a GLM to see if there are correlations between variables. Being biological data, it is important that they are used in original format, not rounded. I tried running a Shapiro Wilk test to see if my data has a normal distribution and also to transform it with logarithm, but in both cases the distribution was not normal. So when I ran a histogram, I realized that their distribution was very close to that of Poisson. Nov 4, 2020 at 19:57
• This isn't an answer. It's an attempt to engage w/ the OP & clarify the situation / question. This is a good thing to do, but it should be done via comments. tl/dr: this should have been a comment. Nov 4, 2020 at 21:02
• @gung My impression is the same, but I understand the passage about the Gamma distribution to be a positive contribution and believe it can reasonably be construed as an answer. Some elaboration of that point would be helpful, though.
– whuber
Nov 4, 2020 at 21:14