ajpty
ajpty

Reputation: 81

using glmer for nested data

I have data on the diversity of pathogens infecting a particular host species across latitudes. The design involved collecting 20 individuals at 3 sites within 4 locations of different latitudes, therefore I have 20 individuals, nested within 3 sites, nested within 4 locations.

Given that my pathogen diversity data is count data with many zeros, which is why I have been exploring using using a GLMM with the lme4::glmer command in R to analyze the data. For the analysis I want to treat latitude as a numeric fixed factor and site as a random factor nested with location.

For my full model I have set up my command as follows:

glmer(pathogen.richness~latitude+(site|location),data=my.data,
      family="poisson")

Is this the correct syntax for what I described?

Thanks!

Upvotes: 7

Views: 14618

Answers (1)

Ben Bolker
Ben Bolker

Reputation: 226761

You probably want

glmer(pathogen.richness~latitude+(1|location/site),
     data=my.data,family="poisson")

However, you're probably going to run into problems trying to fit a random effect of location to only 4 locations, so you may prefer

glmer(pathogen.richness~latitude+location+(1|location:site),
     data=my.data,family="poisson")

(even though location is conceptually a random effect, it may be more practical to fit it as a fixed effect).

Don't forget to check for overdispersion; one way to handle this is to add an observation-level random effect:

transform(my.data,obs=factor(seq(nrow(mydata)))
update(prev_model,.~.+(1|obs))

See the GLMM FAQ and http://glmm.wdfiles.com/local--files/examples/Banta_2011_part1.pdf for more information.

Upvotes: 13

Related Questions