[R] controling omitted category in factor()

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Apr 3 14:48:35 CEST 2007


model.matrix() does this following the instructions you give it 
(ultimately via options("contrasts") about how to encode a factor variable 
(and this is also nothing to do with 'factor()', and factors have 'levels' 
not 'categories', a completely different concept in S but not used 
nowadays in R).

Without an example (see below) we cannot be sure, but probably you are 
using the default options setting of 'contr.treatment' and not specifying 
'contrasts' in your call to lm() (if indeed you are using lm()).  See its 
help page and that of 'relevel' for how to change the base level.

On Mon, 2 Apr 2007, toby909 at gmail.com wrote:

> Hi All
>
> How can I specify which category R should omit when running a linear 
> model with categorical predictors? I saw it omits the first category by 
> default, but I like to have the 3rd category omitted.
>
> Thanks for your hints.

You seem to have the wrong ends of several ideas.  Please study 'An 
Introduction to R' and then a good book (and Chapter 6 of MASS4 is Dr 
Venables' definitive treatment of this area).

> Toby
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.


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