[R] Problem extracting enough coefs from gam (mgcv package)

Martijn Wieling wieling at gmail.com
Mon Apr 23 19:26:19 CEST 2012


Dear useRs,

I have used using the excellent mgcv package (version 1.7-12) to
create a generalized additive model (gam) including random effects -
represented with s(...,bs="re") - on the basis of dialect data.

My model contains two random-effect factors (Word and Key - the latter
representing a speaker) and I have added both random intercepts and
various random slopes for these random-effect factors. There is no
missing data in my dataset. When I try to extract the by-word random
intercepts from my model, using coef(model), I find 357 values, equal
to the number of words in my dataset. Using coef(model) I get
uninformative names: s(Word,1) until s(Word,357), but I'm assuming (I
might be wrong though?) that I can link the labels of the words to
these values by obtaining the 357 labels from the original dataset:
unique(dat[,c("Word")])

Unfortunately, I cannot use this procedure to label the by-word random
slopes, because I find a varying number of values for these (ranging
from 346 to 356) which is always less than 357. (The number of
by-speaker random slopes does equal the number of speakers, though.)

Does anybody i) have an idea why I obtain fewer by-word random slopes
than words, and/or ii) how I can link the random slopes which are
present to the correct labels of the words?

(I did not include the model as it is >300 MB in size, but let me know
if this is necessary.)

Any help would be greatly appreciated!

With kind regards,
Martijn Wieling
University of Groningen
http://www.martijnwieling.nl



More information about the R-help mailing list