DEV Community

Artik Blue
Artik Blue

Posted on

Introduction to probability

Statistics and probability are very related! Probability makes predictions about future events based on models and statistics studies data (imagine, events that already happened and produced results) to gather information about them and perhaps maybe build models.

Imagine we have a coin and we flip it to see if we get heads or tails. By fliping the coin we are making data, data that can be studied later on to for gaining more knowledge about the phenomenon.

So we flip it once and we get heads. At that point our data will be DATA={Heads}, we flip it again and... heads another time, so then DATA={Heads,Heads} and then we go for a third time and we get tails so finally DATA={Heads, Heads, Tails}. At that point, if we stop the experiment right there we might think that one time in every three times the coin returns Tails, the rest of the times Heads or in other terms: Probability(Tails) = 1/3. And what about the probability of Heads, then as we get Heads 2 times every 3 throws it will be 2/3. If we add Probability(Tails) + Proability(Heads) we get 1, so another way of getting the probability of let's say Heads is to do 1-Probability(Tails), thats called the complementary probability!

And that may be true but, what if we repeat this experiment milions of times and we keep track of every result?

Well in that case we will probably get something as: P(tails) = 1/2. Think about it that way: If a coin has two sides, we can only get heads or tails one result per throw, and if the coin is perfectly balanced, it is common sense that we can either get one or another right? So our experimental data should demonstrate that.

Now we will assume that our coin is perfectly balanced, we have a probability of 1/2 for every result.

What if we want to know the probability of getting Heads two times, one after another by throwing the coin two consecutive times.

Now that we know a little bit about probability, let's image all posible situations and try to use the rule we just presented:

FLIP 1 FLIP 2 PROBABILITY
H H 0.25
H T 0.25
T H 0.25
T T 0.25

We can derive that the probability of getting two heads will be 0.25 knowing that the probability of each of the posible outcomes or results of this phenomenon (throwing a coin 2 consecutive times) needs to add to 1. So we have four posible situations each one of them equally probable thus 0.25 is the probability of each one to happen. Another way of thinking about that is just to multiply 0.5 (the probability of getting a head) by the probability of getting heads (0.5).

What about the probability of getting two heads when the coin is loaded and we know that we can get heads with a probability of 0.6 (and thus probability of tails will be... 0.4)? If we follow that rule we just learnt, that is easy, we can multiply 0.6 by itself and we get it!.

The table will look like that this time:

FLIP 1 FLIP 2 PROBABILITY
H H 0.36
H T 0.24
T H 0.24
T T 0.16

We may think that we know all about coin throws and probabilitty right now but there are several other questions to be asked, for example...what if we want to know the probability of getting exactly one head?

Regarding to our loaded coin, let's look at the table one more time

FLIP 1 FLIP 2 PROBABILITY
H H 0.36
H T 0.24
T H 0.24
T T 0.16

There are two posible situations when we are getting exactly one head. (H,T) and (T,H) on those others we get more than one head or no heads at all.

FLIP 1 FLIP 2 PROBABILITY
H T 0.24
T H 0.24

We can calculate the probability of getting exactly one head by adding those two probabilities together. So the total probability will be 0.48.

In situations such as the one we just reviewed the product is asociated with AND and the addition with OR. Our last example could be written like:

The probability of getting exactly one Head is:

The probability of getting Heads AND Tails OR The probability of getting Tails AND Heads.

Voilà!

For the extra mille, let's now imagine a standard dice. The probability of getting one of the possible results is 1/6. What's the probability of getting an even number? As ech result has a probabilitty of 1/6, the probability of an even number will be 3/6 or 1/2 as it can be represented as:

The probability of getting a one OR getting a three OR getting a five.

And about getting the same number twice on a two times dice throw??

Well, we just need to think about the situations when we will have the same number twice, calculate their individual probability and add it all together :)

FLIP 1 FLIP 2 PROBABILITY
1 1 1/6 * 1/6
2 2 1/6 * 1/6
3 3 1/6 * 1/6
4 4 1/6 * 1/6
5 5 1/6 * 1/6
6 6 1/6 * 1/6

And... that add ups to 1/6 again!!

Top comments (0)