Reputation: 61
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:
count density
: numericyear
: categorical, two levelsround
: categorical (each year has its own six rounds, so round is - nested in year)monitoring site
: categorical (data is measured on each monitoring site 6 times a year, so round is crossed with monitoring site)waters
: categorical (each waters has several different sites, so monitoring site is nested in waters)material
: categoricalI 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
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