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.
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 >
Thomas Petzoldt wrote:> 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.I'm not sure what model you want to fit here. To specify a random effect in lme you need both a grouping factor and a model matrix. The error message indicates that lme is unable to determine a grouping factor. It would be correct syntax if you added a single level factor to the data frame and used that but then the model fit would fail because you would be trying to estimate a variance in a model where there is no variation in the term. It seems to me that you are trying to estimate parameters in a mixed-effects model without any random effects and lme can't do that.