GLM, Poisson - non-integer count numbers (average)

Asked

Viewed 305 times

3

I’m doing GLM for frequency data of a behavior x. As I have day 1 and day 2 of observations, I averaged the frequencies of that two days, so my counting data is not integer numbers. However, I am not able to make the models when I use the distribution of Poisson.

How do I fix it?

I’m adjusting model as follows:

al1<-glm(cbind(al)~sp*sexo,poisson(link="log"),data=abfm) 

But I get the following error message:

Warning messages: 
1: In dpois(y, mu, log = TRUE) : non-integer x = 4.500000 
2: In dpois(y, mu, log = TRUE) : non-integer x = 7.500000
  • 2

    You need to go into more detail about your question. Not getting why? Get an error? Your doubt is even of programming, in relation to the code of analysis (or its result), or statistics?

  • Hello Erlon, thank you for your interest. My counting data is not integer numbers because it is averages. So when I do GLM with Poisson distribution, link=log, it gives error. For example: al1<-glm(cbind(al)~sp*sex,Poisson(link="log"),data=abfm) Warning messages: 1: In dpois(y, mu, log = TRUE) : non-integer x = 4,500000 2: In dpois(y, mu, log = TRUE) : non-integer x = 7,500000

  • Bruna, edit these details in the question itself, trying to clarify your problem, as @Molx suggested!

  • I tried to edit the question, but it was rejected. for me, it’s a shame that question is deleted...

  • Was she excluded? I did not delete....

  • @Danielfalbel the question will not be deleted, it is only pending for edits to occur before new answers appear (otherwise it could happen like that other question you answered but the guy was asking something else!). Try to edit again, if it doesn’t work, anything pass me the details of the edition I edit and we vote to reopen the question!

  • @Carloscinelli has now accepted the edition. We will try to reopen?

  • 1

    @Danielfalbel thanks, I voted to reopen, already has 3 votes

Show 3 more comments

1 answer

2

There is no way to use the average of the two observations and at the same time use the Poisson distribution. You might try to figure out what the probability distribution of the average of two Poisson i.i.d random variables is, but I think this is not the best way out.

For me, the best way out would be to use a model of repeated measures, and consider a random effect of individual for each day.

For this, considering that you have a database as follows:

> dados <- data.frame(
+   id = 1:100,
+   explicativa = runif(100, 0, 20)
+   )
> 
> dados$r1 <- rpois(100, dados$explicativa)
> dados$r2 <- rpois(100, dados$explicativa)
> 
> head(dados)
  id explicativa r1 r2
1  1    9.082513 16 14
2  2   17.741123 14 29
3  3   10.819865 13 12
4  4   18.527938 22 25
5  5    4.828392  6  7
6  6   13.986794 14 15 

r1 and r2 are the frequencies observed on day 1 and day 2.

Turn your data into format tidy/long:

library(tidyr);library(dplyr)
dados <- dados %>% gather(dia, resposta, starts_with("r"))

Then adjust a model as follows:

library(lme4)    
modelo <- glmer(resposta ~ explicativa + (0 + dia | id), data = dados, family = poisson)

Thus, you will be considering that for each individual there is a random variation related to the day it is being measured.

  • 1

    Thank you, Daniel. You’ve helped me a lot!

  • Daniel, the package you indicated to me is not available. dplyr package and the argument for tidyr is going wrong. I’ll keep trying....

  • you installed both packages? install.packages("dplyr") and install.packages("tidyr"). then use library(tidyr);library(dplyr)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.