# How can I create a Distribution from its probability density function?

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?

• "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$." – user484 Sep 5 '14 at 16:32

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.

• +1 for the warning, I have experienced that as well. It's something that should at least be noted in the documentation. – Guillochon Sep 5 '14 at 20:18
• @Guillochon ust checked, it's mentioned under Possible Issues. – Szabolcs Sep 5 '14 at 20:48
• 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." – Guillochon Sep 5 '14 at 21:26
• @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. – Szabolcs Sep 5 '14 at 21:37
• 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. – J. M.'s ennui Mar 14 '19 at 15:26