[R] Order of terms in formula changes aov() results

Weidong Gu anopheles123 at gmail.com
Fri Mar 23 16:55:24 CET 2012


Hi,

It seems that you have an unbalanced anova case which can be
complicated in interpretation. This question has been addressed in the
list you can search of previous mails. Basically, for unbalanced data
(or unorthorgonal), estimates of SS of a factor depends on other
factors. Type I SS (which is the method by aov) is a sequential
method. Therefore, order of variables in the model matters. For your
situation, you may want to use type II or type III SS (check Anova in
car) because they are estimates adjusted for other variables in the
model, thus order-independent.

Weidong Gu

On Thu, Mar 22, 2012 at 5:06 PM, Stuart Luppescu <slu at ccsr.uchicago.edu> wrote:
> Hello, This one is very perplexing. I have teacher observation data,
> with factors teacher ID, observer ID, component, grade and subject. When
> I do this,
>
> aov(data=ratings.prin.22, rating ~ obsid.f + tid.f + subject.f + grade.f + comp.f)
>
> I get this:
>
> Terms:
>                  obsid.f     tid.f   grade.f    comp.f Residuals
> Sum of Squares  306.23399 221.38173   1.70000  14.52831 279.05780
> Deg. of Freedom        74        87         2         9      1406
>
> This looks right. There are about 82 observers so 74 degrees of freedom
> for obsid.f is OK. But if I do this (just reordering the terms in the
> formula):
>
> aov(data=ratings.prin.22, rating ~ comp.f + grade.f + subject.f + tid.f + obsid.f)
>
> I get this:
>
> Terms:
>                  comp.f  grade.f subject.f    tid.f  obsid.f Residuals
> Sum of Squares   15.0923  23.3968    5.9982 499.3568   0.0000  279.0578
> Deg. of Freedom        9        4         4      152        3      1406
>
> Now obsid.f only has 3 degrees of freedom and the sum of squares is
> 0.00. Could this be due to the unbalanced design?
>
> If someone can explain this to me I would be very grateful.
>
> --
> Stuart Luppescu -=- slu .at. ccsr.uchicago.edu
> University of Chicago -=- CCSR
> 才文と智奈美の父 -=-    Kernel 3.2.1-gentoo-r2
> Tony Plate: There looks to be a typo in the R-exts
>  manual: [...] Peter Dalgaard: 'svn blame' tells me
>  that this was Brian's addition in rev.35362 [...]
>  Brian D. Ripley: I prefer 'svn praise' myself.
>  Peter Dalgaard: Or 'svn annotate'. I think it
>  depends on what I'm looking for, plus the risk
>  that the author (perpetrator, contributor) might
>  be me...    -- Tony Plate, Peter Dalgaard and
>  Brian D. Ripley (about a typo in the
>
> ______________________________________________
> R-help at r-project.org 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.



More information about the R-help mailing list