# lme4 - correct formula for a crossed factor nested mixed model

I am having a little trouble verifying correct notation for a crossed factor nested mixed model anova using lme4 package in R. My data is experimental, I applied two crossed treatments (light and nutrients) and measured growth of algal cultures, and did so during 3 separate months. I would like to specify in the model that the light and nutrient factors are nested within month. This is not a three way crossed design because the algal communities were different each month. I'm considering month to be a fixed factor because it is temporally dependent, but light and nutrient application as random because high and low light or nutrient levels can be generalized to a broader range of natural conditions (although I know arguments could be made for the opposite).

Using lme4, my model for crossed random effects looks like this, although I'm not certain that this is the appropriate way to specify that nutrients and light are nested within Month:

lmer(growth.day ~ (1|Light:Nutrients) +
(Month / Light:Nutrients), growth.dat)


something doesn't seem right in output. I've considered using aov(), as follows, but I am not sure that notation is correct in describing Month as fixed and Light * Nutrients as random:

aov(growth.day ~ Error(Light * Nutrients) +
(Month / (Light * Nutrients)), growth.dat)


It makes very little sense to me to treat Month as fixed, while also having Light and Nutrients nested within it. Either you should treat Month and fixed and Light, in which case the random part of the formula will be:

( 1| Month) + (1 | Light)


... Or you treat Month as random, in which case you have Light nested within Month, so this would imply:

(1 | month) + (1| Month:Light)


and you also have Nutrients nested within Month, so this would imply:

(1 | month) + (1| Month:Nutrients)


So combining these we arrive at

(1 | month) + (1| Month:Light) + (1| Month:Nutrients)


Edit:

To address the concern in the comment:

The singular fit implies that at least one of those random factors may not be needed.

As for the extra interaction term, between Light and Nutrients, you could add a further random factor for that. However whether that would be useful depends on what exactly you mean by "a key interest". Modelling it as random will only result in an estimate for it's variance. If you are interested in the fixed effect of that interaction, that implies that they should be fixed factors and not random at all. This would then leave only Month as the random factor in the model, which could very well be appropriate. In conjuntion with this, and on re-reading the question, where you say that Light and Nutrients are "treatments", this usually means you should model them as fixed. Just because these factors can be thought of as a sample from a larger population does not mean they have to be random. Moreover I don't know how many levels of these factors you used ? If there are a large number then modelling them as random may indeed be better. But if they are few, perhaps a more appropriate model is:

lmer(growth.day ~  Light * Nutrients) + ( 1 | Month), ... )

• Thank you. The notation for having light and nutrients nested within Month makes perfect sense. However, if I run this model, I receive a warning: boundary (singular) fit: ... which I have read can be a problem when models are overfit or have many random effects. Also, the model does not test the interaction between Light and Nutrients, which is a key interest (see the aov model, above). I am not particularly interested in 'Month' as a factor in the model, other than to specify that effects of nutrients*light are nested within that grouping factor. Thanks again! – Rose Feb 7 at 2:58
• @Rose You are welcome. I have updated my answer in response. – Robert Long Feb 7 at 8:02
• Great, Thanks for these additional insights! This is very helpful to someone learning about mixed effects models and R notation at the same time. – Rose Feb 7 at 23:23