# Circular smooths within a GAM-GEE framework

I have a predictor variable which I fit in a GAM as a circular smooth term:

temp <- transform(temp, impact.f = factor(impact))
gam(Dist ~ impact.f + s(TimeAroundHW, by=impact.f, k=k, bs ="cc"),
data=temp, family="Gamma")

I want my standard errors to be robust to residual auto-correlation within blocks of individual as currently there is a high degree of auto-correlation. I also want a population mean response rather than individual effects so I'd like to fit in a GEE framework rather than a mixed-effects model, however I cannot find any examples or possibilities for fitting circular smooths with GEEs. Has anyone done this before?

I have read a paper (Benjamins et al., 2017 Harbour porpoise distribution can vary at small spatiotemporal scales in energetic habitats) in which they do exactly this. They also provide the R code that they used, you might want to check it?

They basically generate variance-covariance matrices for the cyclic covariates, and include these in the GEE. Here's the piece of code that they use for that purpose:

## STEP 4: Model selection - covariate preparation ##
# Construct variance-covariance matrices for cyclic covariates:
TideBasis<-gam(DPM~s(TIDEMINUTE, bs="cc", k=6), fit=F, data=M7, family=binomial, knots=list(TIDEMINUTE=seq(0,1,length=6)))$$X[,2:5] AvgHrBasis<-gam(DPM~s(HOUR, bs="cc", k=6), fit=F, data=M7, family=binomial, knots=list(HOUR=seq(0,23,length=6)))$$X[,2:5]

TideBasisMat<-as.matrix(TideBasis)
AvgHrBasisMat<-as.matrix(AvgHrBasis)

So then, in their model, they use these last 2 objects created (TideBasisMat and AvgHrBasisMat) inside the GEE.
I am not a statistician so I can't explain you why and how this works though... Just forwarding you what I found as I had the exact same problem previously.
Hope that helps even though your post was quite a while ago!