<b>The Relative Frequency</b> of any random variable is the number of occurance in the total number of observation. 
The Relative Frequency is calculated as:<br>
\begin{equation}
Relative Frequency = \frac{Frequency}{Total\ number\  of\ observations}
\end{equation}<br>
E.g. We have a samples are like { 5,7,11,19,23,5,18,7,18,23 }. If we calculate the relative frequency of each unique values then it will be as:<br>
${R.F of (5)} = {\frac {2}{10}}$<br>
${R.F of (7)} = {\frac {2}{10}}$<br>
${R.F of (11)} = {\frac {1}{10}}$<br>
${R.F of (18)} = {\frac {2}{10}}$<br>
${R.F of (19)} = {\frac {1}{10}}$<br>
${R.F of (23)} = {\frac {2}{10}}$<br>

Whereas, <b>Probability</b> is actually the limiting case of the <b> Relative Frequency </b> when the sample approaches(limits) towards population. 

Going to demonstrate that probability is actually the limiting case of relative frequency when the sample slowly approaches population.

Lets first take an example of binomial random variable where we are taking a sample of observations (responses) arrising due to repititive conduction of a binomial experiment. Which means that we are going to perform some experiment 'N' number of times where each each conduction of experiment (trial) will result in an obervation or response of a trial out of two possible responses. Lets say that our binomial trial is the toss of a coin where each toss is going to give us one of the two responses : Either Heads or Tails. 

As we are in statistical domain, we will evaluate the relative frequencies of heads as well as tails as:

\begin{equation}
r = \frac{h}{N}
\end{equation}

Where, r = Relative Frequency.
       h = Number of Binomial Experiments in which heads was the outcome.
       N = Total number of times binomial experiment has been conducted. 


```python
# Importing the Numpy library alias np and matplotlib library alias plt
import numpy as np
import matplotlib.pyplot as plt
```

Going to conduct a binomial experiment (having two results either Head or Tail) for N=10 times and considering that the coin used in coin tossing is an unbiased coin, i.e. p=q=0.5


```python
N = 10
psuccess = 0.5
qfailure = 1-psuccess
ExperimentOutcomes = np.random.binomial(N,psuccess)
```


```python
ExperimentOutcomes
```




    4



We tossed an unbiased coin 10 times, we got only 4 heads. So, the relative frequency is given by:

\begin{equation}
r = \frac{h}{N} = \frac{4}{10} = 0.4
\end{equation}

Let's toss an unbiased coin 100 times and see what happens. 


```python
N = 100
ExperimentOutcomes = np.random.binomial(N,psuccess)
```


```python
ExperimentOutcomes
```




    54



We tossed a coin 100 times, we got 54 heads. So, the relative frequency is given by:

\begin{equation}
r = \frac{h}{N} = \frac{54}{100} = 0.54
\end{equation}

Let's toss an unbiased coin 10000 times and see what happens.


```python
N = 10000
ExperimentOutcomes = np.random.binomial(N,psuccess)
```


```python
ExperimentOutcomes
```




    4972



We tossed a coin 10000 times, we got 4972 heads. So, the relative frequency is given by:

\begin{equation}
r = \frac{h}{N} = \frac{4972}{10000} = 0.4972
\end{equation}

Let's toss a coin 100000 times and see what happens.


```python
N = 100000
ExperimentOutcomes = np.random.binomial(N,psuccess)
```


```python
ExperimentOutcomes
```




    49991



We tossed a coin 100000 times, we got 49991 heads. So the relative frequency is given by:

\begin{equation}
r = \frac{h}{N} = \frac{49991}{100000} = 0.49991
\end{equation}

The theoretical answer to the probability of getting heads in a single toss is 0.5 and we can observe that as we are increasing the number of tosses, we are approaching the theoretical value of probability in terms of relative frequency.

This phenomena can also be shown by plotting relative frequencies of heads with increasing sample sizes which are slowly approaching population. 


```python
#we are trying to get the values from the lower limit=10, higher limit=500 
#in the interval of 10.
Ns = np.arange(10,500,10)
```


```python
Ns
```




    array([ 10,  20,  30,  40,  50,  60,  70,  80,  90, 100, 110, 120, 130,
           140, 150, 160, 170, 180, 190, 200, 210, 220, 230, 240, 250, 260,
           270, 280, 290, 300, 310, 320, 330, 340, 350, 360, 370, 380, 390,
           400, 410, 420, 430, 440, 450, 460, 470, 480, 490])



We have generated different sample sizes at the gap of 10 tosses. 


```python
ExperimentOutcomes = np.random.binomial(Ns,psuccess)
```

We have tossed an unbiased coin at different values of total tosses(N) and recorded the number of heads(h) during several number of total tosses. 


```python
RelativeFrequencies = ExperimentOutcomes/Ns
```

We have now calculated relative frequencies by dividing the number of heads(h) which we observed during different values of N.


```python
plt.stem(Ns,RelativeFrequencies)
```

As we can observe from above plot that as we are tossing a coin more number of times, the relative frequency of heads is approaching towards psuccess = 0.5. 

Now, let's change the psuccess to 0.65 and plot the similar graph once again. 


```python
psuccess = 0.65
ExperimentOutcomes = np.random.binomial(Ns,psuccess)
```


```python
RelativeFrequencies = ExperimentOutcomes/Ns
```


```python
plt.stem(Ns,RelativeFrequencies)
```

As we can observe from above plot that as we are tossing a coin more number of times, the relative frequency of heads is approaching towards psuccess = 0.65. 

Now, let's change the psuccess to 0.35 and plot the similar graph once again. 


```python
psuccess = 0.35
ExperimentOutcomes = np.random.binomial(Ns,psuccess)
```


```python
RelativeFrequencies = ExperimentOutcomes/Ns
```


```python
plt.stem(Ns,RelativeFrequencies)
```

As we can observe from above plot that as we are tossing a coin more number of times, the relative frequency of heads is approaching towards psuccess = 0.35. 


```python

```

dc72aaae23f93222c2e9a24d0a9c582d48e3c5f5
ipynb
Jupyter Notebook
1. Relative Frequency and Probability and their relation.ipynb
rarpit1994/Probability-and-Statistics
1ae8b7428ec9a3072fce3089d7951b9f7bd06c26
Apache-2.0
2019-03-24T10:29:56.000Z
2019-03-24T10:29:56.000Z
1. Relative Frequency and Probability and their relation.ipynb
rarpit1994/Probability-and-Statistics
1ae8b7428ec9a3072fce3089d7951b9f7bd06c26
Apache-2.0
1. Relative Frequency and Probability and their relation.ipynb
rarpit1994/Probability-and-Statistics
1ae8b7428ec9a3072fce3089d7951b9f7bd06c26
Apache-2.0
Qwen/Qwen-72B
1. YES
2. YES