[R-sig-ME] Error message in Pedigreemm

David Duffy David.Duffy at qimr.edu.au
Mon Feb 18 02:08:11 CET 2013


On Mon, 18 Feb 2013, Napo Vargas wrote:

> Error in function (fr, FL, start, REML, verbose)  :
>  Number of levels of a grouping factor for the random effects
> must be less than the number of observations

Whether you see this (in your case, spurious) error message depends on 
what version of lme4 you have installed.  A quick hack is

my_lmer_finalize <- edit(lme4:::lmer_finalize)

change

     if (!(length(levels(dm$flist[[1]])) < length(Y)))
         stop(paste("Number of levels of a grouping factor for the random effects",
             "must be less than the number of observations", sep = "\n"))

to

     if (!(length(levels(dm$flist[[1]])) <= length(Y)))
         stop(paste("Number of levels of a grouping factor for the random effects",
             "must be less or equal to the number of observations", sep = "\n"))

and save.  Then

my_pedigreemm <- edit(pedigreemm)

and change the fifth last line from

    else lmer_finalize, lmf)

to

    else my_lmer_finalize, lmf)

Now,

system.time(AM1 <-
my_pedigreemm(WS~WT+Sex+(1|ID),data=cdata, pedigree=list(ID=ped1)))

should work.  You could alter this check permanently when you install 
lme4 by editing the appropriate file.

BTW, with lme4, you can leave all your variables of interest in cdata 
eg cdata$Sex <- factor(cdata$Sex).


David Duffy,



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