[R] cross-classified random factors in lme without blocking
Peter Dalgaard
p.dalgaard at biostat.ku.dk
Fri Oct 31 10:37:28 CET 2003
Gordon Smyth <smyth at wehi.edu.au> 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.
(The model is the same but you get different DF calculations, none of
which are correct in the completely balanced case...)
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help
mailing list