GAM in R – Modeling Repeated Measures

generalized-additive-modelmgcvrrepeated measures

I have a data set where abundance is measured at 3 treatment levels from the same transects over the span of 3 months. I read that to account for repeated measures, I could smooth time (day of the year) for each treatment effect, leading me to code my negative binomial model like this using mgcv:

model <- gam(Abundance ~ Treatment + 
            DayofYear +
            s(KelpCover) +
            s(DayofYear, by=Treatment), 
          data=abunddata,
          family = nb(link=log),
          method="REML")

When I ran the model, the intercept (control treatment) was not able to be estimated (all zeros and NaNs). Apparently this can be because there are not enough data points for that coefficient, so when I checked there were 247 observations for the control, with the other two treatment levels having 400 and 499.

Model summary:

enter image description here

Are there any other way to account for repeated measures in a GAM?

Best Answer

It looks like you have this problem: Problems interpreting GAM output which already has a great answer from Gavin Simpson, here: https://stats.stackexchange.com/a/404862/341520

In short, you have redundancy between the "simple" terms Intercept, DayofYear and s(DayofYear, by=Treatment). You need to either drop at least DayofYear or adjust the spline definitions as described in the linked answer.

Related Question