Here's the data and set up:
library(fitdistrplus)
library(gamlss)
finalVector <- dput(finalVector)
c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 1, 2, 1, 1, 1, 1, 1,
1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 2, 1, 3, 2, 1, 1, 1, 1, 1, 1, 2,
2, 1, 4, 2, 3, 1, 2, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 1, 2, 2, 1, 1, 4, 1, 2, 2, 1, 1, 1, 1, 1, 2, 1, 1, 2, 2, 1,
2, 1, 1, 4, 2, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1)
countFitPoisson <- fitdist(finalVector,"pois", method = "mle", lower = 0)
countFitZeroPoisson <- fitdist(finalVector, 'ZIP', start = list( ##mu = mean of poisson, sigma = prob(x = 0))
mu = as.numeric(countFitPoisson$estimate),
sigma = as.numeric(as.numeric(countFitPoisson$estimate))
), method = "mle", lower= 0)
The first call works successfully. The final says it failed to estimate and I'm not sure why. Thanks!
Edit:
Assuming I did the code correctly (not sure), then the only thing I can think of is that there are not enough zeros to fit the model?
Your data is not really zero-inflated, hence fitting the model does not lead to an improvement. Rather than using the
fitdistr
approach, I'm usingglm
and extended regression models below. All regression (sub-)models just use a constant (or intercept) without any real regressors, though. For visualization I use rootograms via thecountreg
package available from R-Forge (which contains the successor functions to thepscl
count data regressions).First, let's look at the Poisson fit:
This corresponds to a fitted mean of
exp(-0.284)
, i.e., about 0.753. This fits the data very well if you compare observed and fitted frequencies:This shows that the fit for the counts 0, 1, 2 is essentially perfect and there are only small deviations for 3, 4, 5 but these frequencies are extremely low anyway. So judging from this it appears that no extension of the model is necessary.
But to formally compare the model with others, one could consider a zero-inflated Poisson (as you tried) a hurdle Poisson or a negative binomial. The zero-inflated model yields:
Thus, the count mean is essentially identical to before and the probability of zero-inflation is essentially zero (
plogis(-9.151)
is about 0.01%).The hurdle model works similarly but can use a zero-censored Poisson model for 0-vs-greater and a truncated Poisson for the positive counts. This is then also nested within the Poisson model and hence a Wald test can be carried easily out:
This also clearly shows that there are no excess zeros and a simple Poisson model suffices.
As a final check one could also consider a negative binomial model:
This has again virtually the same mean and a huge theta parameter that is close enough to infinity (= Poisson). Thus, overall the Poisson model is simply sufficient and there is no need for any of the extensions considered. The likelihoods are almost unchanged and the additional parameters (zero-inflation, zero-hurdle, theta-dispersion) do not yield any improvement: