We are hoping for some guidance regarding a gam model using mgcv R package. We want to know if variables measured over time affect our outcome variable. In other words if variable "X" and/or variable "Y" changes after controlling for time.
We have the following variables:
- ID - subject identification
- year - continuous covariate, repeated measures
- Var X - continuous variable
- Var Y - continuous variable
- Outcome - continuous variable, dependent variable
We are not entirely sure if the following model answers our question:
m1 <- gam(Outcome ~ s(VarX) + s(VarY) + s(year) +
s(year, ID, bs = "fs"),
family = gaussian, data = dat, method = 'REML')
Or if the model below is the one taking into account that each variable is measured over time for each ID:
m2 <- gam(Outcome ~ s(VarX) + s(VarY) + s(year) +
s(year, ID, bs = "fs", by = VarX) +
s(year, ID, bs = "fs", by = VarY),
data = dat, method = 'REML')