Reputation: 11
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?
Upvotes: 1
Views: 541
Reputation: 23101
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
Upvotes: 1