3
$\begingroup$

I am trying to wrap my head around the function ProbabilityDistribution. For training purpose, I'd like to recreate the binomial distribution (without using it) so that the two code lines return the same output.

PDF[BinomialDistribution[n, p], k]

PDF[MyBinomialDistribution[n, p], k]

My try

I would construct this function more or less like this

MyBinomialDistribution = 
 ProbabilityDistribution[
  Binomial[n, k] p^k (1 - p)^(n - k), {k, 0, Infinity}, {n, 0, Infinity}, {p, 0, 1}
]

PDF[MyBinomialDistribution[n, p], k]

but it obviously doesn't work! Thanks for your help!

$\endgroup$
7
$\begingroup$

You made several mistakes

  • MyBinomialDistribution should be a function of n and p.

  • There is only one variable k. n and p are parameters

The correct definition is

MyBinomialDistribution[n_, p_] := 
 ProbabilityDistribution[Binomial[n, k] p^k (1 - p)^(n - k), {k, 0, n, 1}]

PDF[BinomialDistribution[n, p], k]

enter image description here

PDF[MyBinomialDistribution[n, p], k]

enter image description here

$\endgroup$
  • $\begingroup$ That totally makes sense. Thank you! $\endgroup$ – Remi.b Oct 21 '14 at 22:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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