2022-03-24

Range and Quartile

Introduction

One of the fundamental concepts in statistics is the idea of variability, which refers to how much the data varies from one observation to another. Two important measures of variability in statistics are range and quartiles.

Range

The range is the difference between the largest and smallest values in a dataset.

Calculation

To calculate the range, subtract the smallest value from the largest value.

Range = Largest value - Smallest value

Example

Suppose we have a dataset of test scores for a group of students: 65, 70, 75, 80, 85. The smallest value is 65 and the largest value is 85. Therefore, the range of the dataset is:

Range = 85 - 65 = 20

Quartiles

Quartiles are values that divide a dataset into four equal parts.

Calculation

To calculate the quartiles, first arrange the dataset in order from smallest to largest. Then, find the median of the entire dataset. The median splits the dataset into two halves. The first quartile (Q1) is the median of the lower half of the dataset, and the third quartile (Q3) is the median of the upper half of the dataset. The second quartile (Q2) is the same as the median of the entire dataset.

Example

Let's use the same dataset of test scores from before: 65, 70, 75, 80, 85. First, we arrange the dataset in order: 65, 70, 75, 80, 85. The median is 75, which is the second quartile (Q2). The lower half of the dataset consists of 65, 70, and 75. The median of this lower half is 70, which is the first quartile (Q1). The upper half of the dataset consists of 80 and 85. The median of this upper half is 82.5, which is the third quartile (Q3).

Python Implementation of Range and Quartiles

Here's a Python implementation of range and quartiles:

python
data = [65, 70, 75, 80, 85]
range = max(data) - min(data)
print("Range:", range)

# Quartiles
data_sorted = sorted(data)
n = len(data_sorted)
Q1 = data_sorted[n//4]
Q2 = data_sorted[n//2]
Q3 = data_sorted[(3*n)//4]
print("Q1:", Q1)
print("Q2:", Q2)
print("Q3:", Q3)
Range: 20
Q1: 70
Q2: 75
Q3: 85

In this implementation, we first calculate the range by subtracting the minimum value from the maximum value. Then, we calculate the quartiles by first sorting the data, finding the median (Q2), and then finding the medians of the lower and upper halves of the data to get Q1 and Q3, respectively.

Ryusei Kakujo

researchgatelinkedingithub

Focusing on data science for mobility

Bench Press 100kg!