为什么我的 GLM 中的交互项系数等于 NA?

问题描述 投票:0回答:1

我运行了以下模型:

model <- glm(DV ~ IV1*IV2, data = data, family="poisson")

我收到了以下结果:

Call:
glm(formula = DV ~ IV1 * IV2, family = "poisson", 
    data = data)

Coefficients: (1 not defined because of singularities)
                   Estimate Std. Error z value Pr(>|z|)
(Intercept)        0.465506   0.053783   8.655   <2e-16
IV1            -0.005388   0.048897  -0.110    0.912
IV2         0.540514   0.032046  16.867   <2e-16
IV1:IV2        NA         NA      NA       NA
                     
(Intercept)       ***
IV1               
IV2        ***
IV1:IV2    
---
Signif. codes:  
0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for poisson family taken to be 1)

    Null deviance: 3029.4  on 2153  degrees of freedom
Residual deviance: 2705.6  on 2151  degrees of freedom
  (364 observations deleted due to missingness)
AIC: 7393.5

Number of Fisher Scoring iterations: 5

我的第一个想法是这两个变量必须共线......

table(data$IV1, data$IV2, useNA = "always")
      
          0    1 <NA>
  0     331  198    0
  1    1278  711    0
  <NA>    0    0    0

但事实似乎并非如此。

我无法在这里重现整个数据框,但我想知道人们是否知道这里会发生什么?还有什么我应该检查的吗?

这就是我使用

with()
命令时的样子:

with(survey_clean, table(IV1, IV2, DV, useNA = "always"))
, , DV = 0

     IV2
IV1   0   1
    0   0  15
    1 398  47

, , DV = 1

     IV2
IV1   0   1
    0   0  12
    1 266  85

, , DV = 2

     IV2
IV1   0   1
    0   0  50
    1 259 145

, , DV = 3

     IV2
IV1   0   1
    0   0  52
    1 131 163

, , DV = 4

     IV2
IV1   0   1
    0   0  67
    1 204 260

, , DV = NA

      IV2
IV1    0   1 <NA>
  0    331   2    0
  1     20  11    0
  <NA>   0   0    0
r model glm
1个回答
0
投票

检查

with(survey_clean, table(...))
输出的细分,我们可以看到,当
{IV1=0, IV2=0}
DV 时,
NA
条件
only
发生(即,该单元格包含 0 表示
DV
==0-4 并且是仅当
DV
NA
时才非零。因为默认情况下这些情况会被
glm()
丢弃(处理 R 中缺失数据的唯一 简单 方法是 完整案例分析,它会丢弃
 的观察结果) NA
任何模型变量中的值),模型的数据集只有三种预测变量组合(
IV[1,2]
= {0,1}、{1,0} 或 {1,1}),因此总共只能估计三个系数。

事后看来,如果你跑的话问题会更清楚

with(survey_clean, table(IV1, IV2, is.na(DV)))

(这将给出仅按

DV
是否为
NA
分隔的表格,而不是针对
DV
的每个单独值)

© www.soinside.com 2019 - 2024. All rights reserved.