Consider me very new to the world of GAMs, I am actually using it out of necessity rather than by choice but I thought it could be a chance to learn something new anyway.
Originally I had hoped to model my data with a GLMM, which feels fairly natural to me in the way you assign nested random variables. In the case of my study, using lme4
I would write (1|SURVEYGR/YEAR/PlotID)
. This implies PlotID
is nested in YEAR
which is nested in SURVEYGR
. But when it comes to the mgcv
package I haven't managed to find a clear explanation for the equivalent expression. I have seen it is possible to use the bs=re
(re=random effect) argument for example s(YEAR, bs="re")
while in other cases such as this blog I have seen a number of random variables together as such s(SURVEYGR,YEAR,PlotID, bs="re")
but there is a lot going on and it is hard to tease out what this code implies. The problem is, I am not sure how nested random variables should be structured
So ultimately I would like to know what the mgcv
code equivalent for a GAM model would be for the following GLMM model written for lme4
:
glmer.nb(count ~ vegetation.cover + temperature +
(1|SURVEYGR/YEAR/PlotID)
, na.action = "na.fail"
, data = dd, verbose=T)
At a guess it might be something like
gam(count ~ s(vegetation.cover) + s(temperature) +
s(SURV.GR,YEAR,PlotID, bs="re")
, family = nb()
, data=dd, method="REML")
EDIT
a bit of snooping around turned up this post on SO where translating the comments to my question suggest including the terms individually and then the interaction for nested random effect terms like so:
+ s(SURV.GR, bs="re") + s(SURV.GR,YEAR, bs="re") + s(SURV.GR,YEAR,PlotID, bs="re")
Any thoughts?