Fit method for discrete distributions in scipy.stats?
Hi all, Recently I needed to fit a Zipf distribution to some data for an application and noticed that while scipy has a fit method for the continuous distributions, it has none for any discrete distributions. Is there any reason for this, or has it just not been done yet? There aren't that many discrete distributions and I'd be happy to try to put together a PR to add this, but I'd just like to make sure that there is no specific reason it's not already there before I start writing any code. One possible issue I can think of is that some distributions have discrete shape parameters (i.e. binomial and the number of trials): an MLE estimate would probably return a non-integer (the distributions accept non-integers just fine). Thoughts? Thanks, Graham Clenaghan
On Sat, Aug 15, 2015 at 5:56 PM, Graham Clenaghan <gclenaghan@gmail.com> wrote:
Hi all,
Recently I needed to fit a Zipf distribution to some data for an application and noticed that while scipy has a fit method for the continuous distributions, it has none for any discrete distributions.
Is there any reason for this, or has it just not been done yet? There aren't that many discrete distributions and I'd be happy to try to put together a PR to add this, but I'd just like to make sure that there is no specific reason it's not already there before I start writing any code.
One possible issue I can think of is that some distributions have discrete shape parameters (i.e. binomial and the number of trials): an MLE estimate would probably return a non-integer (the distributions accept non-integers just fine).
That and that many parameters also have strong interval restrictions are the main reason. The main reason I guess is that nobody went over these cases. My guess is that a generic setup will not work very well, and it might be better to add fit methods on a case by case basis. statsmodels is fitting binomial (fixed n), Poisson and Negative Binomial models. All of them have loc fixed at zero. The parameter restrictions are imposed by nonlinear transformations (link functions in GLM). Some like Negative Binomial are also reparameterized, which is pretty common of there is no parameter for the mean. I think we could add fit methods for restricted usage, e.g. Poisson fit with loc=0 is just the mean of the data, IIRC. Binomial with fixed n and fixed loc is just the proportion, IIRC. I don't know about estimating Zipf. Estimating parameters where the support of the distribution depends on the parameters, e.g. hypergeom, might be difficult, I never tried. Also, I is not clear whether the distributions generalize to real numbers if the parameters are supposed to be int. Some do, some don't, or some generalize for some methods but not for others, AFAIR. If loc is estimated as in the continuous distribution, it would have to be restricted to integers. The alternative would be to get the limited cases where it makes sense (fixed loc, fixed n) into statsmodels, or one of the powerlaw packages for zipf. (Evgenyi is now the main maintainer for stats.distributions, with support by several others.) Josef
Thoughts?
Thanks, Graham Clenaghan
_______________________________________________ SciPy-Dev mailing list SciPy-Dev@scipy.org http://mail.scipy.org/mailman/listinfo/scipy-dev
participants (2)
-
Graham Clenaghan -
josef.pktd@gmail.com