[R] mgcv: Extract random effects from gam model

janvanhove jan.vanhove at unifr.ch
Mon Jul 23 11:08:12 CEST 2012

Hi everyone,

I can't figure out how to extract by-factor random effect adjustments from a
gam model (mgcv package).

Example (from ?gam.vcomp):
dat <- gamSim(1,n=400,dist="normal",scale=2)
a <- factor(sample(1:10,400,replace=TRUE))
b <- factor(sample(1:7,400,replace=TRUE))
Xa <- model.matrix(~a-1)    ## random main effects
Xb <-  model.matrix(~b-1)
Xab <- model.matrix(~a:b-1) ## random interaction
dat$y <- dat$y + Xa%*%rnorm(10)*.5 + 
  Xb%*%rnorm(7)*.3 + Xab%*%rnorm(70)*.7
dat$a <- a;dat$b <- b

mod <- gam(y ~ s(a, bs="re") + s(x2, k = 15), data = dat)

When I run plot(mod) I can see the adjustments for the "a" factor, but I
don't know which adjustment is associated with which factor. Is it possible
to extract the information underlying this plot numerically?


View this message in context: http://r.789695.n4.nabble.com/mgcv-Extract-random-effects-from-gam-model-tp4637415.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list