[R] contrats hardcoded in aov()?

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Jun 23 16:40:25 CEST 2005


The source code actually says

         ##  helmert contrasts can be helpful: do we want to force them?
         ##  this version does for the Error model.
         opcons <- options("contrasts")
         ....

and do note it is unset again a few lines later.  (Listing a function 
inside R is not giving you the `source code'.)

So Helmert contrasts are only used for computing the strata, nothing to do 
with your comment as the user never gets to see anything other than the 
projections onto strata.  Having a nearly orthogonal parametrization helps 
numerical stability in e.g. establishing if projections are orthogonal.

On Thu, 23 Jun 2005, RenE J.V. Bertin wrote:

> Hello,
>
> I was just having a look at the aov function source code, and see that 
> when the model used does not have an Error term, Helmert contrasts are 
> imposed:

If this is really the `source code' as you claim, why did you remove the 
very helpful comment?

>    if (is.null(indError)) {
> ...
>   }
>    else {
>        opcons <- options("contrasts")
>        options(contrasts = c("contr.helmert", "contr.poly"))
>        on.exit(options(opcons))
> ...
>
>
> My reading of several contributed user guides' sections on ANOVA is that 
> Helmert contrasts are not intuitive at all and best avoided by 
> non-expert users. This explains why I didn't see any influence of the 
> various contrast settings on my results, and I wonder why this local 
> shadowing of global settings is done?

As others have noted:

1) The AoV itself does not depend on the coding used.

2) Some other things you can do with an aov fit do, and there you want an
orthogonal parametrization if possible, both for ease of interpretation 
and numerical stability.

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




More information about the R-help mailing list