Autocorrelative parameter in GAM in R I'm looking at a dataset of the number of users who used a specific software over a period of a year. I also have a binary predictor in the model. There is substantial autocorrelation in the data, and so I'm trying to include a parameter to account for this. Currently, my model is as such:
gam_y <- gamm(Users ~ s(Date, k = 365) + binary_pred, data = player_numbers, method = "REML", correlation = corAR1())
However, this model still comes up with substantial autocorrelation. Am I specifying the AR1 term incorrectly, or is there likely to be a different problem? (I'm quite new to GAMs).
Thanks in advance!
 A: This is possibly correct; you are not setting this up to be robust to data issues however. Ideally you would use corAR1(form = ~ time) where time is some variable ordering the observations regularly in time. If your data are in time order and regularly spaced when the model sees the data then how you have it will work, but if you have NAs in the data for example or data get out of order, relying on the ordering is a bad thing.
I'm not sure how you determined that there was strong residual autocorrelation as you didn't mention this, but most often people come to this conclusion because they look at the ACF of the residuals and it remains autocorrelated. Unfortunately this is often a mistaken assumption because the autocorrelation structure is only taken into account if you extract the normalized residuals and these are not the default in the resid() method for "lme" classed models. Use resid(gam_y$lme, type = "normalized") to access the residuals for checking residual autocorrelation.
If you did that already, then consider if the dependence structure in the residuals really is AR(1) or whether higher order or whether moving average terms are needed in the correlation structure. You can specify these with the corARMA() correlation structure but model fitting will be a lot slower as there aren't the same computational tricks available that are used by corAR1().
