[R] Random effects in GAMs

Julian Chen power.julian.chen at gmail.com
Sat Feb 13 00:27:04 CET 2016


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" developed by Prof Simon Wood 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!

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

> 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
>
> --
> Life is nothing but a dream,
>      and if we are artists,
> then we can create our life with Love,
>      and our dream becomes
>        a masterpiece of art.
>



-- 
Life is nothing but a dream,
     and if we are artists,
then we can create our life with Love,
     and our dream becomes
       a masterpiece of art.

	[[alternative HTML version deleted]]



More information about the R-help mailing list