0

I am trying to fit a negative binominal distribution to a dataset that only has one field and that field is the number of words in a sentence. How do I fit the distribution using statsmodels.discrete.discrete_mode

  • Did you have a look at the documentation? https://www.statsmodels.org/stable/generated/statsmodels.discrete.discrete_model.DiscreteModel.html – gofvonx Apr 18 '21 at 11:15
  • if i have my data as exog then what endog if the dataset only has one field ? – Mark Sweetner Apr 18 '21 at 19:27
  • 1
    If you just want to fit the distribution without explanatory variables, then `endog` are the observed values of the distribution and `exog` is a constant, i.e. array of `ones`. Parameters are (log)mean and dispersion, and not the standard negative binomial parameterization. – Josef Apr 20 '21 at 01:34

1 Answers1

1

I think that statsmodels class is just meant to be a backend asset for regression models, and not for fitting distributions. See the reference here: Regression with Discrete Dependent Variable

But in an answer in an other question here, there is a link, with a possible workaround to exploit the statsmodels regression model, to fit your distribution: Newbie question about discrete distributions and MLE

I have looked at scipy.stats.nbinom as well for you, as scipy has the MLE fitting methods for all kinds of distributions. But the discrete distributions do not have fitting methods. There are numerous answers here explaining the difficulties with that, and some alternative approaches:

As an alternative possibility besides the ones mentioned in the above answers, I can advise you to check out Bayesian numerical methods with the PyMC3 package, as that includes a Negative Binomial distribution as well.

Betelgeux
  • 353
  • 2
  • 15