Error in optim : nonfinite value supplied by optim
Hi All,
I am fitting a zeroinflated Poisson model using the R recipe. I am getting this error message below, can someone explain why is this and how can I fix it, please?
Error in optim(fn = loglikfun, gr = gradfun, par = c(start$count, start$zero, : nonfinite value supplied by optim Traceback: optim(fn = loglikfun, gr = gradfun, par = c(start$count, start$zero, . if (dist == "negbin") log(start$theta) else NULL), method = method, . hessian = hessian, control = control)
Answers

Hi,
This message pops up with a number of open source R packages. It typically means the algorithm's optimization function is unable to go further, perhaps due to multicollinearity issues, or lack of variance in the data.
There are more flexible packages out there, and you may want to try a zeroinflated negative binomial model, which removes the conditional target mean = variance assumption of the zeroinflated poisson model.
The glm package in R has this model: https://stat.ethz.ch/Rmanual/Rdevel/library/MASS/html/glm.nb.html
So does statsmodels in python: https://www.statsmodels.org/dev/generated/statsmodels.discrete.count_model.ZeroInflatedNegativeBinomialP.html?highlight=zeroinflatednegativebinomial#statsmodels.discrete.count_model.ZeroInflatedNegativeBinomialP
Best,
Pat