Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
This Expectation[z + y, {z \[Distributed] Z, y \[Distributed] Y}] works. – b.gatessucks Jul 22 '13 at 6:16
up vote 4 down vote accepted

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

    z + y == k, {z \[Distributed] Z, y \[Distributed] Y}], {k, 0, 
    2}] -> {0, 1, 2}]
share|improve this answer

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:

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

share|improve this answer

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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