I’m happy to announce DistributionsFactories.jl, a package that solves a problem most of us have hit: you know the summary statistics you want — a mean and variance, a couple of quantiles, a mode — but you need an actual Distributions.jl object with those properties, and the named families aren’t parameterised that way.
DistributionsFactories.jl inverts that. You give it the family and the moments or quantiles, and it solves for the parameters.
In some cases, all it is doing is using an explicit solution of “moment matching” equations, and in other cases the computation under the hood is more complicated.
e.g.
using DistributionsFactories, Distributions
make_dist(Gamma, mean=5.0, var=3.0) # Gamma with exactly this mean and variance
make_dist(Normal, q1=10.0, q3=30.0) # Normal pinned to two quartiles
It also treats feasibility as first-class: dist_exists and available_distributions tell you which families can hit a given target
There are companion Python and R ports, but the Julia package is the master.
Very useful! I wonder if we could omit the distribution family and pick the one with “minimum error” after trying them all. Do you have any comment about that?
Thanks. At the moment, they are all with \approx 0 (machine error) and a big point of the package is checking for feasibility. That is, you specify moments (or similar specs), and the package lets you know if the distribution exists or not.
I guess one could have that you over specify specs, but it is much less well defined. So I’m not sure how this would work and fit in the package exactly. But would love to hear further details of such a request - and usecase. Thanks.
Another idea that would be useful for probabilistic modelling would be to provide a function that returns, for example, an InverseGamma distribution parametrised such that 99% of its density falls between 0.5 and 50.
Michael Betancourt does this using Stan’s algebra_solver in this blog post.
EDIT: Hmm, or is this already possible with one of the keywords? I should have checked before but currently can’t try myself.
EDIT #2: This is already possible (although not for InverseGamma):
It’s nice to have the original functionality in Julia first and we have also the mirrors in strangers such as R and Python as mentioned in the README files.
I see from the repo that it supports truncation for certain distributions, but no mention of censoring so far. Is it already there and I just kissed it, or would you consider this in your future development plans?
Also - would it be able to support custom distributions?
Yes, supports several truncations. In fact, this got us into the project, as the feasible moments for truncated normals and related distributions were not simply known.
As for censoring have not thought about that - but great if you open an issue. Similarly with custom distributions.