Remove some factor-interaction terms from estimation

旧街凉风 提交于 2021-02-10 07:10:12

问题


I'd like to remove certain factor interactions from an estimation. Here's an example with generated data from an imaginated labour market (I uploaded it here: http://pastebin.com/raw.php?i=EcMEVqUC)

s <- source("http://pastebin.com/raw.php?i=EcMEVqUC")$value

lm(income ~ age + cit * prof, data=s)

In this example economy, foreigners are not allowed to work in the public sector, therefore citforeign:profofficial is NA. Therefore I would like to exclude the interaction term of citforeign:profofficial. But keep all other interactions.

As I understand factors as multiple dummy variables stored in one column I don't think there's a logic problem with that?

(How) can I achieve this?

[edit]
A one step-solution would be great as I would want to use it with stepAIC()


回答1:


Use function update.

model1 <- lm(income ~ age + cit * prof, data=s)
model2 <- update(model1, . ~ . - citforeign:profofficial)


来源:https://stackoverflow.com/questions/16914249/remove-some-factor-interaction-terms-from-estimation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!