I want to fit a GAM in R. My data are negative binomial. Plus they have a temporal autocorrelation.
m1 <- gam(Y~s(X,Day), s(fDate, bs="re"), family=negbin(c(1,10), link = log), data=data)
Resid <- resid(m1)
acf(Resid)
With the acf()
function I have detected a temporal autocorrelation. Can I apply a correlation structure in gam()
, or do I have to use gamm()
, since in gamm()
I can´t use a negative binomial function, or am I doing something wrong with that? Is it basically possible to apply a negative binomial family in gamm()
like this?
m2 <- gamm(Y~s(X,Day), random=list(Date=~1), family=negbin(c(1,10), link = log),
correlation=corAR1(form=~Day), data=data)
gamm
- so I am not sure whatform=~Day
means exactly in this context.) So I think it should stay here, with a discussion of possible reasonable model specifications. $\endgroup$