[R] library(car) Anova() and Error-term in aov()

Peter Dalgaard p.dalgaard at biostat.ku.dk
Thu Aug 26 14:08:18 CEST 2004

Paul Lemmens <P.Lemmens at nici.kun.nl> writes:

> Dear all,
> Type III SS time again. This case trying to reproduce some SPSS (type
> III) data in R for a repeated measures anova with a betwSS factor
> included. As I understand this list etc, if I want type III then I can
> do
> library(car)
> Anova(lm.obj, type="III")
> But for the repeated measures anova, I need to include an Error-term
> in the aov() call (Psychology-guide from Jonathan Baron) which results
> in multiple lm() calls. Anova() does not seem capable to handle this
> situation. Or am I tackling Type III calculation, in this case with
> Error(), the wrong way (besides ignoring advice concerning Type I vs
> III)??
> For instance,
> dat <- rnorm(12)
> pp <- factor(c(rep(1:3,2), rep(4:6,2)))
> betw <- gl(2,6)
> A <- factor(rep(c(rep('a',3),rep('b',3)), 2))
> taov <- aov(dat~betw*A+Error(pp/A))
> Anova(taov, type="III") # Goes wrong with following error.
> #Error in Anova(taov, type = "III") : no applicable method for "Anova"
> Phrased differently, ?Anova says "Calculates type-II or type-III
> analysis-of-variance tables for model objects produced by 'lm' and
> 'glm'", so it's not suitable for the aovlist that aov() with
> Error()-term returns. How can I compute Type III SS for such objects?

Well, ...

In a balanced design you don't need Type III SS (because they are all
the same) --  summary(taov) will do.

In an unbalanced design, you don't want to use aov() with an Error
term. (Slightly overstated, but you certainly get to think very
closely if the unbalance is in the Error model).

I'm not actually sure what SPSS does in the case of unbalanced designs
(complete-case analysis?).

In principle, with a balanced Error model, you should be able to
extract, say, taov[[2]] and do an Anova() or drop1() on that, but it
doesn't work because the object is not really an "lm" object, even

> class(taov[[2]])
[1] "aov" "lm"

but we get things like

> model.frame(as(taov[[2]],"lm"))

   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907

More information about the R-help mailing list