specification of mixed effects model with two levels of repeated measures (in R) My colleagues and I conducted a study of the effects of an experimental translocation on the movement and activity patterns of common brushtail possums in New Zealand. This involved first capturing 12 individuals (6 males and 6 females), fitting them with GPS collars, and releasing each study animal within its home range. After seven days, we re-captured the animals, fitted them with new GPS collars, and then moved them to a common release site that was well outside of all of their home ranges. For both deployments the GPS collars recorded location data at 5-min intervals for an 11-h period during the night when possums are active. Our response variables were duration of nightly active periods, total distance moved per night, mean nightly speed and several other metrics that were descriptive of variation in movement behaviour. 
Our data are a bit messy (unbalanced) because we didn’t get observations from all animals each night of the two 7-d sampling periods (for various reasons), but basically look like this for each animal, with multiple response variables:


*

*Up to seven nights of movement data prior to translocation;

*Translocation event; 

*Up to seven nights of movement data after translocation.


Our major research questions were:
1.  Do males and females differ in the responses to translocation?
2.  How do responses to translocation (as measured by activity, movement, etc) change with respect to the time (day) since the translocation event? 
3.  The interaction between 1 and 2 above.  
As far as I can tell, these data are best analysed with a mixed-effects model with REML, because of their repeated-measures nature (both before and after translocation), missing values, and combination of fixed (sex) and random factors. From what I’ve read (Zuur’s book), classical repeated-measures ANOVA is inappropriate for several reasons.
My question is thus: what is an appropriate mixed-effects model formulation for these data in R using the ‘lme4’ package? There is a before/after effect (with respect to translocation), a repeated-measures effect (seven sequential days of data for each GPS collar deployment), and again the fixed effect of sex. I am confused on how to nest the data properly to incorporate the two different levels of temporal autocorrelation (i.e., before/after translocation and then the time series of each GPS deployment). 
Any help with what is the correct model code for analysis in R would be hugely appreciated!!
 A: 
Our major research questions were: 1. Do males and females differ in the responses to translocation? 2. How do responses to translocation (as measured by activity, movement, etc) change with respect to the time (day) since the translocation event? 3. The interaction between 1 and 2 above.

I believe the basic structure here would be something like:


*

*fixed effects: ~ sex*day*I(day>0), where day is centred on the translocation day (i.e. the translocation occurs on day 0, pre-translocation days are negative, post-translocation days are positive).  This allows for different slopes before and after as well as a discontinuity at the translocation time (different intercepts).

*random effects: ideally ~day*I(day>0)|individual to allow for varying slopes and intercepts in both periods among individuals.  This may be slightly too ambitious (estimating a 3x3 covariance matrix from 12 individuals = 6 parameters), but it's not insane.

*you may want to use lme to more easily allow for autocorrelation via correlation=corCAR1(~day) (or something like that); this uses a continuous-time first-order autoregressive model. The continuous-time part in particular (in contrast to the more usual discrete-time corAR1) is useful when there are missing values in the data set or the values are otherwise unevenly spaced.  You might be able to do this via the lme4ord package, but that's definitely at the 'alpha' (i.e. experimental) release stage.


You probably want to think about transforming the response.  One useful trick is to find the residuals from your initial fit and then try MASS::boxcox(r~1).  A log-transform is usually a good initial guess unless you have zeros in your data.
Some other more advanced stuff that might be interesting but is computationally harder and possibly beyond the scope of this data set:


*

*consider the possibility of differences between sexes in either within-individual variance (easy via weights=varIdent(~1|sex)) or among-individual variance (harder) 

*'stack' the data and fit the responses as single multivariate observations (e.g. see here rather than a variety of univariate observations

*consider GAMs for the temporal trends (e.g. the gamm4 package)

