[R] mgcv: Extract random effects from gam model
s.wood at bath.ac.uk
Mon Jul 23 11:41:36 CEST 2012
Hi Jan ,
coef(mod) will extract the coefficients, including for a. They are
labelled and for 'a' are in the same order as levels(a).
On 23/07/12 10:08, janvanhove wrote:
> 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.
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
Simon Wood, Mathematical Science, University of Bath BA2 7AY UK
+44 (0)1225 386603 http://people.bath.ac.uk/sw283
More information about the R-help