如何在R中使用卡方检验来检验指数分布

3

在我的数据集中,我有15个观测值,并且我想测试这个分布是否可以用速率为0.54的指数分布来表示。变量x如下:

table(x)
x
0  1  2  4  5  7  8 10 
2  1  4  2  2  2  1  1 

有没有想法如何在R中实现这个?

1
这不是一个重复的@akrun,至少你提供的链接没有使用卡方检验来确定数据是否来自特定分布。 - Sandipan Dey
2
@akrun 抱歉,但我不认为这是一个重复的问题!请仔细阅读问题。 - brock
@SandipanDey 这是别人转发了重复的链接并标记了它。这就是全部。 - akrun
2个回答

1
我们可以尝试类似这样的东西。
set.seed(1)
observed <- c(2,  1,  4,  2,  2,  2,  1,  1)
prob.exp <- dexp(c(0,  1,  2,  4,  5,  7,  8, 10), rate=0.54) # prob for the exp dist. variable for the values
chisq.test(observed, p=prob.exp, rescale.p = TRUE)
#X-squared = 73.523, df = 7, p-value = 2.86e-13

我们也可以尝试这样做(附带理论定义):
set.seed(1)
observed <- c(2,  1,  4,  2,  2,  2,  1,  1)
prob.exp <- dexp(c(0,  1,  2,  4,  5,  7,  8, 10), rate=0.54)
prob.exp <- prob.exp / sum(prob.exp) # normalize
expected <- sum(observed)*prob.exp
# expected frequency of the values
chisq.stat <- sum((observed-expected)^2/expected)
# [1] 73.52297
1-pchisq(sum(chisq.stat),df=8-1)
# [1] 2.859935e-13

他们确切地给出了相同的结果,正如预期的那样(适合度检验的零假设被拒绝,因此数据不来自分布)。

1
您可以测试数值“名称”和该值表的观察值之间的对数链接(即在测量水平上的指数分布),并使用log(rate)的偏移量来涵盖内容。如果添加log(rate)的偏移量具有截距明显不为0,则特定假设将被拒绝(而不是...)。
summary( glm( vals ~ nm+offset(rep(0.54, 8)) ,family=poisson))

Call:
glm(formula = vals ~ nm + offset(rep(0.54, 8)), family = poisson)

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-0.9762  -0.3363  -0.1026   0.1976   1.1088  

Coefficients:
            Estimate Std. Error z value Pr(>|z|)
(Intercept)  0.36468    0.40787   0.894    0.371
nm          -0.06457    0.08027  -0.804    0.421

(Dispersion parameter for poisson family taken to be 1)

    Null deviance: 3.3224  on 7  degrees of freedom
Residual deviance: 2.6593  on 6  degrees of freedom
AIC: 26.38

Number of Fisher Scoring iterations: 4

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接