3.4 Comparing Theoretical and Empirical Probabilities

Last updated: March 8th, 2020

Comparing Theoretical and Empirical Probabilities¶

In the first section we introduced the concept of empirical probability as the relative frecuency of a given outcome.

Now that we know how to calculate some theoretical probabilities, let's perform some experiments and compare them!

Remember the last experiment of throwing a dice $5$ times. We calculated the probability of getting all ones as

In [10]:
p_all_ones = (1/6) ** 5
p_all_ones

Out[10]:
0.00012860082304526745

Now, let's model this experiment, and see what the relative frequency is:

In [11]:
import random

In [12]:
def throw_dice():
return [random.randint(1,6) for _ in range(5)]

In [18]:
throw_dice()

Out[18]:
[1, 3, 5, 1, 5]

Given $n$ throws, let's count how many are all ones.

In [14]:
def count_all_ones(n):
amount_found = 0
for _ in range(n):
dice = throw_dice()
if dice == [1,1,1,1,1]:
amount_found +=  1
return amount_found

In [15]:
def prob(n):
return count_all_ones(n)/n

In [24]:
prob(1_000_000)

Out[24]:
0.000145

We can see that the empirical probability gets closer to the theoretical probability as we throw the dice more times.

In [28]:
abs(prob(1_000_000)-p_all_ones)

Out[28]:
5.600823045267438e-06