Karl Knoblick
2007-Jun-28 11:08 UTC
[R] aov and lme differ with interaction in oats example of MASS?
Dear R-Community! The example "oats" in MASS (2nd edition, 10.3, p.309) is calculated for aov and lme without interaction term and the results are the same. But I have problems to reproduce the example aov with interaction in MASS (10.2, p.301) with lme. Here the script: library(MASS) library(nlme) options(contrasts = c("contr.treatment", "contr.poly")) # aov: Y ~ N + V oats.aov <- aov(Y ~ N + V + Error(B/V), data = oats, qr = T) summary(oats.aov) # now lme oats.lme<-lme(Y ~ N + V, random = ~1 | B/V, data = oats) anova(oats.lme, type="m") # Ok! # aov:Y ~ N * V + Error(B/V) oats.aov2 <- aov(Y ~ N * V + Error(B/V), data = oats, qr = T) summary(oats.aov2) # now lme - my trial! oats.lme2<-lme(Y ~ N * V, random = ~1 | B/V, data = oats) anova(oats.lme2, type="m") # differences!!! (except of interaction term) My questions: 1) Is there a possibility to reproduce the result of aov with interaction using lme? 2) If not, which result of the above is the correct one for the oats example? Thanks a lot! Karl __________________________________ Alles was der Gesundheit und Entspannung dient. BE A BETTER MEDIZINMANN! www.yahoo.de/clever
Peter Dalgaard
2007-Jun-28 12:27 UTC
[R] aov and lme differ with interaction in oats example of MASS?
Karl Knoblick wrote:> Dear R-Community! > > The example "oats" in MASS (2nd edition, 10.3, p.309) is calculated for aov and lme without interaction term and the results are the same. > But I have problems to reproduce the example aov with interaction in MASS (10.2, p.301) with lme. Here the script: > > library(MASS) > library(nlme) > options(contrasts = c("contr.treatment", "contr.poly")) > # aov: Y ~ N + V > oats.aov <- aov(Y ~ N + V + Error(B/V), data = oats, qr = T) > summary(oats.aov) > # now lme > oats.lme<-lme(Y ~ N + V, random = ~1 | B/V, data = oats) > anova(oats.lme, type="m") # Ok! > # aov:Y ~ N * V + Error(B/V) > oats.aov2 <- aov(Y ~ N * V + Error(B/V), data = oats, qr = T) > summary(oats.aov2) > # now lme - my trial! > oats.lme2<-lme(Y ~ N * V, random = ~1 | B/V, data = oats) > anova(oats.lme2, type="m") > # differences!!! (except of interaction term) > > My questions: > 1) Is there a possibility to reproduce the result of aov with interaction using lme? > 2) If not, which result of the above is the correct one for the oats example? >The issue is that you are using marginal tests which will do strange things when contrasts are not coded "right", and in particular treatment contrasts are not. Switch to e.g. contr.helmert and the results become similar. Marginal tests of main effects in the presence of interaction is not necessarily a good idea and they have been debated here and elsewhere a number of times before. People don't agree entirely, but the dividing line is essentially whether it is uniformly or just mostly a bad idea. It is essentially the discussion of type III SS.> fortune("type III")Some of us feel that type III sum of squares and so-called ls-means are statistical nonsense which should have been left in SAS. -- Brian D. Ripley s-news (May 1999)> Thanks a lot! > Karl > > > __________________________________ Alles was der Gesundheit und Entspannung dient. BE A BETTER MEDIZINMANN! www.yahoo.de/clever > > ______________________________________________ > 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. >-- O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Prof Brian Ripley
2007-Jun-28 13:02 UTC
[R] aov and lme differ with interaction in oats example of MASS?
On Thu, 28 Jun 2007, Karl Knoblick wrote:> Dear R-Community! > > The example "oats" in MASS (2nd edition, 10.3, p.309) is calculated for aov and lme without interaction term and the results are the same. > But I have problems to reproduce the example aov with interaction in MASS (10.2, p.301) with lme. Here the script: > > library(MASS) > library(nlme) > options(contrasts = c("contr.treatment", "contr.poly"))That is the problem. You need true contrasts, so use contr.helmert. When I did so I got the same results from lme and aov for the anovas. The question of what a 'marginal' AoV means without orthogonality is moot. The sequential version is fine here.> # aov: Y ~ N + V > oats.aov <- aov(Y ~ N + V + Error(B/V), data = oats, qr = T) > summary(oats.aov) > # now lme > oats.lme<-lme(Y ~ N + V, random = ~1 | B/V, data = oats) > anova(oats.lme, type="m") # Ok! > # aov:Y ~ N * V + Error(B/V) > oats.aov2 <- aov(Y ~ N * V + Error(B/V), data = oats, qr = T) > summary(oats.aov2) > # now lme - my trial! > oats.lme2<-lme(Y ~ N * V, random = ~1 | B/V, data = oats) > anova(oats.lme2, type="m") > # differences!!! (except of interaction term) > > My questions: > 1) Is there a possibility to reproduce the result of aov with interaction using lme? > 2) If not, which result of the above is the correct one for the oats example? > > Thanks a lot! > Karl-- 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