I've got a problem while trying to specify the 'right' nesting of the random effects of my dataset. The dataset registers hourly variations in temperature inside termite mounds:
- Sampling was performed in four localities, differing in soil composition.
- On each locality, ~20 termite mounds were sampled.
- The temperature of each termite mound was registered every hour during a day.
So, 24 data, per mound, in four localities. According to this previous question, to study how temperatures changes within mounds and among localities, I drew my model as:
Tmodel <- lmer(Temperature ~ Hour + Locality + (1|Locality/Mound/Hour), Tver, REML=FALSE)
and I got this message:
Error in checkNlevels(reTrms$flist, n = n, control) :
number of levels of each grouping factor must be < number of observations
From this message, I get that I'm sort of 'constraining' my data, so that per grouping factor (hour, in mound, in locality), there is just one observation; am I right? But then, how should I specify the nestedness of my random factors?
Temperature ~ Hour + Locality + (1|Mound). This formula assumes thatMoundis coded such that mounds from different localities have different ids. If this is not the case (e.g. you have mounds 1 to 20 in locality #1 and then again mounds 1 to 20 in locality #2), then you should useTemperature ~ Hour + Locality + (1|Locality:Mound). – amoeba Jun 14 '17 at 20:52Hourvia polynomials or splines, taking its circular nature into account, but this is another issue.) – amoeba Jun 14 '17 at 20:56sleepstudydata days are NOT nested in subjects (and I don't think your link says it); days are repeated measures within subjects. But you are right that it's similar to your situation. So you can use either (1|Mound) or (Hour|Mound); the first option is random intercept, the second is random intercept and "slope". It's fine to use random slopes, but I would a bit worried that it might not work in your case, because yourHouris categorical variable with 24 levels, so (Hour|Mound) would estimate 24 variance parameters and [cont.] – amoeba Jun 15 '17 at 11:49Daysis a continuous variable so (Days|Subject) estimates only one random intercept, one random slope, and one correlation between them. – amoeba Jun 15 '17 at 11:50