5
$\begingroup$

I'm trying to obtain a sum distribution of two discrete random variables. The function TransformedDistribution doesn't work for me in such case:

Z = EmpiricalDistribution[{0.7, 0.3} -> {0, 1}];
Y = EmpiricalDistribution[{0.6, 0.4} -> {0, 1}];

TransformedDistribution[z+y,{z \[Distributed] Z, y \[Distributed] Y}]

It gives an answer, which seems as a distribution of z+y, but when I ask to calculate a mean or CDF or PDF it gives no answer.

TransformedDistribution works well for named distributions - geometric, poisson and etc.

Thanks in advance.

$\endgroup$
1
  • $\begingroup$ This Expectation[z + y, {z \[Distributed] Z, y \[Distributed] Y}] works. $\endgroup$ Commented Jul 22, 2013 at 6:16

3 Answers 3

6
$\begingroup$

A current work-around is to use Probability to construct an equivalent emprirical distribution:

EmpiricalDistribution[
 Table[Probability[
    z + y == k, {z \[Distributed] Z, y \[Distributed] Y}], {k, 0, 
    2}] -> {0, 1, 2}]
$\endgroup$
8
$\begingroup$

OP writes: "I'm trying to obtain a sum distribution of two discrete random variables"

Using empirical distributions to carry out symbolic work is not the appropriate course to pursue. I would also suggest that you avoid using the in-built black box distributions, ... not only because they sometimes take non-standard forms ... but in part because common distributional notation often has many different standard forms / conventions, and using black boxes is by far the easiest way to make unnecessary mistakes.

Your example has 2 independent Bernoulli random variables, $Z$~Bernoulli($p$) and $Y$~Bernoulli($q$), where $(Z,Y)$ have joint pmf $f(z,y)$:

f = p^z (1-p)^(1-z) * q^y (1-q)^(1-y);   

which you can enter in raw mma as:

dist = ProbabilityDistribution[f, {z,0,1,1}, {y,0,1,1}, Assumptions -> {0<p<1, 0<q<1}]

Then, the pmf of $X=Z+Y$ is:

PDF[TransformedDistribution[z+y, {z, y} \[Distributed] dist], x]

which yields:

enter image description here

For your example, $p = \frac{3}{10}$, and $q = \frac{4}{10}$. Mathematica's TransformedDistribution function actually works rather nicely here.

$\endgroup$
7
$\begingroup$

In line with advice of @wolfies (but using black box distribution) the PMF of sum of two independent Bernoulli distributed random variables can also be done as:

Y = BernoulliDistribution[p];
Z = BernoulliDistribution[q];
X = TransformedDistribution[y+z, {y \[Distributed] Y, z \[Distributed] Z}]

PDF[X} yields the same result.

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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