I'm currently trying to figure out how to specify a generalized additive model in four different ways in order to investigate how my outcome variable changes surrounding different events. So what I want to model is
- fixed effect of year from event only, with no person-specific model parameters (i.e., each person is assigned an identical curve),
- multilevel with person-specific varying intercepts (i.e., the shape of the curve is the same for each person, but an intercept allows for different overall levels of my outcome variable),
- multilevel with person-specific varying intercepts and slopes (i.e., in addition to the intercept, a slope parameter allows for different linear change in my outcome variable over time), and
- multilevel with person-specific varying curves. In a next step I would like to compare these models on the basis of predictive fit and deviance explained.
So far, I got this, which (if I got it right?) does not include any specification. It just represents the estimated population-level trajectories of my outcome variable surrounding the event (as "year" was event-centered):
gam_event1 <- gam(outcome ~ s(year), data = event1.sample, method ="REML")
This is my output plotted:
But how can I specify these four different models described above? Unfortunately looking at the mgcv documentation wasn't a great help to me.
I'm relatively new to R and even newer to GAM so please excuse me if this is a really stupid question! Your help is highly appreciated!