Skip to content

Random effects in GAMs

3 messages · Philippi, Tom, Julian Chen

#
I am now trying to use random effects in GAMs developed by Professor Simon
Wood. Prof Wood uses  s(...,bs="re") to account for the random effects.
Random intercepts models or random slopes models are two different types of
mixed linear models or general random effects model (Cameron and Trivedi,
2005). I wonder if the Wood's method includes both random intercepts and
random slopes. Based on my understanding, this method does? Anyone can help
me clarify this method? The following is the link of Random effects in GAM
developed by Prof Wood.

https://stat.ethz.ch/R-manual/R-devel/library/mgcv/html/random.effects.html
#
Julian--
Without further information on your data generating process and what
structure you are trying to capture with your model, we don't know what
your random effects are accounting for. For instance, my frequent use case
is GAM for smoothing across time, and sites as random effects, which
requires mgcv::gamm or gamm4:gamm4 (the first method in your linked page)
instead of gam() with s(...,bs='re').   I don't think that anyone can give
you helpful answers without that further information.

I highly recommend Simon Wood's book "Generalized Additive Models".  It
starts with clear explanations of linear models and generalized linear
models, builds through gams, and ends with a chapter on mixed models and
gamms.  I find it to be a valuable reference for LM, GLM, GAM, and GAMM,
all in a single book.

Tom 2



On Fri, Feb 12, 2016 at 10:58 AM, Julian Chen <power.julian.chen at gmail.com>
wrote:

  
  
#
I am now using random effects of GAM to predict crash frequency at
intersections. The family is negative binomial distribution. I wonder if
this term bs="re" can account for both random intercepts and random slopes
effects together?

It is longitudinal data. The number of crashes, traffic volume on major
roads and traffic volume on minor roads are observed repeatedly three years
for each different intersection as below.

crash main.traffic.volume minor.traffic.volume  ID
1 38122 2789 1
0 40216 2930 1
0 41231 3022 1
2 12890 3401 2
3 13241 3211 2
2 13568 3322 2
1 46889 5688 3
2 48232 5843 3
0 52301 6012 3
*... ...         ...         ...*

I wonder if my code below can account for both random intercepts and random
slopes effects together? or only random slopes effects? Any suggestions?
#########################################################################################
gam(crash~s(main.traffic.volume, ID, bs=?re")+s(minor.traffic.volume, ID,
bs="re"), family=nb(),data=mydata3sg)
#########################################################################################

Many thanks!
Julian

On Fri, Feb 12, 2016 at 1:58 PM, Julian Chen <power.julian.chen at gmail.com>
wrote: