8
$\begingroup$

I have a probability density function. Is there a mechanism to create a Distribution object from it, such that normal Mathematica commands that usually work on distributions, such as Variance, RandomVariate, etc., work on it?

$\endgroup$
  • 3
    $\begingroup$ "ProbabilityDistribution[$\mathit{pdf}$, {$x$, $x_\min$, $x_\max$}] represents the continuous distribution with PDF $\mathit{pdf}$ in the variable $x$ where the $\mathit{pdf}$ is taken to be zero for $x < x_\min$ and $x > x_\max$." $\endgroup$ – Rahul Sep 5 '14 at 16:32
12
$\begingroup$

You need ProbabilityDistribution.

Example:

distr = ProbabilityDistribution[E^(-(x^2/2))/Sqrt[2 π], {x, -Infinity, Infinity}]

Mean[distr] (* ==> 0 *)

Variance[distr] (* ==> 1 *)

Warning:

You are responsible for ensuring that the probability density function you provide is normalized over its domain. Mathematica will not verify this and will not warn you if it isn't, however it will give you incorrect results when using the distribution. I know from experience that e.g. Variance and RandomVariate will give incorrect results in this case.

$\endgroup$
  • $\begingroup$ +1 for the warning, I have experienced that as well. It's something that should at least be noted in the documentation. $\endgroup$ – Guillochon Sep 5 '14 at 20:18
  • $\begingroup$ @Guillochon ust checked, it's mentioned under Possible Issues. $\endgroup$ – Szabolcs Sep 5 '14 at 20:48
  • $\begingroup$ This is new to the documentation in Mathematica 10 (and the online documentation), it is not mentioned clearly in the Mathematica 9 documentation. There, it appears under "properties & relations" and simply says "The integral of the PDF over the distribution domain needs to be unity." $\endgroup$ – Guillochon Sep 5 '14 at 21:26
  • $\begingroup$ @Guillochon I think it's a good idea to use the feedback box at the bottom of online doc pages, they seem to listen to reasonable suggestions. $\endgroup$ – Szabolcs Sep 5 '14 at 21:37
  • 1
    $\begingroup$ Addendum to the warning: in current versions, use the setting Method -> "Normalize" if you want ProbabilityDistribution[] to perform normalization of your PDF on your behalf. $\endgroup$ – J. M. will be back soon Mar 14 at 15:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.