DEV Community

Artik Blue
Artik Blue

Posted on

More about probability: Binomial distributions

Let's go back to our previous coin throwing example!

Let's suppose that we flip a regular coin two times. How many times will we get two heads or two tails?

Exactly two! Good easy

Now let's flip it five times. How many outcomes do have the same number of heads than tails? Weeell... it will be zero, as five is an even number, you see sometimes we can know the result easily without having to do a lot of math behind.

Going back to the same example, let's now say 1 heads and then 4 tails, in how many ways can we achieve that? There are five scenarios when this is posible. We can image five slots each slot being one throw and as we are looking for 1 head only, the head can be in only one position at a time, so it can move through every slot but be in one slot at a time. But if we now want to know about scenarios with 2 heads, this gets complicated.

You can think about that this way: We have 5 slots and heads can be in 2 slots at a time, so if the first head is on one spot, then the other one has 4 slots to move on so it would be 4 * 5.

But... those hads can move to diferent positions but those are not independent entities, they are events so we cannot understand them as head1 and head2 being their permutation a diferent scenario. We'll have to divide by two to get rid of those permutations.

The calculation will be

5*4/2 = 10

If instead of two heads we want three of them, the calculation is similar

5*4*3 / 3*2*1

Again we have five slots for the first head, four for the second and three for the third, but we need to avoid those permutation scenarios (for the first throw the coin can be in one out of three positions, for the second throw in two, one for the last throw).

As you already saw, there can be a generalization related to this process. We see that we are dividing by numbers that are a result of a secuence of multiplication from the number itself all the way down to one, that is called the factorial and it looks like this:

n! = n*(n-1)*(n-2)...*1

So something like

5*4*3 / 3*2*1

Can also be represented as:

5*4*3 / 3!

Understanding this we can define the formula for calculating the posible situations on a particular event can happen, the binomial distribution:

n! / k! * (n-k)!

Where n is the number of times a phenomenon repeats (ex: 10 coin flips) and k is the times a result has to repeat (ex: 5 heads) assuming that we only have two options (heads or tails) for the phenomenon.

Let's apply the rule to calculate real probabilities withouth having to draw
those tedious truth tables:

We flip a coin 5 times and we want to get EXACTLY one heads, whats the probability?

The total amount of situations we can expect to have on that phenomenon is 2^5 = 32 (32 combinations of diferent results)

The about the specific situations we are interested in:

n = 5
k = 1

5! / (5-1) * 1 = 5

So 5/32 = 0.15625

That is our probability

But what if the coin is loaded and P(heads) is 0.8?

Again, we can start by calculating the number of scenarios when this will happen:

5! / 4! * 1! = 5;

And on this situation(s) we will get heads 5 times and tails one so it will be something like

1*0.8 * 1*0.8..... *1*0.2 (probability of tails * 1 tails) In other terms:

0.8^4 * 0.2^1

So 0.4

Now you know about the binomial distribution... use this knowledge with responsability...

Top comments (0)