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!
Answer
You made several mistakes
MyBinomialDistribution
should be a function ofn
andp
.There is only one variable
k
.n
andp
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]
PDF[MyBinomialDistribution[n, p], k]
Comments
Post a Comment