1
# 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 的卡方检验数据:table(emp1) 和 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 的卡方检验数据:table(emp2) 和 table(est2) X-squared = 8.9722, df = 12, p-value = 0.7053

是否有一些解释为什么我在泊松和二项式负分布之间的卡方检验(重复多次)中具有完全相同的 p 值?我预计负二项式分布超过 0.05,泊松分布 <0.05,但这不会发生。

4

0 回答 0