Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Mathematica, how can I define an arbitrary probability distribution?

I want an arbitrary function p[x] that integrates to 1 and for all x, 0 <= p[x] <= 1. Some kind of transformation rule?

like image 232
Sasha Avatar asked Aug 19 '10 19:08

Sasha


1 Answers

You could use ProbabilityDistribution for this together with an undefined function of x:

dist = ProbabilityDistribution[p[x], {x, -Infinity, Infinity}];

It now knows a few rules to apply:

  • continuous probability density: probability of a single value is zero

    In[26]:= Probability[x == 0, x \[Distributed] dist]
    
    Out[26]= 0
    
  • the probability of having a value at all

    In[28]:= Probability[x > 0 || x <= 0, x \[Distributed] dist]
    
    Out[28]= 1
    
  • The CDF at - infinity

    In[29]:= CDF[dist][-\[Infinity]]
    
    Out[29]= 0
    
  • The CDF at + infinity

    In[30]:= CDF[dist][\[Infinity]]
    
    Out[30]= 1
    
  • The PDF

    In[32]:= PDF[dist][x]
    
    Out[32]= p[x]
    
  • However, it doesn't assume the PDF of the distribution is normalized:

    In[33]:= Integrate[PDF[dist][x], {x, -Infinity, Infinity}]
    
    Out[33]= Integrate[p[x], {x, -Infinity, Infinity}]
    
  • The latter can be taught, defining an UpValue for p:

    p /: Integrate[p[x], {x, -Infinity, Infinity}] = 1;
    
  • Now it can integrate the PDF:

    In[4]:= Integrate[PDF[dist][x], {x, -Infinity, Infinity}]
    
    Out[4]= 1
    

You know that your second requirement, i.e. 0 <= p[x] <= 1, is not generally true for probability density functions, do you?

like image 100
Sjoerd C. de Vries Avatar answered Jan 04 '23 06:01

Sjoerd C. de Vries