Solved – lmer for repeated measures

lme4-nlmemixed modelrrepeated measures

I have several animal pairs pair. For each, I repeatedly measured daily proportions of time they spent in contact time.con (30-60 measurements for each group, 1 measurement per date). I want to compare how much time different pairs spent in contact using lmer and controlling for repeated measures. The pairs are permanent, so essentially pair = individual. Here is a simplified example:

      pair   date     time.con

 [1,] "1"  "01.06.17" "0.12"  
 [2,] "1"  "02.06.17" "0"     
 [3,] "1"  "03.06.17" "0.11"  
 [4,] "2"  "04.06.17" "0.34"  
 [5,] "2"  "05.06.17" "0.02"  
 [6,] "2"  "06.06.17" "0.07"  
 [7,] "3"  "01.06.17" "0.14"  
 [8,] "3"  "02.06.17" "0.26"  
 [9,] "3"  "03.06.17" "0.1"

So, the fixed effect would be pair. The question is, how do I control for repeated measures? If I use pair as both fixed and random effect, the model, obviously, fails to converge:

`lmer(time.con ~ pair + (1|pair))`

I guess that's where I'm meant to use date somehow (as nested in pair?), but I cannot get the syntax right:

`lmer(time.con ~ pair + (1+pair|date))` (doesn't work)

I'm probably missing something simple, as I'm new both to R and lmm. Would appreciate any advice!

Best Answer

This seems to be a longitudinal study, with measurements over time for each pair. As a first step, based on the date variable you could construct the follow-up time variable, which is the time from the first measurement. Think however carefully if the first measurement really is the time 0 for each pair for your experiment or perhaps another date.

Then, you include random effects for the pair grouping variable, but not include it also as a fixed effect. You could start with a random intercepts model, e.g.,

fm1 <- lmer(time.con ~ follow_up_time + (1 | pair), 
            data = your_data)

This model postulates that the correlations over time within a pair remain constant. You could extend the model by assume that the correlations decrease with the time span between measurements using a random intercepts and random slopes model, e.g.,

fm2 <- lmer(time.con ~ follow_up_time + (follow_up_time | pair), 
            data = your_data)

To evaluate if you need the random slopes, you could do a likelihood ratio test, i.e.,

anova(fm1, fm2)
Related Question