[R-sig-ME] [R] lme nesting/interaction advice

Kevin Wright kw.statr at gmail.com
Mon May 12 16:56:17 CEST 2008


> > Maybe you are looking for something similar to:
> >
> > set.seed(78987)
> > a = rep(1:3,each=120)
> > b = rep(1:3,3, each=40)
> > c = rep(1:10,9,each=4)
> > y = rnorm(360,0,10)
> > x = cbind(a,b,c,y)
> > colnames(x) = c("a", "b", "c", "y")
> > x = as.data.frame(x)
> >
> > lme = lme(y ~ factor(a)*factor(b)*factor(c)-1, x, ~factor(c))
> > anova(lme)
> >
>
>  With the very same model you're using I get:
>
>  > lme.mod = lme(y ~ selection * males * month-1, random = ~month, testdat)
>  Error in getGroups.data.frame(dataMix, groups) :
>   Invalid formula for groups
>  > lme.mod = lme(y ~ selection * males * (month-1), random = ~month,
> testdat)
>  Error in getGroups.data.frame(dataMix, groups) :
>   Invalid formula for groups
>
>  I copy/paste the datset below, in case it makes things clearer.
>
>  Thanks,
>
>  Federico

I tried the code at the top of this message--it did not work for me.
The example uses some unfortunate code.  For example, it is not a good
idea to have a data frame 'lme' and a function name 'lme'.  Also,
there are vector objects a, b, and c.  These vectors are then put into
a data frame x and then the lme call refers to 'factor(a)', but is
this the vector a or the column a in the data frame x?  It is a
confusing example.

I have several times found that lme works a lot better with
groupedData objects than data frames.  (Adds confusion in my opinion,
but has some nice features such as groupedData plot methods).

For your data, try this:

d=read.table("c:/data.txt",header=TRUE)
d2=groupedData(y~selection|block, data=d)
mod=lme(y ~ selection * males * month-1, random = ~month, d2)
anova(mod)


Kevin Wright




More information about the R-sig-mixed-models mailing list