# Aggregate repeated measures data or model it?

The structure of my data is causing me some trouble because I'd prefer to aggregate it but I'm not sure of the implications.

It's from an experiment comparing dwell time. The subjects were randomly assigned to one of two habitats. The habitats are identical except for an area that has been modified with characteristics that mimic (possibly) preferred habitats.

There are numerous subjects but we measure how much time each spends in the modified area each day.

There is evidence that differing amounts of sunlight affect habitat utilization and since we can't control the weather, we record whether each day is cloudy or sunny. We have gathered data on twenty-one consecutive days.

I would like to estimate the habitat effect on the difference in dwell times using a simple linear model such as:

$$E(y \mid \mathbf{x}) = \beta_0 + \beta_1 x_1 + \beta_2 x_2 + \beta_3 x_1 x_2$$

where $x_1$ is the habitat indicator, $x_2$ is the sunny/cloudy indicator, and we consider the possibility that the habitat difference can be modulated by the weather by estimating the habitat and weather interaction: $x_1x_2$.

Obviously this completely ignores the sequential and grouped nature of the data since we measure each subject multiple times.

In order to assume independence of the error term, I think I would need something like

$$E(y \mid \mathbf{x}) = \beta_0 + \beta_1 x_1 + \beta_2 x_2 + \beta_3 x_1 x_2 + \beta_4 x_3 + \beta_5 x_5$$

where $x_1$ and $x_2$ are as above, but $x_3$ is a subject-level fixed effect, and $x_5$ is something like a subject-level AR(1) term to account for within subject autocorrelation.

So my question is this: what is the hazard in aggregating the data so that each subject's outcome is the sum of time spent in the modified area on sunny days and cloudy days? If I simply add up each subject's time, I can estimate my first model without worrying about the autocorrelation or the individual fixed effects, right?

If you just add up the times, how do you interpret that e.g. the total time on 7 sunny days (e.g. 30 min per day) was 210 mins and on 14 cloudy days (e.g. 25 min per day) was 350 mins? Presumably you would divide by the number of days to get dwell time per day? If so, that in principle works fine for comparing the mean dwell time per day, except that the variance of the two outcomes is not necessarily the same, because it is more variable for the setting, for which you have fewer observations. I.e. an equal variance assumption would be potentially wrong, but it may not impact your results too much (hard to say - probably pretty safe, if the number of aggregated observations is almost equal in all groups) or you could use a model that allows for that.

Additionally, adding up the times may be problematic, if observations for some days are missing (may not be a concern in your case?) or the number of observations per animal differ - and if this is not occurring completely at random (it would for example be a problem, the observer could not be bothered to go out and do observations when the weather was particularly bad).

A repeated measures model would also allow you to adjust for further daily covariates or a continuous measure of light (e.g. some continuous measure of brightness). It would also tell you something about variation across days. However, it appears both of these things are not of interest.

Dwell time can presumably not be negative and also cannot exceed 24 hours per day, so a linear model may be bad choice. It may however be an acceptable approximation, but I would be worried about that and try to check that beforehand.

Using a subject-level fixed effect in the repeated measures model is an option, if you have a lot of data per individual, but alternatively you could just have a random subject effect with some correlation across the visits. However, as a correlation structure AR(1) tends to have very bad properties, because it tends to assume that observations that are far away from each other are independent even if the data clearly contradicts this (this would be partially mitigated by a fixed subject effect, but even then I would suspect that something more complex is better).

Additionally, you may have to consider whether dwell time is independent across subjects at a site assuming more than one subject can access an area at the same time, because then they might interact, which might increase or decrease dwell time. If there's only ever one subject that can access an area, this is of course no issue.

I'd say the biggest 'hazard' is that you may miss an interaction with time. It's possible that you have an effect of your habitat indicator, but that effect is not equally spread across measurements. I would just double check that by plotting your data, and check that nothing weird is going on. If it seems like the effect of habitat is a real main effect (i.e. the difference between the indicators is approximately equal for every measurement point), you're safe.