I am modeling fishery CPUE as a function of a number of a number of covariates using a GAM approach that includes fixed and random effects.
I understand that there are limitations with regards to predicting random effects (predict function only addresses fixed effects) with gamm4. How does the predict function in the basic gam (mgcv, using bs="re") deal with the random effects? Are they included in predictions? Any thoughts would be much appreciated…
Best Answer
Yes, they are included, but only ever for the observed levels of the random factor. You can turn this using the
by
variable smooth trick however.Consider the following example taken from
?gam.models
:Now lets get the additive term contributions from the model and compare them with the full blown model predictions:
which gives
So we are convinced now that the two ways of generating the predicted values are equivalent. now look at
p
the additive term contributions to the fitted values:The first column is the
s(fac)
which was a random effect spline in the fitted GAM.I will add that the
gamm()
function also in mgcv can give the within-group predictions (fitted values):