[R] lme: error message with random=~1

Dimitris Rizopoulos dimitris.rizopoulos at med.kuleuven.ac.be
Wed Jan 5 11:43:47 CET 2005


Hi Thomas,

"random=~1" works if your data frame is in "groupedData" format, check 
this:

# Orthodont is in groupedData format
fm1 <- lme(distance~age+Sex, data=Orthodont, random=~1)
#####
dat <- as.data.frame(Orthodont)
fm2.1 <- lme(distance~age+Sex, data=dat, random=~1)

`dat' is an ordinary data.frame and thus random=~1 doesn't work. But 
this works:

fm2.2 <- lme(distance~age+Sex, data=dat, random=~1|Subject)
# you declare the grouping factor

I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/336899
Fax: +32/16/337015
Web: http://www.med.kuleuven.ac.be/biostat
     http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm


----- Original Message ----- 
From: "Thomas Petzoldt" <thpe at hhbio.wasser.tu-dresden.de>
To: "R-Help" <r-help at stat.math.ethz.ch>
Sent: Wednesday, January 05, 2005 11:11 AM
Subject: [R] lme: error message with random=~1


> Hello,
>
> I have an unbalanced mixed model design with two fixed effects
> "site" (2 levels) and "timeOfDay" (4 levels) and two random effects
> "day" (3 consecutive days) and "trap" (6 unique traps, 3 per site).
>
> The dependent variable is the body length ("BL") of insect larvae 
> from 7 to 29 individuals per trap (104 individuals in total).
>
> To account for pseudo replication I used nlme (or lme4 as suggested 
> for crossed random factors). The results indicate, that the random 
> effects are very small, so I followed the lme example and tried to 
> fit a model with random=~1.
>
> Unfortunately I got the following error message:
>
> Error in getGroups.data.frame(dataMix, groups) :
> Invalid formula for groups
>
> I suppose, that it would be redundant (and confusing to the reader) 
> if we leave unnecessary random effects in the model, but due to 
> pseudo replication it may be an offense if we simply ignore it and 
> use lm.
>
> Reading the respective chapters in Pinheiro & Bates, Venables & 
> Ripley and Crawley several times, I found no example for this 
> situation. Is there a common way how to handle this?
>
> Thomas P.
>
> PS: I can provide a full example, if necessary.
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list