# [R] Possible bug in lmer nested analysis with factors

Yan Wong h.y.wong at leeds.ac.uk
Fri Sep 16 19:57:44 CEST 2005

```On 16 Sep 2005, at 17:12, Doran, Harold wrote:

> I think you might have confused lme code with lmer code. Why do you
> have
> c/d in the random portion?

Apologies. I obviously have done something of the sort. I assumed
that the 'random' assignment in lme could just be incorporated into
an lmer call by placing it in brackets and removing the ~, so that

lme(a ~ b, random= ~ 1|c/d)

would be equivalent to

lmer(a ~ b + (1|c/d))

Is there a good guide somewhere to lmer calling conventions? I
obviously don't understand them. As you can see, I would like to nest
d within c, (and actually, c is nested in b too).

Perhaps it would be better with some explanation of the Crawley data.
There are 3 fixed drug treatments ('b') given to 2 rats (6 rats in
all: 'c'), and 3 samples ('d') are taken from each of the rat's
livers, with some response variable recorded for each sample ('a':
here just allocated a Normal distribution for testing purposes). I.e.
c and d are random effects, with d %in% c and c %in% b.

He analyses it via
aov(a ~ b+c+d+Error(a/b/c))

I'm wondering what the lme and lmer equivalents are. I've been told
that a reasonable form of analysis using lme is

a<-rnorm(36);b<-rep(1:3,each=12);d<-rep(1:3,each=2,6)
c <- rep(1:6, each=6) #use unique labels for each rat ## I got this
wrong in my previous example
model1 <- lme(a ~ b, random= ~ 1|c/d)

Which gives what looks to be a reasonable output (but I'm new to all
this mixed modelling stuff). How would I code the same thing using lmer?

> I think what you want is
>
>> lmer(a ~ b + (1 | c)+(1|d))
>>
>
> Which gives the following using your data

I'm not sure this is what I wanted to do. But thanks for the all the
help.

Yan

```