3
$\begingroup$

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.

$\endgroup$
8
  • $\begingroup$ I'm not following the "why" you want to do this. I'm not questioning that there is a good reason: I'm just not understanding. Would you not need to define all of the desired properties like you did with the mean and variance? For example: PDF[unknowndistribution[\[Mu]_, \[Sigma]_], z_] ^:= pdf[z, \[Mu], \[Sigma]]. $\endgroup$
    – JimB
    Commented May 31, 2021 at 2:44
  • $\begingroup$ 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$
    – flinty
    Commented May 31, 2021 at 10:14
  • 3
    $\begingroup$ I think that the ability to implement new distributions would definitely be very useful. Clearly, there is no documented way to do so, and it's unclear if there is a standardized extension interface even for internal use. If there is one, it is likely in the Statistics`Library` context. I would start spelunking there. $\endgroup$
    – Szabolcs
    Commented May 31, 2021 at 13:45
  • $\begingroup$ @JimB Wouldn't it be great if we could implement our own distributions that work with good performance and good reliability? Sure, 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$
    – Szabolcs
    Commented May 31, 2021 at 13:48
  • 1
    $\begingroup$ @Szabolcs All of what you say makes sense. Another very recent question is related: mathematica.stackexchange.com/questions/246925/… where something minimal is stated about the probability distribution and just various low order moments - rather than the pdf and cdf - are of interest. $\endgroup$
    – JimB
    Commented May 31, 2021 at 20:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.