Reputation: 1459
I am using a binomial GLMM to examine the relationship between presence of individuals (# hours/day) at a site over time. Since presence is measured daily for several individuals, I've included a random intercept for individual ID.
e.g.,
presence <- cbind(hours, 24-hours)
glmer(presence ~ time + (1 | ID), family = binomial)
I'd like to also look at using ID as a random slope, but I don't know how to add this to my model. I've tried the two different approaches below, but I'm not sure which is correct.
glmer(presence ~ time + (1 + ID), family = binomial)
Error: No random effects terms specified in formula
glmer(presence ~ time + (1 + ID | ID), family = binomial)
Error: number of observations (=1639) < number of random effects (=5476) for term (1 + ID | ID); the random-effects parameters are probably unidentifiable
Upvotes: 0
Views: 2386
Reputation: 735
You cannot have a random slope for ID
and have ID
as a (level-two) grouping variable (see this documentation for more detail: https://cran.r-project.org/web/packages/lme4/lme4.pdf).
The grouping variable, which is ID
in the models below, is used as a variable for which to specify random effects. model_1
gives random intercepts for the ID
variable. model_2
gives both random intercepts and random slopes for the time
variable. In other words, model_1
allows the intercept of the relationship between presence
and time
to vary with ID
(the slope remains the same), whereas model_2
allows for the both the intercept and slopes to vary with ID
, so that the relationship between presence
and time
(i.e., the slope) can be different for each individual (ID
).
model_1 = glmer(presence ~ time + (1 | ID), family = binomial)
model_2 = glmer(presence ~ time + (1 + time | ID), family = binomial)
I would also recommend:
Snijders, T. A. B., & Bosker, R. J. (2012). Multilevel analysis: an introduction to basic and advanced multilevel modeling (2nd ed.): Sage.
Upvotes: 3