Skip to content
Prev 15653 / 20628 Next

A question on setting up a generalized additive mixed effect model

Hi Leon,

I agree that it makes sense to have both a by-subject intercept and
slope, but you will needs lots of data to estimate that for GAMM because
the smoothers "eat" a lot of data. Based on your model structure and
error message, I'm guessing that you have around 20 subjects or less.
Both for computational and inferential purposes, you need closer to 40
or preferably 100+ subjects for this study. See e.g. Button et al. 2013
(Nature Neuroscience) or Button's more recent paper in eNeuro. I know
that's a lot for scanner data, especially of infants. :(

Two other quick notes:

1. don't name your fitted model "gam" as this then shadows the function
"gam()" and can lead to a world of pain full of subtle bugs and weird
error messages.

2. You can also fit your model with a more mixed-model like syntax (e.g.
1|subjeIndex ) via the package gamm4. It turns out that you can express
random effects as smoothers (the mgcv approach) or smoothers as random
effects (the gamm4) approach. Depending on your exact model structure,
one or the other may be faster. See

?mgcv::random.effects

for more info.

Phillip
On 04/04/2017 12:18 AM, Leon Lee wrote: