Scipy.nbinom vs Negative Binomial Distribution formula

Viewed 20

The provided question:

Show using the formula for the negative binomial distribution that the probability Brian kicks his fourth successful field goal on the sixth attempt is 0.164.

The probability of a single success is p = 0.8, the number of successes is k = 4, and the number of necessary attempts under this scenario is n = 6.

What I have understood:

This should be the formula:

(From the open intro book on page 160)

Meaning this should be the solution:

Which I can verify here:

>>> from math import comb
>>> comb(5,3)*(pow(0.8,4))*(pow(0.2,2))
0.16384000000000007

However, when I try to solve this using scipy I get a very different answer

Given 6 attempts, 4 success, with the probability of success equal to 0.8

>>> import scipy
>>> scipy.stats.nbinom.pmf(6,4,0.8)
0.002202009599999998

And if I try to do it the opposite way as suggested here.

Given 6 attempts, 2 failures, with the probability of failure equal to 0.2

>>> scipy.stats.nbinom.pmf(6,2,0.2)
0.07340032

Can someone point out the error of my interpretation?

1 Answers

Sorry, I see now the issue.

The scipy nbinom.pmf function should be read as:

scipy.stats.nbinom.pmf(num_failures, num_successes, prob_of_success)

Where num_failures + num_successes = total_cases

So in my case, the args should have been:

Given 6 attempts, 4 success, with the probability of success equal to 0.8

>>>> scipy.stats.nbinom.pmf(2,4,0.8)
0.16383999999999996

I still wonder why scipy has chosen this format...

Related