4
$\begingroup$

My model is:

model1 <- glmer(Avg_egg_mass ~ Treatment + Alt_cat + Treatment:Alt_cat + (1|Nest) + (1|Site)+ (1|Year), na.action=na.omit, family = poisson (link=log), data = dframe1)

where I am relating average egg mass (continous variable) to a four group treatment (set to factor) and three categories of altitude (also set to factor).

It doesn't seem to work and I get this error message Error: grouping factors must have > 1 sampled level.

$\endgroup$
4
  • $\begingroup$ If your response is continuous, a Poisson model is mis-specified. $\endgroup$
    – Sycorax
    Sep 23, 2014 at 16:25
  • $\begingroup$ @user777 You would be interested, then, in reading the post at blog.stata.com/tag/poisson-regression explaining how and why such a model can be useful. $\endgroup$
    – whuber
    Sep 23, 2014 at 16:43
  • $\begingroup$ @whuber That post is very interesting, and illustrates a use of Poisson regression I was not aware of. But I can't wrap my mind around something simple: if $P$ is a Poisson PMF, then $P(2.5)=0$. So am I correct that the procedure uses an analogue to the Poisson distribution with support over $\mathbb{R}^+$? $\endgroup$
    – Sycorax
    Sep 23, 2014 at 17:07
  • 1
    $\begingroup$ @user777 Good point. The fitting is done using maximum likelihood. The contribution to the "likelihood" of the parameter $\lambda$ due to any nonnegative integral value $x$ can be rewritten $\exp(-\lambda)\lambda^x/x!=\exp(x\log(\lambda)-\lambda)/\Gamma(x+1),$ which actually is defined for all real (indeed, complex) values of $x$. I believe that is what is used in this generalized application. $\endgroup$
    – whuber
    Sep 23, 2014 at 17:22

1 Answer 1

6
$\begingroup$

What's happening is that your data are cast as factors, but not all levels of that factor appear in your data. So you can't group your data by these non-present factors. You'll either have to use a superset of this data which includes all levels of the factors, or re-level the grouping columns to have levels only for the groups present in the column.

$\endgroup$
6
  • $\begingroup$ Thanks for the fast reply! That makes sense and I have changes my categories for altitude. Instead I now get the warning messages "1: In (function (fr, X, reTrms, family, nAGQ = 1L, verbose = 0L, ... :non-integer x = 4.500000". Could you by any chance explain why this is happening now? Cheers $\endgroup$
    – Aisha
    Sep 27, 2014 at 10:37
  • $\begingroup$ @Aisha I can't say for sure. My advice would be to look at your data and find where the value 4.5 occurs. Wherever it is, the fit procedure doesn't like non-integer values to be there. $\endgroup$
    – Sycorax
    Sep 27, 2014 at 16:09
  • $\begingroup$ The non-integer values issue was actually related to a different model, where I looked at rate of female provisioning per hour in relation to the above variables. I can't really change these values to integers. $\endgroup$
    – Aisha
    Oct 6, 2014 at 10:20
  • $\begingroup$ @Aisha It sounds like you still have some questions. That's fine! If it's a statistics-related question, ask it here. If it's more related to programming, Stack Overflow is the correct place to ask. $\endgroup$
    – Sycorax
    Oct 6, 2014 at 12:30
  • $\begingroup$ Yes, I'm still a little confused. So I get the same integer warning messages in a few of my models. For example when I run this glmer: model1 <- glmer(Avg_egg_mass ~ Treatment + Alt + Treatment:Alt + (1|Obs), family = poisson(link=log), data = dframe1) and the output is: "There were 50 or more warnings (use warnings() to see the first 50) > warnings() Warning messages: 1: In (function (fr, X, reTrms, family, nAGQ = 1L, verbose = 0L, ... :non-integer x = 1.010000" $\endgroup$
    – Aisha
    Oct 9, 2014 at 12:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.