【发布时间】:2014-04-12 09:27:45
【问题描述】:
问题:我打算用交互项拟合线性模型。在估计“完整”模型后,我想删除不重要的交互项。但是,在我的模型上使用函数 update(lm(),.~.-interaction) 后,什么也没有发生。请帮忙。
数据:
library(car)
data(Prestige)
Prestige_compl <- Prestige[complete.cases(Prestige),] #rm NA's
attach(Prestige_compl)
型号:
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
为什么应该删除的交互项仍然存在?
【问题讨论】:
标签: r