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] *)
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]
$\endgroup$
Commented
Jul 16, 2018 at 15:17
TransformedDistribution
as it is indeed more readable, and fixed the output image, which I had copied wrong.
$\endgroup$
{x1, x2} \[Distributed] ...
would be fine with multinomial distributions. The form of Distributed
must follow each distribution individually, though.
$\endgroup$
MultinomialDistribution
documentation. Single value distributions work with single variable, others demand list of correct length... but you can't trivially combine them.
$\endgroup$
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}$