Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linear model with Constraints

Tags:

r

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 couldn't figure out how to modify it...

like image 828
Vytautas Avatar asked Aug 25 '26 10:08

Vytautas


1 Answers

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).

like image 68
Joshua Ulrich Avatar answered Aug 28 '26 04:08

Joshua Ulrich