[R] Random effects in package mgcv

Simon Wood simon.wood at bath.edu
Thu Apr 28 08:56:00 CEST 2016


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:
> Hello R users,
>
>
> I have a quick question I was hoping to get your input on. I am new to R
> and the smooth statistical regression world, and am trying to wrap my mind
> around the issues concerning using splines for mixed effect modeling.
>
> My question is the following: in the ‘gamm’ function, generalized additive
> mixed models can be estimated by including random components. These can be
> explicitly defined in the syntax, where you can also define whether the
> random component is an intercept, slope, or both. My understanding is that
> in the gam/bam function the same is achieved by including the bs="re”
> option for random intercepts and linear random slopes. Am I correct? If so,
> is there a way to specify whether it is the intercept or slope we are
> interested in, and does that have any effect on the output of the model?
>
> I hope these questions make sense, and I look forward to learning more
> about this.  Thanks for taking the time to read through this email.
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


-- 
Simon Wood, School of Mathematics, University of Bristol BS8 1TW UK
+44 (0)117 33 18273     http://www.maths.bris.ac.uk/~sw15190



More information about the R-help mailing list