I am using
gam from the
mgcv package to model the effects of climate on the size of small lakes. I have data from 70 lakes across 30 years. As change in lake area is non-linear over time, I have modeled
Year as a smooth term:
gam(Size ~ s(Year, Lake_ID, bs="fs") + Climate)
Lake_ID is a factor corresponding to each lake and
Climateis the annual temperature and precipitation measurements. However, my PACF plot looks like:
Is my interpretation that this shows significant autocorrelation up to lag 6 correct? I have tried to fit the same model using
gamm with an autocorrelation term.
gamm(Size ~ s(Year, Lake_ID, bs="fs") + Climate, correlation = corAR1(form=~Year|Lake_ID)
However, this gave the following error:
Error in matrix(0, size.cg[i], size.cg[i]) : object 'size.cg' not found.
This error can be reproduced on a toy dataset below, which seems to only occur using the
library(mgcv) set.seed(0) dat <- gamSim(4,n=200,scale=2) gamm1 <- gamm(y~s(f1,fac,bs="fs"), correlation = corAR1(form=~f1|fac),data=dat)
Is there some way to use the factor-smooth with corAR1 in gamm? Any ideas how to address the autocorrelation in the lake dataset using either