Skip to content

Contrast problem

2 messages · Jane McFerren, Brian Ripley

#
Hi,

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.

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

what am I doing wrong and how can I get R to recognise its a factor?

Thanks
Jane

------------------------------------------------------
BA flight sale now at http://www.lycos.co.uk. 
Boston, ?129 rtn. including tax, Wednesday, 1pm
#
On Wed, 27 Nov 2002, Jane McFerren wrote:

            
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.
Is age really a factor (try is.factor)?
as.factor(age) will ensure that.