r - AER分散测试()与R中的负二项式分散相矛盾

标签 r statistics poisson

我正在分析数据计数的泊松回归。泊松要求方差和均值相等,因此我正在检查离差以确保这一点。对于分散,我使用两种方法:

  • AER 包的分散测试()。
  • 使用 (glm.nb) 将色散模型检查为负二项式
> pm <- glm(myCounts ~ campaign, d, family = poisson)
> summary(pm)

Call:
glm(formula = myCounts ~ campaign, family = poisson, data = d)

Deviance Residuals: 
   Min      1Q  Median      3Q     Max  
-4.074  -1.599  -0.251   1.636   6.399  

Coefficients:
             Estimate Std. Error z value Pr(>|z|)    
(Intercept)  4.955870   0.032174  154.03   <2e-16 ***
campaign    -0.025879   0.001716  -15.08   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for poisson family taken to be 1)

    Null deviance: 428.04  on 35  degrees of freedom
Residual deviance: 195.81  on 34  degrees of freedom
AIC: 426.37

Number of Fisher Scoring iterations: 4

> dispersiontest(pm)

    Overdispersion test

data:  pm
z = 3.1933, p-value = 0.0007032
alternative hypothesis: true dispersion is greater than 1
sample estimates:
dispersion 
   5.53987 

> # Calculate dispersion with Negative Binomial
> nb_reg <- glm.nb(myCounts ~ campaign, data=d)
> summary.glm(nb_reg)

Call:
glm.nb(formula = myCounts ~ campaign, data = d, init.theta = 22.0750109, 
    link = log)

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-1.9235  -0.7083  -0.1776   0.6707   2.4495  

Coefficients:
             Estimate Std. Error t value Pr(>|t|)    
(Intercept)  4.914728   0.082327  59.697  < 2e-16 ***
campaign    -0.023471   0.003965  -5.919  1.1e-06 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for Negative Binomial(22.075) family taken to be 1.069362)

    Null deviance: 76.887  on 35  degrees of freedom
Residual deviance: 35.534  on 34  degrees of freedom
AIC: 325.76

Number of Fisher Scoring iterations: 1

如您所见,NB 提供了 1.069362 色散。然而,分散测试()结果为 5.5,具有明显的过度分散。如果我没记错的话,AER 不是参数测试,所以我们只能知道是否存在过度/不足分散。然而,这两种方法都是矛盾的。

有人知道为什么吗?

最佳答案

在 glm.nb() 中,方差参数化为 𝜇+𝜇^2/𝜃,其中 𝜇 是平均值(更多信息请参见 this discussion ),𝜃 是 theta,而在泊松中它是 ϕ * 𝜇其中 phi 是您看到的色散 5.53987。

在负二项式中,色散 1.069362没有意义,您需要查看 Negative Binomial() 内的 theta,在您的情况下为 22.075。我没有您的数据,但使用您的截距作为平均值的粗略估计:

mu = exp(4.914728)
theta = 22.0750109
variance = mu + (mu^2)/theta
variance
977.6339
variance / mu
[1] 7.173598

这会给你一些类似于你的色散的东西。您应该注意,您的色散是根据完整模型估计的,而我只是根据您的截距猜测了一个。

底线是结果并不不一致。您可以使用负二项式对数据进行建模。

下面是一个例子来说明上述关系。我们使用负二项式模拟过度分散的数据(这是最简单的):

y = c(rnbinom(100,mu=100,size=22),rnbinom(100,mu=200,size=22))
x = rep(0:1,each=100)

AER::dispersiontest(glm(y~x,family=poisson))

    Overdispersion test

data:  glm(y ~ x, family = poisson)
z = 8.0606, p-value = 3.795e-16
alternative hypothesis: true dispersion is greater than 1
sample estimates:
dispersion 
  8.200214 

粗略地说,这是通过将每个组中的方差除以每个组中的平均值得出的:

mean(tapply(y,x,var)/tapply(y,x,mean))
[1] 8.283044

您可以看到离散度显示为 1,而实际上您的数据过度离散:

    summary(MASS::glm.nb(y~x))

Call:
MASS::glm.nb(formula = y ~ x, init.theta = 21.5193965, link = log)

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-4.0413  -0.6999  -0.1275   0.5800   2.4774  

Coefficients:
            Estimate Std. Error z value Pr(>|z|)    
(Intercept)  4.66551    0.02364  197.36   <2e-16 ***
x            0.66682    0.03274   20.37   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for Negative Binomial(21.5194) family taken to be 1)

关于r - AER分散测试()与R中的负二项式分散相矛盾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61267391/

相关文章:

python - 执行 2 个样本 t 检验

r - 独立的pivot_longer

r - 如何使用自定义中断从连续变量创建分箱因子变量?

python统计分析

hibernate - 是否有一个很好的 GUI 可用于显示 Hibernate 统计信息?

r - 零膨胀泊松分布的经验和理论分布图

r - mle2 公式调用的自定义密度函数定义错误

Python Numpy 泊松回归产生错误的数字

r - 用于比较向量的用户定义的 R 函数

r - 编辑 emmeans 箭头图的侧面文本