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.

Topic probability scipy python statistics

Category Data Science


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 trials 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’ trials are the success and remaining ‘n – r’ trials 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’ trials 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!


>>> 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$$

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.