简体   繁体   中英

R programming - Linear regression (two sets of dummy variables) with equality constraints

I am currently working on the linear regression with two set of dummy variables -

model1 <- lm(y ~ factor1 + factor2, data=mydata)

where factor1 contains 30 categorical variables and factor2 contain 5 categorical variables.

I have two constraints - sum(coefficient of each factor1 * some constant term of each factor1) = 0 and sum(coefficient of each factor2 * some constant term of each factor2) = 0.

I realize that the solution is somehow related to add "contrasts" to the lm function but I don't know how to code it properly. Anyone could you please enlighten me. Or please feel free to leave your suggestion on alternative methods to work with this kind of problem

Thanks a lot.

Can you use glmc package? But I don't know how to put in the constraints.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM