3

I have behavioral data for many groups of birds over 10 days of observation. I wanted to investigate whether there is a temporal pattern in some behaviors (e.g. does mate competition increase over time?) And I was told that I had to account for the autocorrelation of the data, since behavior is unlikely to be independent in each day.

However I was wondering about two things:

  1. Since I'm not interested in the differences in y among days but the trend of y over days, do I still need to correct for autocorrelation?

  2. If yes, how do I control for the autocorrelation so that I'm left out only with the signal (and noise of course)?

For the second question, keep in mind I will be analyzing the effect of time on behavior using mixed models in R (since there are random effects such as pseudo-replication), but I have not found any straightforward method of correcting for autocorrelation in the data when modeling the responses.

Zoe
  • 27,060
  • 21
  • 118
  • 148
Romulo
  • 41
  • 1
  • 2

1 Answers1

6

(1) Yes, you should check for/account for autocorrelation.

The first example here shows an example of estimating trends in a mixed model while accounting for autocorrelation.

You can fit these models with lme from the nlme package. Here's a mixed model without autocorrelation included:

cmod_lme <- lme(GS.NEE ~ cYear,
            data=mc2, method="REML",
            random = ~ 1 + cYear | Site)

and you can explore the autocorrelation by using plot(ACF(cmod_lme)).

(2) Add correlation to the model something like this:

cmod_lme_acor <- update(cmod_lme, 
       correlation=corAR1(form=~cYear|Site)

@JeffreyGirard notes that

to check the ACF after updating the model to include the correlation argument, you will need to use plot(ACF(cmod_lme_acor, resType = "normalized"))

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • Hi, in your example it looked like you are looking at autocorrelation on the random effects. Can I use it in the fixed effects? In my case the independent variable is time (days), but time itself can cause the autocorrelation I'm trying to correct. So do I have to have time as both fixed and random effects? My model be something like this: (g)lmer(Behavior ~ Time + (1|groupID), data = bird) – Romulo Apr 12 '18 at 21:21
  • This models autocorrelation in the residuals. `~cYear|Site` means that `cYear` is the time-ordering variable and `Site` is the grouping variable (i.e., residuals are only correlated within groups); you would want something like `correlation=corAR1(formula=~Time|groupID)`. This is for `lme`; you can't easily do it with GLMMs. – Ben Bolker Apr 12 '18 at 23:17
  • 1
    Tried to add the correlation structre with correlation=corAR1(formula = ~time|Site) but it gives me an error. Turns out that the code now is correlation=corAR1(form = ~time|Site) – Simone Jun 08 '18 at 15:36
  • 1
    Note that to check the ACF after updating the model to include the correlation argument, you will need to use `plot(ACF(cmod_lme_acor, resType = "normalized"))` or it will show you a version that was not corrected. – Jeffrey Girard Oct 04 '18 at 22:01