1

(I'm working in R) If I want to run a linear model on a dependent variable as a function of a categorical variable with 3 levels (l=3), and I want to use orthogonal contrasts, will I always have to establish l-1 contrasts?

Suppose I want to compare level 1 to level 2, and level 1 to level 3. Assuming the levels are called "1", "2", and "3", I would use contrasts:

c(-0.5,0.5,0),  c(-0.5,0,0.5)

That is l-1 contrasts. But what if I also want to compare level 2 to level 3? Would I have to build another linear model only for that?

kjetil b halvorsen
  • 63,378
  • 26
  • 142
  • 467
HernanLG
  • 201
  • 1
  • 9

1 Answers1

2

Assuming you have an intercept in the model, if you use more than l-1 contrsts your model matrix will be singular. So you cannot do that.

But, after fitting the model you can test the contrasts you want, you will find that a contrast comparing levels 2 and 3 is a linear combination of the two contrasts you have given. There are many similar posts on this site, so look at for instance Categorical variable coding to compare all levels to all levels

kjetil b halvorsen
  • 63,378
  • 26
  • 142
  • 467