R update()交互项未删除
问题:我打算用交互项拟合一个线性模型。在估计“完整”模型之后,我想删除不重要的交互项。但是,在我的模型上使用函数update(lm(),.~-interaction)后,什么都没有发生。请帮忙 数据:R update()交互项未删除,r,R,问题:我打算用交互项拟合一个线性模型。在估计“完整”模型之后,我想删除不重要的交互项。但是,在我的模型上使用函数update(lm(),.~-interaction)后,什么都没有发生。请帮忙 数据: 库(车) 数据(声望) Prestige_compl女性:typewc不是实际的互动术语。真正的互动是女性:类型分解为2个系数,因为类型是一个包含3个类别的因素。请记住,伪变量(即使在交互中)的含义始终是类别和默认类别之间的差异。仅删除一个类别可能会改变“默认”类别的效果-因此,如果仅从模型中删除
库(车)
数据(声望)
Prestige_compl女性:typewc不是实际的互动术语。真正的互动是女性:类型分解为2个系数,因为类型是一个包含3个类别的因素。请记住,伪变量(即使在交互中)的含义始终是类别和默认类别之间的差异。仅删除一个类别可能会改变“默认”类别的效果-因此,如果仅从模型中删除几个类别,则基本上没有一致的方法来解释交互(或虚拟变量)。您应该删除所有类别或保留所有类别
如果你使用
modR1 <- update(modR0, .~. -women:type)
modR1嗨,谢谢你的回答。我真的很感激。
modR0 <- lm(prestige ~
income +
education +
women +
income * type +
education * type +
women * type ,
data = Prestige_compl)
# fit a linear model with interaction terms
summary.lm(modR0)
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -5.822e+00 7.311e+00 -0.796 0.42803
income 4.692e-03 6.691e-04 7.013 5.00e-10 ***
education 1.625e+00 9.163e-01 1.773 0.07971 .
women 1.343e-01 4.656e-02 2.885 0.00494 **
typeprof 2.436e+01 1.351e+01 1.803 0.07496 .
typewc -2.178e+01 1.727e+01 -1.261 0.21081
income:typeprof -4.144e-03 7.132e-04 -5.810 1.03e-07 ***
income:typewc -7.527e-04 1.814e-03 -0.415 0.67924
education:typeprof 1.512e+00 1.235e+00 1.224 0.22423
education:typewc 2.123e+00 2.190e+00 0.970 0.33491
women:typeprof -1.601e-01 6.506e-02 -2.460 0.01588 *
women:typewc 2.893e-02 1.117e-01 0.259 0.79619
modR1 <- update(modR0, .~. -women:typewc)
summary.lm(modR1)
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -5.822e+00 7.311e+00 -0.796 0.42803
income 4.692e-03 6.691e-04 7.013 5.00e-10 ***
education 1.625e+00 9.163e-01 1.773 0.07971 .
women 1.343e-01 4.656e-02 2.885 0.00494 **
typeprof 2.436e+01 1.351e+01 1.803 0.07496 .
typewc -2.178e+01 1.727e+01 -1.261 0.21081
income:typeprof -4.144e-03 7.132e-04 -5.810 1.03e-07 ***
income:typewc -7.527e-04 1.814e-03 -0.415 0.67924
education:typeprof 1.512e+00 1.235e+00 1.224 0.22423
education:typewc 2.123e+00 2.190e+00 0.970 0.33491
women:typeprof -1.601e-01 6.506e-02 -2.460 0.01588 *
women:typewc 2.893e-02 1.117e-01 0.259 0.79619
modR1 <- update(modR0, .~. -women:type)