I'm completely new to GAM's so please bear with me. We have two groups that have an outcome measured over time. The trends are clearly non-linear and while measurements of the outcome differ at the start of time, they gradually converge to be quite similar. We are interested in trying to model and test the latest time that differences between the two groups are still statistically significant.
My plan was to run a gam model and then test group means at regular time points using the emmeans package.
If I run the following model, everything works great:
gam_mod <- gam(lactate ~ group + s(time, by = group), data = dat_long)
I can get predictions, do plots and test differences.
However, while most observations are independent there are some individuals with multiple observations - in total: 53 subjects with 64 observations. So, it may not make that much difference if I ignore the repeated measures given there aren't many.
In any case if I run a model to try and account for the repeats, I get an error:
> gam_mod <- gam(lactate ~ group + s(time, by = group) + s(id, bs = "re"), data = dat_long) Error in gam(lactate ~ group + s(time, by = group) + s(id, bs = "re"), : Model has more coefficients than data
If I want to specify a random intercept, is this model specification correct? If so, is the error just because I don't have enough data (how many parameters are being estimated?), or are there issues because of the larger numbers of singleton clusters?