4
$\begingroup$

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]
$\endgroup$
0

2 Answers 2

5
$\begingroup$

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]

Mathematica graphics

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] *) 
$\endgroup$
5
  • 2
    $\begingroup$ 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] $\endgroup$
    – Bob Hanlon
    Commented Jul 16, 2018 at 15:17
  • $\begingroup$ @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. $\endgroup$
    – MarcoB
    Commented Jul 16, 2018 at 16:09
  • $\begingroup$ {x1, x2} \[Distributed] ... would be fine with multinomial distributions. The form of Distributed must follow each distribution individually, though. $\endgroup$
    – kirma
    Commented Jul 16, 2018 at 16:12
  • $\begingroup$ @kirma I don't understand your point. Could you elaborate on your second sentence? $\endgroup$
    – MarcoB
    Commented Jul 16, 2018 at 17:01
  • $\begingroup$ 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. $\endgroup$
    – kirma
    Commented Jul 16, 2018 at 17:47
3
$\begingroup$

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

$\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.