How to calculate binomial cumulative density function with python

Question:

I have the following binomial distribution:

Last year, the number of new buildings in Community Board 12 and Community Board 11 in the bronx was 347. Of those 347, 107 took place in Community Board 12.

If we randomly select 70 of the 347 new buildings, the probability distribution would be:

X ~ B (70, 107/ 347)

If I want to know the probability that of those 70 randomly selected new buildings, 20 take place in Community Board 12, I would do in the following way using scipy.stats:

binom.pmf (20, 70, 0.3083573487)                                                                                                                                                                  
0.09646726155763652

If I want to know the probability that of those 70 randomly selected buildings, less or equal to 20 buildings took place in Community Board 12, I would it the following way using scipy.stats:

binom.cdf (20, 70, 0.3083573487)                                                                                                                                                                  
0.39547679625297977

If I want to know the probability that of those 70 randomly selected buildings only less than 20 took place in Community Board 12, I would do the following way using scipy.stats:

binom.cdf (20, 70, 0.3083573487, loc = 1)                                                                                                                                                         
0.2990095346953431

What I am having trouble with is finding out the probability that of those 70 randomly selected new buildings, 20 or more take place in Community Board 12. I know that the results should be 0.60452320375, but I can’t find the scipy.stats command to get this results.

Any help, greatly appreciated.

Thanks.

Asked By: Leito

||

Answers:

Since the cdf(x) of a probability distribution is the integral from negative infinity to x, the integral of x to positive infinity is 1-cdf(x). So for your problem it would simply be:

probabilityGreaterThan20inCommunity12 = 1 - binom.cdf (20, 70, 107./347)

Alternatively use the binom.sf method

probabilityGreaterThan20inCommunity12 = binom.sf (20, 70, 107./347)
Answered By: alexpiers
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.