Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using glmer for nested data

Tags:

r

nested

lme4

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!

like image 326
ajpty Avatar asked Oct 16 '13 21:10

ajpty


People also ask

Can fixed effects be nested?

Random effects, like fixed effects, can either be nested or not; it depends on the logic of the design.

What nested random effects?

Nested random effects are when each member of one group is contained entirely within a single unit of another group. The canonical example is students in classrooms; you may have repeated measures per student, but each student belongs to a single classroom (assuming no reassignments).


1 Answers

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.

like image 55
Ben Bolker Avatar answered Sep 21 '22 12:09

Ben Bolker