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), 
          family = nb(link=log),

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?

  • $\begingroup$ "all zeros and NaNs" Do you mean, that all Abundance values for the control where 0 or NaN? If yes then your problem is actually with the log-link. Also you should share summary(model) $\endgroup$ Commented Oct 3, 2023 at 18:21
  • $\begingroup$ @LukasLohse I added the model summary! $\endgroup$ Commented Oct 3, 2023 at 22:41

1 Answer 1


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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.