On Wed, 27 Nov 2002, Jane McFerren wrote:
> I have a question regarding contrasts in linear models. I have a factor
variable
> age with 4 levels, in the output of the linear model I want a coefficient
for each
> level of age.
You can't get that, only 3 contrasts can exist for a 4-level factor.
By default you get second - first, third - first and fourth - first.
> I have made sure that age is a factor but am unsure how to put age into the
> model to ensure the model knows it is a factor an dto display all levels.
>
> I have tried doing
>
> fit<-lm(y~C(age)+sex.....) (the dot bits are the rest of the function
which I have
> cut out as its not important here)
>
> but it only displays age as though it has one level
Is age really a factor (try is.factor)?
> what am I doing wrong and how can I get R to recognise its a factor?
as.factor(age) will ensure that.
--
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 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at
stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._