# How do I properly write scipy.stats.binom.cdf() details

I need to calculate the probability of my random variable being $$\le 0$$. It's a binomial distribution, $$10000$$ trials, probability of success is $$\frac{10}{19}$$ (roughly $$0.53$$).

How do I properly use the scipy.stats.binom.cdf() to do that?

I've tried the following:

stats.binom(10000, a).cdf(0)


But it gives me an answer $$0$$.

I feel like I might be missing something about the formula itself.

>>> from scipy.stats import binom
>>> binom.cdf(0, 10000,10/19)
0.0


Binomial random variable are nonnegative. Hence you want to compute the probability that it is equal to zero which is

$$\left(\frac{10}{19} \right)^{10000}\approx 10^{-2787.54}\approx 0$$

• Siong, thank you! I was trying to replicate the R function: pbinom(1000/2-1, size = 1000, prob = 10/19) from link , here is the working solution in Python binom.cdf(1000/2 -1, 1000,10/19)  with the result = $0.045$ . What bothers me is that result changes so much when I change n from $1000$ to $10000$. And deviates drastically from my similations that gives a similar to $0.045$ result. – Polina May 5 '19 at 15:16
• i don't quite understand the description. Do you mean that as you change the $n$ from $1000$ to $10000$, there's some unexpected output? – Siong Thye Goh May 5 '19 at 15:25
• @Polina, in the question you're asking for the cdf at zero, but in the code in your comment here you're asking for the cdf at 499 (or 4999)! From your link: "Specifically, in our example above, we can show that (S+n)/2 follows a binomial distribution...to compute Pr(S<0) we note that Pr(S<0)=Pr( (S+n)/2 < (0+n)/2 )." Now that's given by the cdf of the binomial (S+n)/2 at n/2-1. – Ben Reiniger May 5 '19 at 17:01

Code would be:

n=10000
p=10/19
k=0
scipy.stats.binom.cdf(k,n,p)


However, before using any tool [R/Python/ or anything else for that matter], You should try to understand the concept.

Concept of Binomial Distribution:

Let’s assume that a trail is repeated n times. The happening of an event is called a success and the non-happening of the event is called failure.

Let ‘p’ be the probability of success and ‘q’ be the probability of failure in a single trial so that p + q = 1

We assume that all trails are independent and ‘p’ and ‘q’ are the same in each trial.

Now, by compound probability theorem for independent events, the probability that first ‘r’ trails are the success and remaining ‘n – r’ trails are failure is

(p^r)*(q^n-r)

This expression shows the probability of ‘r’ continuous success and ‘n – r’ continuous failures. However, ‘r’ successes in n trials can occur in nCr ways [Combinations of n things, taken r at a time: nCr = n! / r!(n - r)! = nPr / r! ]

Hence by multiplication theorem or probability/compound probability theorem/counting principle for independent events [insert hyperlink], the probability of getting ‘r’ success in ‘n’ trails is given by P (r) = nCr p^r q^n-r, where ‘r’ can be considered as a discrete random variable which takes values from 0, 1, 2, …, up to maximum ‘n’

So theoretically too, x [binomial variate] taking value less than zero is not possible. And

prob[x <= 0 ] = p[x = 0] = q^n

In your case this quantity is negligible.

I hope it helps!