[R] type III ANOVA for a nested linear model

Peter Dalgaard P.Dalgaard at biostat.ku.dk
Tue Jul 10 13:54:35 CEST 2007


Carsten Jaeger wrote:
> Hello,
>
> is it possible to obtain type III sums of squares for a nested model as
> in the following:
>
> lmod <- lm(resp ~ A * B + (C %in% A), mydata))
>
> I have tried
>
> library(car)
> Anova(lmod, type="III")
>
> but this gives me an error (and I also understand from the documentation
> of Anova as well as from a previous request
> (http://finzi.psych.upenn.edu/R/Rhelp02a/archive/64477.html) that it is
> not possible to specify nested models with car's Anova).
>
> anova(lmod) works, of course.
>
> My data (given below) is balanced so I expect the results to be similar
> for both type I and type III sums of squares. But are they *exactly* the
> same? The editor of the journal which I'm sending my manuscript to
> requests what he calls "conventional" type III tests and I'm not sure if
>   
> can convince him to accept my type I analysis.
In balanced designs, type I-IV SSD's are all identical. However, I don't think the model does what I think you think it does. 

Notice that "nesting" is used with two diferent meanings, in R it would be that the codings of C only makes sense within levels of A - e.g. if they were numbered 1:3 within each group, but with C==1 when A==1 having nothing to do with C==1 when A==2.  SAS does something. er. else...

What I think you want is a model where C is a random terms so that main effects of A can be tested, like in

> summary(aov(resp ~ A * B + Error(C), dd))

Error: C
          Df  Sum Sq Mean Sq F value Pr(>F)
A          2  33.123  16.562  0.4981 0.6308
Residuals  6 199.501  33.250

Error: Within
          Df Sum Sq Mean Sq F value   Pr(>F)
B          1 915.21  915.21 83.7846 9.57e-05 ***
A:B        2  16.13    8.07  0.7384   0.5168
Residuals  6  65.54   10.92
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1


(This is essentially the same structure as Martin Bleichner had earlier today, also @web.de. What is this? an epidemic? ;-))


-- 
   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



More information about the R-help mailing list