4
$\begingroup$

As far as I know, Mathematica lacks a definition for a probability distribution representing a constant random variable.

Is this assertion correct?

Is there a problem in making such a distribution well-defined in Mathematica (assuming we treat it as a continuous rather than a discrete distribution)?

In principle, we could add definitions for this distribution, e.g.

CDF[ConstantDistribution[μ_]] ^:= UnitStep[# - μ] &

How would I find what definitions are needed to make it a "first class" member of the set of distributions supported by Mathematica? So that, for example, it could be used in functions such as TransformedDistribution?

In general, there are ways to work around the lack of such a distribution, but just as it is sometimes useful to have a function such as Identity (e.g. to pass to a function that transforms an input) it can be useful to have the "trivial" distribution.

$\endgroup$
  • $\begingroup$ Is this too limited: constantD = UniformDistribution[{4.3, 4.3}]; RandomVariate[constantD, 10] ? This results in {4.3, 4.3, 4.3, 4.3, 4.3, 4.3, 4.3, 4.3, 4.3, 4.3}. But the PDF and CDF functions don't work with this. $\endgroup$ – JimB May 15 at 21:51
  • $\begingroup$ @JimB I think defining it in terms of pre-defined distributions would be a simple way forward. But as you show, your example doesn't work fully and neither does setting the SD = 0 in a Normal distribution. $\endgroup$ – mikado May 15 at 21:58
6
$\begingroup$

A relatively simple trick can achieve this

ConstantDistribution[m_] = TransformedDistribution[m, {x \[Distributed] NormalDistribution[0, 1]}];

This behaves as desired for some key functions

{Mean, Variance, CDF[#, t] &, CharacteristicFunction[#, t] &}[ConstantDistribution[m]] // Through // InputForm
(* {m, 0, Piecewise[{{1, m - t <= 0}}, 0], E^(I*m*t)} *)
$\endgroup$
  • 1
    $\begingroup$ Wow! Even Expectation works with this approach. $\endgroup$ – JimB May 17 at 18:12
2
$\begingroup$

In[35]:= dist = ProbabilityDistribution[1, {x, a, a, 1}];

In[36]:= DistributionParameterQ[dist]

Out[36]= True

In[39]:= {Mean[dist], Variance[dist], CDF[dist, x], Expectation[s^2 + 1, s [Distributed] dist]} // InputForm

Out[39]//InputForm= {a, 0, Piecewise[{{1, a <= x}}, 0], 1 + a^2}

$\endgroup$
  • $\begingroup$ Interesting - technically you have defined a discrete distribution that only takes the value a, whereas my answer defined a continuous distribution. Mathematica makes a distinction between the two types, at least in PDF $\endgroup$ – mikado Jun 18 at 21:03
  • $\begingroup$ The integral of a finite function from a to a is zero... This really should not work, but I guess the framework is just too robust ;) In[62]:= td = TransformedDistribution[3, {x [Distributed] NormalDistribution[0, 1]}]; In[63]:= DistributionDomain[td] Out[63]= Interval[{3, 3}] In[64]:= DistributionParameterQ[td] Out[64]= True In[69]:= PDF[td, x] // InputForm Out[69]//InputForm= Piecewise[{{0, x != 3}}, Indeterminate] $\endgroup$ – Gosia Jun 18 at 21:14

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.