Steps followed for testing :
- Derive parameter estimates using
fitdistr()
function inMASS
package for the dataset, dt consisting of discrete values varying from 0 to 50.
df=dt[[1]]
nbfit <- fitdistr(df,'negative binomial')
pfit <- fitdist(df, "pois")
- Use parameter estimates for creating reference distribution
fitnb <- dnbinom(0:50, size=0.4, mu=3.9)
fitp <- dpois(0:50, lambda=3.9)
I found that lambda
value is same as mu
.
- Get frequencies
t <- table(df)
D <- as.data.frame(t)
observed_freq <- D$Freq
- perform the chi-squared test
chisq.test(observed_freq, fitnb, simulate.p.value = TRUE)
chisq.test(observed_freq, fitp , simulate.p.value = TRUE)
- Results
for NB
Pearson's Chi-squared test with simulated p-value (based on 2000 replicates)
data: observed_freq and fitnb
X-squared = 476, df = NA, p-value = 0.989
for Poisson
Pearson's Chi-squared test with simulated p-value (based on 2000 replicates)
data: observed_freq and fitp
X-squared = 476, df = NA, p-value = 0.9875
Question:
What can we comment upon which distribution fits better? Clearly, for both X-squared is the same and we fail to reject the null hypothesis.
Can I perform some other test?
Edit
I also used lrtest() function and got the following result:
fit_poi <- fitdistr(df,"poisson")
fit_nbin <- fitdistr(df,"negative binomial")
lrtest(fit_poi,fit_nbin)
Result
Model 1: fit_poi
Model 2: fit_nbin
#Df LogLik Df Chisq Pr(>Chisq)
1 1 -2537.7
2 2 -1159.3 1 2756.6 < 2.2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
With this, can we say negative binomial performs better?
Histogram of actual data used in the test (Note: Codes differ a little based on this dataset)
Actual data
value count
0 205
1 65
2 40
3 40
4 32
5 18
6 15
7 11
8 8
9 9
10 7
11 6
12 8
13 3
14 1
15 8
16 2
18 2
19 2
20 5
21 1
23 2
24 1
25 1
29 1
31 1
32 2
35 1
36 1
42 1
43 1
45 1
50 1
53 1
ppois(50-1, 3.9, lower.tail = FALSE)
returns2.5757e-37
. I find it suspicious when a value so extreme (50) that it (or any larger one) should occur with a chance less than $10^{-36}$ arises in a sample of 2000: that's an astronomically rare event. Not knowing anything about the dataset, I am thereby inclined to mistrust all these results. What have you done to verify that these analyses make sense and give decent descriptions of your data? $\endgroup$