What would I need to define to add a new statistical distribution to Mathematica?
Ideally, it would support as many of Mathematica's statistical functions as possible.
In practice, this might most easily be done using ProbabilityDistribution
or TransformedDistribution
but are there alternatives?
For example, I can give definitions for unknowndistribution
(PDF unknown, but specified mean and variance). For example
Mean[unknowndistribution[μ_, σ_]] ^:= μ
Variance[unknowndistribution[μ_, σ_]] ^:= σ^2
I then can write
d = unknowndistribution[μ, σ];
Mean[d]
(* μ *)
but if I try
TransformedDistribution[x + y, {x \[Distributed] d, y \[Distributed] d}]
it returns effectively unevaluated.
Motivation
Some comments have questioned the motivation for doing this. I'm interested because I want to understand the capabilities of Mathematica.
Clearly, internal distributions are not defined in terms of ProbabilityDistribution
e.g.
ProbabilityDistribution[PDF[NormalDistribution[], x], {x, -∞, ∞}]
does not transform automatically to NormalDistribution[0,1]
. Internally defined distributions are better supported that those defined via ProbabilityDistribution
. It would be interesting to know if it was possible to get some of these additional benefits (without having to add too many definitions).
Doing so is probably hard, but you only establish if a problem is impracticably hard by thinking about and asking other people who probably know far more.
PDF[unknowndistribution[\[Mu]_, \[Sigma]_], z_] ^:= pdf[z, \[Mu], \[Sigma]]
. $\endgroup$ProbabilityDistribution
is the only choice, because\[Distributed]
,RandomVariate
,Expectation
and so on... are not going to work with something else. You'd be writing up-values for everything and it would be grotesquely inefficient. $\endgroup$Statistics`Library`
context. I would start spelunking there. $\endgroup$ProbabilityDistribution
allows one to define just about any univariate distribution, but the associated calculations are likely to be slow, unreliable, or entirely infeasible. Wouldn't it be great if we could give pre-calculated formulas for moments, numerical methods for random sampling, explicit formulas or methods for parameter estimation, etc. $\endgroup$