Tell me more ×
Cross Validated is a question and answer site for statisticians, data analysts, data miners and data visualization experts. It's 100% free, no registration required.

Lets say I am regressing Y on X1 and X2, where X1 is a numeric variable and X2 is a factor with four levels (A:D). Is there any way to write the linear regression function lm(Y ~ X1 + as.factor(X2)) so that I can choose a particular level of X2 -- say, B -- as the baseline?

share|improve this question

1 Answer

up vote 11 down vote accepted

You can use relevel() to change the baseline level of your factor. For instance,

> g <- gl(3, 2, labels=letters[1:3])
> g
[1] a a b b c c
Levels: a b c
> relevel(g, "b")
[1] a a b b c c
Levels: b a c
share|improve this answer
Right on the money. Thanks, chl. – user3671 Mar 14 '11 at 9:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.