Linear model with constraints, [R]

I am new to R and I have the following problem:

I have a simple two-factor linear model:

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

And I want to put restrictions on SUM coefficients factor1 = 0, the same for factor2.

None of the guides provide clues on how to do this.

I found a link to a similar problem here , but it is different, and I could not figure out how to change it ...

+3
source share
1 answer

This is described in Chapter 6 MASSES (Modern Applied Statistics with S). Use an argument contrasts lm(see examples ?contr.sumand ?model.matrix.default).

+2
source

Source: https://habr.com/ru/post/1767021/


All Articles