Skip to content
Prev 360491 / 398503 Next

Random effects in package mgcv

If you want to include random intercepts in a model fit by bam/gam, then 
include
   s(g,bs="re")
in the model formula, where g is a factor variable with one level for 
each group requiring a random intercept.
Now suppose that for each level of group g you want a random slope 
w.r.t. x. You should include a term
   s(g,x,bs="re")
in the gam formula (the order of g and x is not important). For random 
slopes and random intercepts include
   s(g,bs="re") + s(g,x,bs="re")

gam/bam only supports quite simple i.i.d random effects, so correlated 
intercepts and slopes can not be estimated this way. Also the methods 
are not efficient for thousands of random effects (actually 
bam(,discrete=TRUE) in recent versions will manage thousands, but not 
10s of thousands).

best,
Simon
On 27/04/16 15:12, Dean Force wrote: