[R] lm with ordered factors

Prof Brian Ripley ripley at stats.ox.ac.uk
Sat Nov 22 10:51:34 CET 2003


On Sat, 22 Nov 2003 Ted.Harding at nessie.mcc.ac.uk wrote:

> Hi Folks,
> 
> No doubt a question with a well-known answer, but I'm unfortunately
> not managing to find it readily ... !
> 
> I have a quantitative variable Y and a 4-level ordered factor A
> (with very unequal numbers at the different levels, by the way).
> 
> The command
> 
>   lm(Y ~ A)
> 
> returns (amongst other stuff) an intercept, and coefficients
> A.L, A.Q and A.C for the Linear, Quadratic and Cubic effects.
> 
> I'm trying to verify how R computes A.L, A.Q and A.C (equivalently,
> and preferably, what are the definitions of these that correspond
> to how R computes them). I haven't touched whatever R's default
> settings may be for this operation.
> 
> Can some kind soul enlighten me?

?contr.poly, as the default contrasts set by options("contrasts") specify
that for ordered factors. For more details, including how R uses
contrasts, see Chapter 6 of MASS (any edition).

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