# TransformedDistribution doesn't work

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.

-
This Expectation[z + y, {z \[Distributed] Z, y \[Distributed] Y}] works. –  b.gatessucks Jul 22 '13 at 6:16

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}]

-

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.

-

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.

-