简体   繁体   中英

Error in fitting a zero inflated poisson distribution in R

I'm a R beginner trying to fit a ZIP:

set.seed(5695)
a<-c(rep(0,250),rpois(n=750,lambda=2))
fpoisZI <- fitdist(a, "ZIP", start=list(sigma=sum(a == 0)/length(a), mu=mean(a)))

I think this code should be ok, but then it appears an error message:

The dZIP function must be defined

Any idea about what am I doing wrong?

For Zero inflated poisson distribution for fitting a ZIP model, you need the library gamlss.dist . if not installed, install it using install.packages('gamlss.dist') . Then the following code should work:

library(fitdistrplus)
library(gamlss.dist)
set.seed(5695)
a<-c(rep(0,250),rpois(n=750,lambda=2))
fpoisZI <- fitdist(a, "ZIP", start=list(sigma=sum(a == 0)/length(a), mu=mean(a)))
summary(fpoisZI)
#Fitting of the distribution ' ZIP ' by maximum likelihood 
#Parameters : 
#       estimate Std. Error
#sigma 0.2465825 0.01912744
#mu    1.9672566 0.06196681
#Loglikelihood:  -1621.389   AIC:  3246.777   BIC:  3256.593 
#Correlation matrix:
#          sigma        mu
#sigma 1.0000000 0.3968521
#mu    0.3968521 1.0000000

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM