# The sum of two independent variables following the Binomial Distributions

I would have thought the answer to the following was another Binomial distribution, but I can't seem to get Mathematica to output that fact:

PDF[TransformedDistribution[x1 + x2, {x1, x2} \[Distributed] BinomialDistribution[n, p]], y]


Your syntax is slighlty off. The way you wrote it, {x1, x2} \[Distributed] BinomialDistribution[n, p]] indicates that the vector variable {x1, x2} follows the multivariate distribution BinomialDistribution[n, p], which of course does not work.

Instead, you need to indicate the distribution for each variable:

PDF[TransformedDistribution[
x1 + x2, {x1 \[Distributed] BinomialDistribution[n, p],
x2 \[Distributed] BinomialDistribution[n, p]}], y]


This is shown in the second syntax example in the documentation for TransformedDistribution.

Bob Hanlon also pointed out that a more readable result can be obtained by evaluating the TransformedDistribution itself:

TransformedDistribution[x1 + x2,
{x1 \[Distributed] BinomialDistribution[n, p],
x2 \[Distributed] BinomialDistribution[n, p]}
]

(* Out: BinomialDistribution[2 n, p] *)

• Evaluation of just TransformedDistribution[ x1 + x2, {x1 \[Distributed] BinomialDistribution[n, p], x2 \[Distributed] BinomialDistribution[n, p]}] gives BinomialDistribution[2 n, p] which makes it clear that the result is a BinomialDistribution rather than having to visually recognize the fact from the PDF. And on my system, your input evaluates to Piecewise[{{(1 - p)^(2*n - y)*p^y* Binomial[2*n, y], 0 <= y <= 2*n}}, 0] – Bob Hanlon Jul 16 '18 at 15:17
• @Bob Both are excellent points, thank you. I added the result of evaluation of TransformedDistribution as it is indeed more readable, and fixed the output image, which I had copied wrong. – MarcoB Jul 16 '18 at 16:09
• {x1, x2} \[Distributed] ... would be fine with multinomial distributions. The form of Distributed must follow each distribution individually, though. – kirma Jul 16 '18 at 16:12
• @kirma I don't understand your point. Could you elaborate on your second sentence? – MarcoB Jul 16 '18 at 17:01
• For instance, look at MultinomialDistribution documentation. Single value distributions work with single variable, others demand list of correct length... but you can't trivially combine them. – kirma Jul 16 '18 at 17:47

For joint distribution of n iid random variables each with distribution d, you can also use ProductDistribution[{d, n}].

TransformedDistribution[x1 + x2,
{x1, x2} \[Distributed] ProductDistribution@{BinomialDistribution[n, p], 2}]


BinomialDistribution[2 n, p]

PDF[dist, y] // TeXForm


$\begin{cases} p^y \binom{2 n}{y} (1-p)^{2 n-y} & 0\leq y\leq 2 n \\ 0 & \text{True} \end{cases}$