# Nakafa Learning Content

> For AI agents: use [llms.txt](https://nakafa.com/llms.txt) for the site index. Markdown versions are available by appending `.md` to content URLs or sending `Accept: text/markdown`.

URL: https://nakafa.com/en/subjects/mathematics/statistics-foundations/interquartile-range
Source: https://raw.githubusercontent.com/nakafaai/nakafa.com/refs/heads/main/packages/contents/material/lesson/mathematics/statistics-foundations/interquartile-range/en.mdx

Calculate interquartile range to measure data spread. Learn lower and upper quartiles, compare with range, and understand middle data variation.

---

## What Is the Interquartile Range?

We already know how to find the [mean](/en/subjects/mathematics/statistics-foundations/mean) of data. But sometimes, the mean alone isn't enough to describe the data. Imagine two groups of friends with the same average age, but when you look closer, the age spread within each group is very different.

This is where the **Interquartile Range** ($$\mathrm{IQR}$$) comes in handy! The $$\mathrm{IQR}$$ is a measure of data spread that focuses on the **middle $$50\%$$ of the data** after it has been sorted.

Visible text: This is where the **Interquartile Range** () comes in handy! The is a measure of data spread that focuses on the **middle of the data** after it has been sorted.

Why focus on the middle? Sometimes data has values at the extremes (too small or too large, called outliers) that can make other spread measures (like the Range) less accurate. The $$\mathrm{IQR}$$ is more "resistant" to these extreme values.

Visible text: Why focus on the middle? Sometimes data has values at the extremes (too small or too large, called outliers) that can make other spread measures (like the Range) less accurate. The is more "resistant" to these extreme values.

The $$\mathrm{IQR}$$ formula is super simple:

Visible text: The formula is super simple:

```math
\mathrm{IQR} = Q_3 - Q_1
```

- $$Q_3$$ is the Upper Quartile (the value marking the bottom $$75\%$$
  of the data).
- $$Q_1$$ is the Lower Quartile (the value marking the bottom $$25\%$$
  of the data).

Visible text: - is the Upper Quartile (the value marking the bottom 
 of the data).
- is the Lower Quartile (the value marking the bottom 
 of the data).

So, the $$\mathrm{IQR}$$ is the difference between the upper and lower quartiles.

Visible text: So, the is the difference between the upper and lower quartiles.

## Comparing Age Spreads

To make it clearer, let's look at an example.

There are two groups, each with $$12 \text{ people}$$. Let's look at their age data in the table below:

Visible text: There are two groups, each with . Let's look at their age data in the table below:

| Data Point # | Group One | Group Two |
| :----------: | :-------: | :-------: |
| $$1$$ | $$13$$ | $$1$$ |
| $$2$$ | $$14$$ | $$3$$ |
| $$3$$ | $$15$$ | $$4$$ |
| $$4$$ | $$15$$ | $$5$$ |
| $$5$$ | $$16$$ | $$7$$ |
| $$6$$ | $$16$$ | $$8$$ |
| $$7$$ | $$17$$ | $$12$$ |
| $$8$$ | $$17$$ | $$27$$ |
| $$9$$ | $$17$$ | $$28$$ |
| $$10$$ | $$17$$ | $$29$$ |
| $$11$$ | $$17$$ | $$32$$ |
| $$12$$ | $$18$$ | $$36$$ |

Visible text: | Data Point # | Group One | Group Two |
| :----------: | :-------: | :-------: |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |

Let's calculate some statistics for these two groups.

### Calculating the Mean and Quartiles

1.  **Mean (Average):**

    If you calculate the average age for both groups, the result is **exactly the same**, $$16 \text{ years}$$ old.

    Group $$1$$:

    
    
    ```math
    \frac{13+14+15+15+16+16+17+17+17+17+17+18}{12} = \frac{192}{12} = 16
    ```

    Group $$2$$:

    
    
    ```math
    \frac{1+3+4+5+7+8+12+27+28+29+32+36}{12} = \frac{192}{12} = 16
    ```

2.  **Quartiles ($$Q_1$$ and $$Q_3$$):**

    After sorting the data (as in the table above), we find the positions of the quartiles.

    **Group One ($$n=12$$):**
    The position of $$Q_1$$ is at data point $$\frac{1}{4}(12+1) = 3.25$$. This means $$Q_1$$ is between the $$3^{\text{rd}}$$ ($$15$$) and $$4^{\text{th}}$$ ($$15$$) data points. Since both values are the same, then

    
    
    ```math
    Q_1 = 15
    ```

    The position of $$Q_3$$ is at data point $$\frac{3}{4}(12+1) = 9.75$$. This means $$Q_3$$ is between the $$9^{\text{th}}$$ ($$17$$) and $$10^{\text{th}}$$ ($$17$$) data points. Since both values are the same, then

    
    
    ```math
    Q_3 = 17
    ```

    **Group Two ($$n=12$$):**
    The position of $$Q_1$$ is at data point $$3.25$$. This means $$Q_1$$ is between the $$3^{\text{rd}}$$ ($$4$$) and $$4^{\text{th}}$$ ($$5$$) data points. In this case, we can take the average of these two data points:

    
    
    ```math
    Q_1 = \frac{4+5}{2} = 4.5
    ```

    The position of $$Q_3$$ is at data point $$9.75$$. This means $$Q_3$$ is between the $$9^{\text{th}}$$ ($$28$$) and $$10^{\text{th}}$$ ($$29$$) data points. Similarly, we take their average:

    
    
    ```math
    Q_3 = \frac{28+29}{2} = 28.5
    ```

Visible text: 1. **Mean (Average):**

 If you calculate the average age for both groups, the result is **exactly the same**, old.

 Group :

 
 

 Group :

 
 

2. **Quartiles ( and ):**

 After sorting the data (as in the table above), we find the positions of the quartiles.

 **Group One ():**
 The position of is at data point . This means is between the () and () data points. Since both values are the same, then

 
 

 The position of is at data point . This means is between the () and () data points. Since both values are the same, then

 
 

 **Group Two ():**
 The position of is at data point . This means is between the () and () data points. In this case, we can take the average of these two data points:

 
 

 The position of is at data point . This means is between the () and () data points. Similarly, we take their average:

### Calculating the Range and Interquartile Range

Now let's calculate the measures of spread.

1.  **Range:**

    $$\text{Range} = \text{maximum value} - \text{minimum value}$$

    - Range Group One is $$18 - 13 = 5$$
    - Range Group Two is $$36 - 1 = 35$$

      Wow, the ranges are very different! Group Two's data is much more spread out when looking at the extreme values.

2.  **Interquartile Range** ($$\mathrm{IQR}$$):

    $$\mathrm{IQR} = Q_3 - Q_1$$

    - $$\mathrm{IQR}$$ Group One is $$17 - 15 = 2$$
    - $$\mathrm{IQR}$$ Group Two is $$28.5 - 4.5 = 24$$

      The $$\mathrm{IQR}$$ values are also very different!

Visible text: 1. **Range:**

 

 - Range Group One is 
 - Range Group Two is 

 Wow, the ranges are very different! Group Two's data is much more spread out when looking at the extreme values.

2. **Interquartile Range** ():

 

 - Group One is 
 - Group Two is 

 The values are also very different!

### Interpreting the Results

Let's summarize in a table for easy comparison:

| Group | Mean | $$Q_1$$ | $$Q_3$$ | Range | Interquartile Range ($$\mathrm{IQR}$$) |
| :---: | :--: | :----------------------: | :----------------------: | :---: | :-----------------------: |
|  One  | $$16$$ | $$15$$ | $$17$$ | $$5$$ | $$2$$ |
|  Two  | $$16$$ | $$4.5$$ | $$28.5$$ | $$35$$ | $$24$$ |

Visible text: | Group | Mean | | | Range | Interquartile Range () |
| :---: | :--: | :----------------------: | :----------------------: | :---: | :-----------------------: |
| One | | | | | |
| Two | | | | | |

- Both groups have the **same Mean (average) age**, which is $$16$$.
- But their **Range** and $$\mathrm{IQR}$$ values are **very different**.
- **Group One** has a small Range ($$5$$) and a very small $$\mathrm{IQR}$$ ($$2$$). This means the ages of people in Group One are **very close together**, especially the middle $$50\%$$, whose ages only differ by $$2 \text{ years}$$ ($$Q_1=15, Q_3=17$$). The data is **clustered** around the mean.
- **Group Two** has a large Range ($$35$$) and a large $$\mathrm{IQR}$$ ($$24$$). This means the ages of people in Group Two are **much more spread out**. Even the middle $$50\%$$ spans $$24 \text{ years}$$ ($$Q_1=4.5, Q_3=28.5$$). The data is **not as clustered** as Group One.

Visible text: - Both groups have the **same Mean (average) age**, which is .
- But their **Range** and values are **very different**.
- **Group One** has a small Range () and a very small (). This means the ages of people in Group One are **very close together**, especially the middle , whose ages only differ by (). The data is **clustered** around the mean.
- **Group Two** has a large Range () and a large (). This means the ages of people in Group Two are **much more spread out**. Even the middle spans (). The data is **not as clustered** as Group One.

Even if the average is the same, the spread of the data can be very different. The $$\mathrm{IQR}$$ helps us see how spread out the middle part of the data is, giving a better picture of data variation than just looking at the mean or range, especially when there are extreme values.

Visible text: Even if the average is the same, the spread of the data can be very different. The helps us see how spread out the middle part of the data is, giving a better picture of data variation than just looking at the mean or range, especially when there are extreme values.