We have one final type of random variable to learn how to generate using python - the negative binomial random variable. If you remember the negative binomial random variables measures the number of trials I have to perform in order to obtain exactly k successes. A negative binomial random variables can be generated by generating k geometric random variables and adding them together.
To complete the exercise you will need to:
-
Write a function called
bernoulli
that takes in a parameter calledp
. This parameter gives the probability that the trial is successful - and that the function thus returns a 1 -
Use your
bernoulli
function in a second function calledgeometric
. Thisgeometric
function should take one parameterp
(the probability of success in each individual trial). The function should then return a geometric random variable. -
Write one final function called
negative_binomial
. Thisnegative_binomial
function should take two parameters:p
(the probability of success in each individual trial) andk
(the number of successes that you would like to observe). The function should then return a negative binomial random variable.