问题:我打算用交互项拟合线性模型。在估计“完整”模型后,我想删除不重要的交互项。但是,在我的模型上使用函数 update(lm(),.~.-interaction) 后,没有任何反应。请帮忙。
Data:
library(car)
data(Prestige)
Prestige_compl <- Prestige[complete.cases(Prestige),] #rm NA's
attach(Prestige_compl)
Model:
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
Rm 不显着交互作用项:
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
为什么应该删除的交互项仍然存在?
Women:typewc 并不是实际的交互术语。真正的交互是 Women:type,它分解为 2 个系数,因为 type 是一个包含 3 个类别的因素。请记住,虚拟变量的含义(即使在交互中)始终是类别和默认类别之间的差异。仅删除一个类别可能会改变“默认”类别的效果 - 因此,如果您仅从模型中删除几个类别,则基本上没有一致的方法来解释交互(或虚拟变量)。您应该删除所有类别或保留所有类别。
如果你使用
modR1 <- update(modR0, .~. -women:type)
交互项将与其所有类别一起删除。但请注意,某些系数实际上具有统计显着性
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)