tags:

views:

74

answers:

1

Hi all,

I'm quite new to R and I have a following problem:

I have a simple 2-factor linear model:

Rate~factor1 + factor2 //factor1 has 8 categorical values, factor2 has 6 categories;
model1 <- lm(Rate~factor1+factor2, data=myData)

And want to put constraints SUM of factor1 coefficients = 0, the same for factor2.

None of the manuals gives any clue how to do this..

I found a link to similar problem here but it is different and I couldnt figure out how to modify it...

+1  A: 

It's described in chapter 6 of MASS (Modern Applied Statistics with S). Use the contrasts arg of lm (take a look at ?contr.sum and ?model.matrix.default for examples).

Joshua Ulrich
Thanks a lot. I tried it - it did not make the sum of coefficients = 0, but did minimize it (now is 0.2 for 1 factor and 0.08 for the other)
Vytautas
Is there a way to force ==0 condition ?
Vytautas
My answer is the way to force it. If the sums are 0.2 for `factor1` and 0.08 for `factor2`, then the value for the last level of `factor1` is -0.2 and the value for the last level of `factor2` is -0.08. Notice that your regression output is missing a factor level... This is also stated in the link contained in the answer you accepted on stats.stackexchange.com...
Joshua Ulrich