在我的数据集中,我有15个观测值,并且我想测试这个分布是否可以用速率为0.54的指数分布来表示。变量x如下:
table(x)
x
0 1 2 4 5 7 8 10
2 1 4 2 2 2 1 1
有没有想法如何在R中实现这个?
在我的数据集中,我有15个观测值,并且我想测试这个分布是否可以用速率为0.54的指数分布来表示。变量x如下:
table(x)
x
0 1 2 4 5 7 8 10
2 1 4 2 2 2 1 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
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