AER离散度test()与R中的负二项式离散度相反

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

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

  • 通过AER软件包进行的dispersiontest()。
  • [使用(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的色散。但是,dispersiontest()在5.5上具有明显的过度分散。如果我没有记错的话,AER并不是参数测试,那么我们只能知道是否存在过度/分散不足。然而,这两种方法是矛盾的。

有人知道为什么吗?

r statistics poisson
1个回答
0
投票

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

在负二项式中,色散1.069362没有意义,您需要查看负二项式()中的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)
© www.soinside.com 2019 - 2024. All rights reserved.