# Packages
library(MASS)# Pacote MASS
library(car) # Pacote car
# Create some artificial numbers with binomial negative distribution
S<-10
P<-0.6
N<-rnbinom(n=283, size=S, prob=P)
# Poisson --------------------------------------------------------------------------------------
(poisson <- fitdistr(N,"poisson"))
# Comparation between observed vs estimated values
(n <- length(N))
est1 <-n*dpois(N, lambda=poisson$estimate) ## Estimate the values
fecdf1 <- ecdf(N) ### Empirical Cumulative Distribution Function
knotsX1 <- knots(fecdf1) # Aggregate in classes
emp1 <- fecdf1(c(knotsX1,Inf)) # frequency for each value in the distribution
chisq.test(table(emp1),table(est1))
Pearson's Chi-squared test data: table(emp1) and table(est1) X-squared = 8.9722, df = 12, p-value = 0.7053
# Negative binomial ----------------------------------------------------------------------------
( bn <- fitdistr(N,"negative binomial"))
# Comparation between observed vs estimated values
par <- bn$estimate
(size <- par[1])#k
(mu <- par[2])#Media
(n <- length(N))
est2 <-n*dnbinom(N,size=size,mu=mu) ## Estimate the values
fecdf2 <- ecdf(N) ### Empirical distribution function
knotsX2 <- knots(fecdf2) # Aggregate in classes
emp2 <- fecdf2(c(knotsX2,Inf)) # frequency for each value in the distribution
chisq.test(table(emp2),table(est2))
Pearson's Chi-squared test data: table(emp2) and table(est2) X-squared = 8.9722, df = 12, p-value = 0.7053
Is there some explanation why I have the exact same p-values in Chi-square test (repeated several times) between Poisson and Binomial negative distribution? I'll expect more than 0.05 for negative binomial and <0.05 for Poisson distribution, but it doesn't happen.