Dear r-helpers, Can anyone suggest why lm() doesn't complain here: summary(osss.lm1 <- lm(logOdds ~ c.setSize %in% task, data = osss)) whereas in package:nlme (and in package:lme4) osss.lmL <- lmList(logOdds ~ c.setSize %in% task | subj, data = osss) # Error in `contrasts<-`(`*tmp*`, value = "contr.treatment") : # contrasts can be applied only to factors with 2 or more levels If it were because for each subj I have only 1 datum per cell: with(subset(osss, osss$subj == '42'), table(setSize, task)) # task # setSize os ss # 2 1 1 # 3 1 1 # 4 1 1 # 5 1 1 # 6 1 0 # 7 1 0 then osss.lm1 <- lm(logOdds ~ c.setSize %in% task, data = subset(osss, osss $subj == '42')) should fail as well, but I get anova(osss.lm1) # Analysis of Variance Table # # Response: logOdds # Df Sum Sq Mean Sq F value Pr(>F) # c.setSize:task 2 6.8269 3.4134 1.9976 0.2059 # Residuals 7 11.9612 1.7087 _____________________________ Professor Michael Kubovy University of Virginia Department of Psychology USPS: P.O.Box 400400 Charlottesville, VA 22904-4400 Parcels: Room 102 Gilmer Hall McCormick Road Charlottesville, VA 22903 Office: B011 +1-434-982-4729 Lab: B019 +1-434-982-4751 Fax: +1-434-982-4766 WWW: http://www.people.virginia.edu/~mk9y/
Michael Kubovy napsal(a):> Dear r-helpers, > > Can anyone suggest why lm() doesn't complain here:No, we can't since we don't have your data and we have no idea what logOdds, task and osss are... The error given below says you are trying to model the effect of a factor, which however only has 1 level. So maybe lm() didn't treat your variable(s) as factor(s) while lmList does? Petr> > summary(osss.lm1 <- lm(logOdds ~ c.setSize %in% task, data = osss)) > > whereas in package:nlme (and in package:lme4) > > osss.lmL <- lmList(logOdds ~ c.setSize %in% task | subj, data = osss) > # Error in `contrasts<-`(`*tmp*`, value = "contr.treatment") : > # contrasts can be applied only to factors with 2 or more levels > > If it were because for each subj I have only 1 datum per cell: > > with(subset(osss, osss$subj == '42'), table(setSize, task)) > # task > # setSize os ss > # 2 1 1 > # 3 1 1 > # 4 1 1 > # 5 1 1 > # 6 1 0 > # 7 1 0 > > then > > osss.lm1 <- lm(logOdds ~ c.setSize %in% task, data = subset(osss, osss > $subj == '42')) > > should fail as well, but I get > > anova(osss.lm1) > # Analysis of Variance Table > # > # Response: logOdds > # Df Sum Sq Mean Sq F value Pr(>F) > # c.setSize:task 2 6.8269 3.4134 1.9976 0.2059 > # Residuals 7 11.9612 1.7087 > > > _____________________________ > Professor Michael Kubovy > University of Virginia > Department of Psychology > USPS: P.O.Box 400400 Charlottesville, VA 22904-4400 > Parcels: Room 102 Gilmer Hall > McCormick Road Charlottesville, VA 22903 > Office: B011 +1-434-982-4729 > Lab: B019 +1-434-982-4751 > Fax: +1-434-982-4766 > WWW: http://www.people.virginia.edu/~mk9y/ > > ______________________________________________ > 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 > and provide commented, minimal, self-contained, reproducible code. >-- Petr Klasterecky Dept. of Probability and Statistics Charles University in Prague Czech Republic
The short answer is that lm() is written more robustly. I don't think either should fail, but without a reproducible example it is hard to tell. On Mon, 2 Apr 2007, Michael Kubovy wrote:> Dear r-helpers, > > Can anyone suggest why lm() doesn't complain here: > > summary(osss.lm1 <- lm(logOdds ~ c.setSize %in% task, data = osss)) > > whereas in package:nlme (and in package:lme4) > > osss.lmL <- lmList(logOdds ~ c.setSize %in% task | subj, data = osss) > # Error in `contrasts<-`(`*tmp*`, value = "contr.treatment") : > # contrasts can be applied only to factors with 2 or more levels > > If it were because for each subj I have only 1 datum per cell: > > with(subset(osss, osss$subj == '42'), table(setSize, task)) > # task > # setSize os ss > # 2 1 1 > # 3 1 1 > # 4 1 1 > # 5 1 1 > # 6 1 0 > # 7 1 0 > > then > > osss.lm1 <- lm(logOdds ~ c.setSize %in% task, data = subset(osss, osss > $subj == '42'))I don't know what c.setSize is, but data=osss, subset=subs=='42' is a much clear way to write this lm() call.> should fail as well, but I get > > anova(osss.lm1) > # Analysis of Variance Table > # > # Response: logOdds > # Df Sum Sq Mean Sq F value Pr(>F) > # c.setSize:task 2 6.8269 3.4134 1.9976 0.2059 > # Residuals 7 11.9612 1.7087 > > > _____________________________ > Professor Michael Kubovy > University of Virginia > Department of Psychology > USPS: P.O.Box 400400 Charlottesville, VA 22904-4400 > Parcels: Room 102 Gilmer Hall > McCormick Road Charlottesville, VA 22903 > Office: B011 +1-434-982-4729 > Lab: B019 +1-434-982-4751 > Fax: +1-434-982-4766 > WWW: http://www.people.virginia.edu/~mk9y/ > > ______________________________________________ > 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 > and provide commented, minimal, self-contained, reproducible code. >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595