Negative binomial maximum likelihood estimate implementation in Python using L-BFGS-B
python setup.py install
from fit_nbinom import nbinom_mle
import numpy as np
# X is a list or a numpy array representing the data
X = np.array([16, 18, 11, 19, 20, 3, 2, 11, 8, 5])
res = nbinom_mle(X=X)
res.summary()
output:
parameter estimate std err 95%CI lower 95%CI upper
----------- ---------- --------- ------------- -------------
size 3.19747 0.584826 2.05123 4.34371
mu 11.3 0.715784 9.89709 12.7029
tablefmt
argument defines format of summary table.
Available format is the same as python-tabulate.
example: latex
format
res.summary(tablefmt="latex")
output:
\begin{tabular}{lrrrr}
\hline
parameter & estimate & std err & 95\%CI lower & 95\%CI upper \\
\hline
size & 3.19747 & 0.584678 & 2.05153 & 4.34342 \\
mu & 11.3 & 0.715784 & 9.89709 & 12.7029 \\
\hline
\end{tabular}
parameters = res.params()
print(parameters)
output:
{'size': 3.1974721271555056, 'mu': 11.300000225025348}
stderrs = res.stderr()
print(stderrs)
output:
{'size': 0.5846775256549968, 'mu': 0.7157840010743496}
In the probability mass function of negative binomial distribution below: