I ran an experiment where subjects exercised in different climatic conditions. The response variable is the subjects' internal (core) temperatures.

There were 30 subjects and some participated in more than one trial. Each trial had a different ambient temperature, relative humidity, etc. Because of the non-independence of some of the subjects' data due to participating more than once, I decided to use a linear mixed effects model with Subject as the random effect. I also think I need to nest Subject within Trial due to the fact that different climatic conditions effect the subjects' temperatures.

The response variable is the subjects' temperatures and the fixed effects are the subjects' mass, age, and body fat percentage.

Here is my model, in package lme4 in R:

>mod=lmer(Temp ~ Mass + Age + Fat + (1|Subject/Trial), data=data, REML=FALSE)

I get the error:

Error: number of levels of each grouping factor must be < number of observations

I have 43 observations and 6 different trials. Does this mean I just didn't collect enough data to be able to fit this model? Or is there another explanation/anything I can do?

  • $\begingroup$ Please check the GLMM FAQ page. As I interpret the section on Model Specification, it looks like you have Trials nested within Subjects, not Subjects within Trials. Don't know whether that will solve your problem. $\endgroup$ – EdM Jan 25 '20 at 17:58
  • $\begingroup$ Thank you, you are absolutely correct! Unfortunately it doesn't fix the problem. $\endgroup$ – J. E. Jan 27 '20 at 10:21
  • $\begingroup$ That's what I suspected. With some Subjects restricted to only 1 trial there is no way to parcel out the within-Trial Subject random effects from the between-Trial random effects as your nested model would require. If the updated answer from @ErikRuzek suggesting crossed random effects provides the solution, please accept that answer. Note that with only 6 Trials you might treat Trial as a fixed effect instead, as that's on the borderline of where many make the choice between fixed and random modeling. $\endgroup$ – EdM Jan 27 '20 at 14:51

Welcome to the site, J.E. Without looking at your data, I am a little unclear about the trial variable. Given EdM's comment and a closer reading of your post, I want to make sure that I understand this correctly. Trials involved different conditions. So for some (but not all) subjects they had exposure to different trials. This to me sounds like a cross-classified problem rather than a purely nested trial. This would mean that your syntax should shift to the following:

mod <- lmer(Temp ~ Mass + Age + Fat + (1|Subject) + (1|Trial), data=data)

If you have coded your data so that trial 1 is the same condition across subjects (i.e., it represents the same combination of ambient temp and relative humidity) and similarly trial 2 represents the same combination of conditions, etc., then this model syntax will be right whether your data are indeed purely nested or cross-classified. Make sure and check the summary(mod) output where it tells you the Ns in each grouping. If it is off, then check your coding of trial to make sure that trials with the same conditions are consistent across individuals. With 30 subjects and the relative small number of data points, you should use REML, which has better properties than full maximum likelihood with small samples.

  • $\begingroup$ The question specifies 30 subjects (start of second paragraph), with some but not all participating in more than 1 trial (second paragraph, 3rd sentence). There are apparently only 43 observations in total (last paragraph), so no more than 13 of the subjects could have been in even 2 of the 6 trials. Also, the question specifies that the intent was to nest subjects within trials (last sentence, second paragraph). $\endgroup$ – EdM Jan 25 '20 at 20:40
  • 1
    $\begingroup$ Thanks, EdM, for the clarifications. I edited the post accordingly. $\endgroup$ – Erik Ruzek Jan 25 '20 at 21:06
  • $\begingroup$ Thank you very much. I 've done a lot of reading on crossed vs. nested random effects since I saw your comment, and I think you are correct - the model should have crossed random effects. $\endgroup$ – J. E. Jan 27 '20 at 10:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.