I have been experimenting with gamm4 to derive GAMMs of some repeated measures data.
The models looks very nice and seem to give more flexibility than my LMMs.
Ultimately I want to compare models not by the quality of their fit (also the reality of comparing LMM and GAMM fits seems complex?), but in the quality of their predictions in new data sets, and in simulated new data by MCMC.
With LMMs I predict using the fixed effects only using:
mm <- model.matrix(terms(lmer),newdata) newdata$predicted <- mm %*% fixef(lmer)
This is fine since we are predicting in new individuals, with new independent random effects.
I cannot get this predict method to work with gamm4.
> mm <- model.matrix(terms(gamm4$mer), newdata) Error in model.frame.default(object, data, xlev = xlev) : variable lengths differ (found for 'X')
I think this is because the GAM process creates new variables in order to transform predictor variables. It is also complex, because I believe the transforms are stored as random effects, so I would need to extract these random effects, but not the “individual level” random effects.
Does anyone know how I can:
- Extract just the transform effect terms from the gamm4 model?
- Make predictions into new data using gamm4?
- Extract the model specification of the GAMM so I could implement it as a standalone algorithm?
- General advice?