# How should I specify random effects in a crossover study with lots of repeated measures (continuous time component)?

n=20 patients. Each took placebo then did a task for up to 60 minutes. Response (continuous variable) was measured every 2 minutes so I coded time as continuous. Every patient did the task again after taking the treatment drug a month later. The order (drug or placebo) was random.

Using nlme in R, I am not sure which model to use. Or maybe both are wrong?

m1 <- lme(Y ~ Group + minutes, data = datas, random = ~ 1 | ID,
na.action = na.omit)

m2 <- lme(Y ~ Group + minutes, data = datas, random = ~ minutes | ID,
na.action = na.omit)


A couple of points:

• In cross-over trials, an important consideration is whether you have carry-over effects, and this is why you typically include a wash-out period. I guess this is why you allowed one month in between?
• In any case, you need to test whether you have such carry-over effects by including the period (i.e., the indicator of the two sets of patients with 0 say for the ones who first took placebo, and then treatment, and 1 for the one who first took treatment and then placebo) and its interaction with Group. If the interaction is significant, then the wash-out period wasn't sufficient, and you need to include the interaction term in your final model, making interpretation more difficult.
• If the interaction is not significant, then you could potentially only control for the main effect of period.
• As Ben also suggested, you should also include the main effects and interaction of Group and minutes, i.e., Group * minutes.
• For the random effects, you will need to test what is the appropriate random-effects structure, starting from random intercepts, and seeing if you need random slopes and/or additional potentially nonlinear random effects.
• Thanks for that. I am still not sure how to do the last bullet point though, aside from simply trying all possibilities and comparing BIC. How do I "test" for the appropriate random effect structure? Oct 22, 2018 at 21:04
• Most often you build up the random-effects structure starting from intercepts and include each time additional random effects for you time variable (e.g., linear slopes, the quadratic slopes, etc.). In this case, the models are nested and you can compare them using the likelihood ratio test that is performed by the anova() function. Oct 22, 2018 at 21:48
• I found that the lowest BIC model was actually this: m3 <- lme(Y ~ Group + minutes, random = ~minutes*Group|ID) I can only find once example of this on the internet which says the random effects mean: "by-ID random intercepts and by-ID random slopes for minutes, Group, and the minutes * Group interaction plus correlations among the by-ID random effects parameters" -> since it's the lowest BIC should I go with it? Or avoid since I don't have a theoretical justification? Oct 22, 2018 at 23:21

Your first model is a random-intercept model; it assumes individuals vary only in their intercepts (test result at time 0/beginning of measurement).

m1 <- lme(Y ~ Group + minutes, data = datas,
random = ~1|ID, na.action=na.omit)


Your second model is a random-slopes model; it allows for random variation in the individual-level slopes (and in the intercept, and a correlation between slopes and intercepts)

m2 <- update(m1, random = ~ minutes|ID)


I'd suggest the random-slopes model is more appropriate (see e.g. Schielzeth and Forstmeier 2009).

Some other considerations:

• might there be an overall difference in time trends across treatments? Perhaps, so I'd suggest including an interaction between Group and minutes (Group*minutes == 1 + Group + minutes + Group:minutes
• there might be an order effect
• you might want to allow for/check for temporal autocorrelation (e.g. correlation=corAR1(form = ~ minutes | ID), although things might get complicated if you have missing data, see ?nlme::corCAR1)

BTW there's no such thing as nlme4: there's an nlme package, which you'r using (it includes the lme function), and an lme4 package, which includes the lmer function ...

Schielzeth, Holger, and Wolfgang Forstmeier. “Conclusions beyond Support: Overconfident Estimates in Mixed Models.” Behavioral Ecology 20, no. 2 (March 1, 2009): 416–20. https://doi.org/10.1093/beheco/arn145.

• yes, I meant nlme thanks. Glad to know I wasn't completely off, as I did try both as well as interaction and figured I should just use the one with the lowest BIC. I have looked at several papers but none that mention how to do this for crossover studies. I'll check yours out. thanks Oct 22, 2018 at 20:13