Hi everyone: I'm hoping for help analyzing nested data in R. I measured the mass of chicks at 3 time points; chicks were in one of two treatments (P and W) and in one of two environmental conditions (Wet or Dry). I have measurements from multiple chicks per (literal) nest.

Here's what the data look like: chick nest visit treatment condition mass 1 a 1 1 P dry 4.5 2 a 1 2 P dry 17.2 3 a 1 3 P dry 32.4 4 b 1 1 P dry 4.2 5 b 1 2 P dry 18.0 6 b 1 3 P dry 30.2 7 c 2 1 P dry 5.2 8 c 2 2 P dry 18.3 9 c 2 3 P dry 31.0

And here's what the data look like plotted plot of mass over visit

I'm trying to use a linear mixed effects model in lme4 to test the hypothesis that the treatments differ in the dry conditions but not otherwise but I am not sure how to code the random effects/ leverage repeated measures of each individual chick. What do you think of these approaches? Option 1)

lmer(mass~ treatment * condition + (1|visit/nest/chick)

Option 2)

lmer (mass~treatment * condition + visit +(1|nest/chick)

Thanks for any help.


The important question here is whether visit indicate a pre-during-post design, where you measure the chickens' mass before, during and after the treatment. In this case, if you want to assess the effectiveness of the treatment option 2 would be the correct choice.

However, additionally you might want to look at the interaction effect of treatment* condition* visit. If this interaction was significant it would tell you that the change in mass over time (between the different visits) would differ between the treatments, i.e. whether the effectiveness of the treatment differs between conditions (dry vs. wet). Moreover, you might want to estimate a random slope for each chick, to see whether the effectiveness of the treatment varies across chicks and nests.

In that case your model would be:

lmer(mass~ treatment * condition * visit + (1 + visit | nest/chick)

If the treatment was already administered and finished before the first visit, you should go with option 1.

| cite | improve this answer | |
  • $\begingroup$ Thanks! The treatment was administered at Visit 1, the assumption being that size of the chicks could differ between treatments at each of the next two visits. Your suggested model makes sense to me but I was trying to avoid a 3 way interaction because it can be hard to interpret. The suggestion about a random slope also makes sense. $\endgroup$ – SMM Oct 26 '17 at 15:51
  • 1
    $\begingroup$ EDIT: I tried your model Julian and it gave the following error: Error: number of observations (=837) <= number of random effects (=1176) for term (1 + visit | chick:nest); the random-effects parameters and the residual variance (or scale parameter) are probably unidentifiable. Any advise? $\endgroup$ – SMM Oct 26 '17 at 16:22
  • $\begingroup$ This means that the model has too many random terms for the number of observations that you have. For example, do you have more than 1 chicken from each nest, do you have 3 visits of each chicken? A good point to start when you want to see what random effects you can include in the model is to look at crosstabs use data$nest_chick <- paste0(data$nest, data$chick) and afterwards with(data, table(visit, nest_chick)) to see whether there is a 1 in each cell of the table, indicating that you have at least 1 measure for each chicken:nestobservation per visit. $\endgroup$ – Julian Quandt Oct 26 '17 at 18:31
  • $\begingroup$ about the 3-way interaction: I think that it is very relevant and interpretable here, consider this: If you just look at the condition*treatment interaction, the model will take the average mass of the 3 visits, while on the first one you would not expect any difference, as you haven't administered a treatment yet; this diminishes your effect. If you want to get a good understanding of the 3-way interaction make a plot where you calculate difference scores (mass at visit 3 - mass at visit 1), plot the treatment on the x-axis and make a seperate line for each environmental condition. [cont.] $\endgroup$ – Julian Quandt Oct 26 '17 at 18:42
  • 1
    $\begingroup$ you could edit it into your post if you want to. glad to hear that it works :) $\endgroup$ – Julian Quandt Oct 26 '17 at 22:40

Your Answer

