[R] BEGINNER:create dummy variables

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Aug 5 09:38:52 CEST 2003

On Mon, 4 Aug 2003, Michele Grassi wrote:

> Hi.
> I want to put a categorical variables (3 levels) in my 
> logit model. I have to use 2 dummy variables for code 
> theese 3 levels. How can I transform my categorical 
> variables?

model.matrix will do this for you automatically, using the coding set in 
options("contrasts").   How are you fitting `my logit model'?  The normal 
way is to use glm(family=binomial): take a look at the script 
library/MASS/scripts/ch07.R for examples.

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