How should I specify random effects in a crossover study with lots of repeated measures (continuous time component)? I don't see any previous questions (with answers) about this exact thing.
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: 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.

A: 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.
