【问题标题】:R update() interaction term not droppedR update() 交互项未删除
【发布时间】: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


    【解决方案1】:

    the women:typewc 并不是真正的交互术语。真正的交互是 women:type 分解为 2 个系数,因为 type 是一个包含 3 个类别的因素。请记住,虚拟变量的含义(即使在交互中)始终是类别和默认类别之间的差异。仅删除一个类别可能会改变“默认”类别的效果 - 因此,如果您仅从模型中删除几个类别,则基本上没有一致的方法来解释交互(或虚拟变量)。您应该删除所有类别或保留所有类别。

    如果你使用

     modR1 <- update(modR0, .~. -women:type)
    

    交互项及其所有类别将被删除。但请注意,其中一些系数实际上具有统计显着性

    【讨论】:

    • 您好,谢谢您的回答。我真的很感激。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-02-27
    • 1970-01-01
    • 1970-01-01
    • 2022-11-29
    • 2016-06-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多