I have repeated measurements of individuals, like this
y | id | time | V1 | V2 100 1 1 23.2 0.8 88 1 2 22.6 0.9 98 2 1 10.6 1.1 83 2 2 11.1 1.3
y is a continous outcome variable,
id is the patient id,
time is the time point of oberservation and
V2 are covariates.
In this data example we have 2 patients that have 2 observations each, one at time 1 and another one at time 2.
My real data sets has hundreds of patients (ids) and 2-5 observations (time) for each patient.
I now know that the effect of
y is non-linear and what to model this with a GAM.
mgcv package there is a function called
gamm(). In my example, I use it like this:
m <- gamm(y ~ s(V1) + V2 + time ,family=gaussian, data=dat,random= ~(time|id))
Is this correct?
Does this model integrate the fact that
V1 can change over time for each individual?