A. Caikov
A. Caikov

Reputation: 61

How to run a generalized linear mixed model (GLMM) with multiple random factors?

I would like to run a GLMM with multiple random factors using the function glmer in package lme4.

I have a dataset on marine debris like this:

I would like to know if the count densities of marine debris is significantly different between/among years, rounds, waters and materials. So I put-in this:

glmm <- glmer(count density~material*(1|year/round)*(1|waters/monitoring sites),
    family=Poisson)

Could you please let me know if my formula is right?

And I can get nothing from the model, as I typed in:

glmm

It said:

Error: object 'glmm' not found

So what's the right way to use glmer?

Upvotes: 0

Views: 2178

Answers (1)

Ben Bolker
Ben Bolker

Reputation: 226027

At the very least (if your variable names really have spaces in them, which is generally a bad idea, see e.g. this question) you should try:

glmm <- glmer(`count density` ~ material+(1|year/round)+
              (1|waters/`monitoring sites`), 
              family=poisson)

Also note that year won't work well as a random effect because it only has two levels (it's hard to estimate a variance from only two observations: see e.g. these simulations), so maybe

glmm <- glmer(`count density` ~ material+year+(1|year:round)+
               (1|waters/`monitoring sites`), 
              family=poisson)

would be better.

Upvotes: 1

Related Questions