Re: [R] controling omitted category in factor()

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Tue 03 Apr 2007 - 12:48:35 GMT

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

______________________________________________
R-help@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.
Received on Tue Apr 03 22:53:17 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 03 Apr 2007 - 13:30:43 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.