0
$\begingroup$

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?

$\endgroup$
  • $\begingroup$ it just mean you only estimate the intercept and not the slope>? $\endgroup$ – user1320502 Sep 23 '14 at 12:36
  • $\begingroup$ it is a function used in the definition of smooth terms within gam(m) model formulae. See ?mgcv::s $\endgroup$ – rcs Sep 23 '14 at 12:52
1
$\begingroup$
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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.