# gamm4 what does s() do?

say we have the following:

library(gamm4)
set.seed(0)
dat <- gamSim(1,n=400,scale=2) ## simulate 4 term additive truth
## Now add 20 level random effect 􏰁fac􏰀...
dat$fac <- fac <- as.factor(sample(1:20,400,replace=TRUE)) dat$y <- dat$y + model.matrix(~fac-1)%*%rnorm(20)*.5 gamm4 5 br <- gamm4(y~s(x0)+x1+s(x2),data=dat,random=~(1|fac))  What does the s() do in this model? • it just mean you only estimate the intercept and not the slope>? – user1320502 Sep 23 '14 at 12:36 • it is a function used in the definition of smooth terms within gam(m) model formulae. See ?mgcv::s – rcs Sep 23 '14 at 12:52 ## 1 Answer library(gamm4) set.seed(0) dat <- gamSim(1,n=400,scale=2) ## simulate 4 term additive truth ## Now add 20 level random effect 􏰁fac􏰀... dat$fac <- fac <- as.factor(sample(1:20,400,replace=TRUE))
dat$y <- dat$y + model.matrix(~fac-1)%*%rnorm(20)*.5
#gamm4 5
br <- gamm4(y~s(x0)+x1+s(x2),data=dat,random=~(1|fac))
plot(br$gam,pages=1,all=TRUE) br <- gamm4(y~x0+x1+x2,data=dat,random=~(1|fac)) plot(br$gam,pages=1,all=TRUE)


s() terms are represented as penalized splines. You might read Simon Wood's 2006 textbook for more on what that is. The code above illustrates the difference with and without.