Peter Dalgaard <[EMAIL PROTECTED]> writes: > Gordon Smyth <[EMAIL PROTECTED]> writes: > > > On page 165 of Mixed-Effects Models in S and S-Plus by Pinheiro and > > Bates there is an example of using lme() in the nlme package to fit a > > model with crossed random factors. The example assumes though that the > > data is grouped. Is it possible to use lme() to fit crossed random > > factors when the data is not grouped? > > > > E.g., y <- rnorm(12); a=gl(4,1,12); b=gl(3,4,12). Can I fit an > > additive model like y~a+b but with a and b random? > > > > Everything I've tried gives an error: > > > > > lme(y~1,random=~1|(a+b)) > > Error in switch(mode(object), name = , numeric = , call = object, > > character = as.name(object), : > > [[ cannot be of mode ( > > > lme(y~1,random=~a+b) > > Error in getGroups.data.frame(dataMix, groups) : > > Invalid formula for groups > > > > A standard trick is to define a grouping with one level: > > one <- rep(1,length(y) > lme(...., random=~pdBlocked(.....)|one) > > (Sorry, I'm a little rusty on the syntax, but just follow the example > in P&B) > > AFAIR, it also works with random=list(a=~1,one=~b) and vice versa.
Not sure about that. > (The model is the same but you get different DF calculations, none of > which are correct in the completely balanced case...) I realize that it is awkward to use lme to fit models with crossed random effects. As Saikat DebRoy and I described in a recent preprint http://www.stat.wisc.edu/~bates/reports/MultiComp.pdf we now have a good handle on the computational methods for mixed-effects models with nested or crossed or partially crossed random effects. Both the nlme and the lme4 packages are based on structures that are tuned to nested random effects and do not easily accomodate crossed random effects. I have a draft of the contents of classes and methods for fitting linear mixed-effects models with nested or crossed or ... but it is a long way from the draft to working, tested code. Although it will take some time to get all the pieces in place I do offer some encouragement that this awkward phrasing of crossed random effects will some day be behind us. ______________________________________________ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help