# ProbabilityDistribution only accepts dx=1 for discrete distributions

Bug introduced in 10.4.1 or earlier and somewhat fixed in 12.0.0

This question maybe related to (95436) but neither its answer nor the documentation for ProbabilityDistribution state whether we may build a discrete probability distribution using a step size $$dx$$ different from $$1$$.

## Minimum Working Example

Let's say that we want to build a discrete probability distribution (say a prior distribution) for some random variable $$X$$ which can only take values in the range $$[0,1]$$. We do know that $$Pr(X=\frac{1}{12}) = 0.25$$, $$Pr(X=\frac{1}{6})=0.5$$, $$Pr(X=\frac{1}{4})=0.25$$ and the probability is zero for all other values.

From reading the documentation one might assume that we can use Piecewise within ProbabilityDistribution using a discrete range specification with $$dx = \frac{1}{12}$$ to build a discrete probability distribution matching our prior information:

priorDistribution = ProbabilityDistribution[
Piecewise[
{
{ 0.25, x == 1/12 },
{ 0.50, x == 1/6  },
{ 0.25, x == 1/4  }
}
],
{ x, 0, 1, 1/12 }
]


But this surprisingly will not work in Version 11.0 :

PDF[priorDistribution, 1/4]


PDF[ProbabilityDistribution[[Piecewise] 0.25 [FormalX]==1/12 0.5 [FormalX]==1/6 0.25 [FormalX]==1/4 0 True ,{[FormalX],0,1,1/12}],0.25]

RandomVariate[ priorDistribution, 10 ]


RandomVariate::noimp: Sampling from ProbabilityDistribution[[Piecewise] 0.25 [FormalX]==1/12 0.5 [FormalX]==1/6 0.25 [FormalX]==1/4 0 True ,{[FormalX],0,1,1/12}] is not implemented.

Am I missing something? It seems that ProbabilityDistribution only accepts $$dx = 1$$ (I tried $$dx = 2$$ for a different range and it also did not work).

Update (Version 12.0.0):

While the above given example still does not work, the limitation with regard to dx has been fixed (at least with regard to dx > 1):

dist = ProbabilityDistribution[
0.25 Boole[ x == 4]
+ 0.50 Boole[ x == 6]
+ 0.25 Boole[ x == 12 ]
,
{ x, 0, 12, 2}
]

PDF[ dist, 4 ]


0.25

• If you try something simple like: dist = ProbabilityDistribution[1/6, {x, 1, 11, 2}], it appears that it works with calculations like Mean or Variance, but not with RandomVariate. It doesn't work with your example at all. – wolfies Sep 1 '16 at 20:25
• I have reported the issue to WRI [CASE:3705612] and will update this post once I have gotten a feedback. – gwr Sep 2 '16 at 13:49
• The irregular behavior with Piecewise has been confirmed by WRI today. I just added the bugs tag and header accordingly. – gwr Sep 9 '16 at 8:59

It does seem to be broken for increments other than one. The workaround is either to rescale or else use EmpiricalDistribution

priorDistribution =
ProbabilityDistribution[
Piecewise[{
{0.25, x == 1},
{0.50, x == 2},
{0.25, x == 3}}],
{x, 1, 12, 1}];

DiscretePlot[PDF[priorDistribution, 12 x], {x, 0, 1, 1/12}] Alternatively,

wts = {0.25, 0.50, 0.25};

data = {1/12, 1/6, 1/4};

priorDistribution =
EmpiricalDistribution[wts -> data];

DiscretePlot[PDF[priorDistribution, x], {x, 0, 1, 1/12}]


(* plot same as above *)

• Would you think this should be called a bug? – gwr Sep 2 '16 at 5:40
• @gwr - looks like one to me. – Bob Hanlon Sep 2 '16 at 13:21