Mixed Model – Analyzing Mixed Models with Nested and Crossed Random Effects

crossed-random-effectslme4-nlmemixed modelnested dataregression

I'm new to mixed effects models and am trying to use the lmer() function from the lme4 R package to specify a random effects structure.

In my experiment, subjects are spread out over 11 non-overlapping groups. Groups were fairly big (hundreds of subjects) and were tested on at least 4 successive days. On each day, subject performance was measured under two experimental conditions (hungry, satiated) and during each of these conditions, each subject contributed zero to potentially many data points. Groups were tested sequentially, i.e., on each day only one group was tested.

After reading through lectures, tutorials, and posts on here, I think my model should look like this

response_time ~ experimental_condition + (1 | group_id/day) + (1 | subject_id)

and the subject_id needs to be unique across the entire data set.

Does this look okay? And under which (hypothetical) circumstances would one nest experimental_condition within day?

Thanks for any help!

Edit: I should have mentioned that day is currently coded as the day of the experiment. In other words, it is not unique across groups (i.e., there is a day 1, day 2, … for each group).

Best Answer

Does this look okay?

Based on your description, and given your research question of estimating the effect of experimental_condition, while accounting for the non-independence of observations due to the random structure your experiment has, this does not look OK to me. The issue is with the random structure, and how to handle the day variable.

It appears that each and every subject belongs to one and only one group. Thus, subjects are nested within groups, so you need the term:

... + (1 | group_id / subject_id) + ...

which will fit random intercepts for each group and each subject within a group.

This leaves the question of how to treat the day variable: fixed or random. There isn't necessarily a black and white answer to this, but see the list of threads at the end of my answer for help on how to choose. The first thing to note is that day has only 4 levels. This isn't necessarily a problem if day is nested within group_id, since there will then be $n_{day} \times n_{group} = 44$ intercepts.

So, if treating day as random and nested within group we would have:

response_time ~ experimental_condition + (1|group_id/subject_id) + (1|group_id/day)

which expands to

response_time ~ experimental_condition + (1|group_id) + (1|group_id:subject_id) + (1|group_id)+ (1|group_id:day)

which then simplifies to:

response_time ~ experimental_condition + (1|group_id) + (1|group_id:subject_id) + (1|group_id:day)

Alternatively if day is not nested within group we wouldn't fit random intercepts with only 4 levels, so treating day as fixed would make more sense in that scenario:

response_time ~ experimental_condition + day + (1|group_id/subject_id)

In the this latter model you should consider whether to fit an interaction term in the fixed part if the effect of the experimental condition differs by day:

response_time ~ experimental_condition * day + (1|group_id/subject_id)

And under which (hypothetical) circumstances would one nest experimental_condition within day?

Nesting experimental_condition within day makes sense if each experimental_condition belongs to one and only one day. That does not seem to be the case with your design. This would also bring up the problem of whether to fit a factor as random or variable. See the following threads for much discussion on that topic:

What is the difference between fixed effect, random effect and mixed effect models?

How to determine random effects in mixed model

Understanding Random Effects in Linear Mixed Models

Can a variable be included in a mixed model as a fixed effect and as a random effect at the same time?

Choosing Random Effects to Include in a Linear Mixed Model

Related Question