thekingofkings / chicago-crime

Crime correlation anaysis
MIT License
11 stars 3 forks source link

My own python implemetation **NegBin** class does not work. #17

Open thekingofkings opened 7 years ago

thekingofkings commented 7 years ago

Wrong log-likelihood function is used

In python/NegBinStatModel, the negative binomial distribution likelihood function is used, i.e. nbinom.logpmf, which is wrong.

Refer this link for the correct log-likelihood function.

thekingofkings commented 7 years ago

The log-likelihood function might not be completely wrong, but it is definitely over-simplified.

Follow the NegativeBinomial implementation to improve this function.

thekingofkings commented 7 years ago

My own implementation keeps failing, due to "optimization not converge" or "current function value is nan".

One possible explanation is that I did not implement the score function, which gives the gradient of the log-likelihood function at given parameters.

Refer this source code docstring

thekingofkings commented 7 years ago

statsmodels NegativeBinomial model is not flexible enough

I followed the implementation of the discrete.NegativeBinomial model.

Now it seems that the original NegativeBinomial model has issue to fit data. There is a bug report