Median

Rumman Ansari   Software Engineer   2023-02-23   146 Share
☰ Table of Contents

Table of Content:


Median

The median is a statistical measure of central tendency that represents the middle value of a dataset when it is arranged in ascending or descending order. To calculate the median of a dataset, you need to have the following prerequisites:

  1. A dataset: You must have a set of numerical data for which you want to calculate the median.
  2. Ordered data: The data should be arranged in either ascending or descending order.
  3. Odd or even number of data points: If the dataset has an odd number of data points, then the median is the middle value. If the dataset has an even number of data points, then the median is the average of the two middle values.
  4. Numeric data: The data must be numeric, meaning that it can be measured or counted. If the data is categorical, such as a list of names or colors, then the median cannot be calculated.

Once you have these prerequisites, you can easily calculate the median of the dataset by following a simple formula based on the number of data points and the position of the middle value(s).


Median - Formula

The formula for calculating the median of a set of data with n elements is:

\begin{equation} \text{Median} = \begin{cases} x_{(n+1)/2} & \text{if } n \text{ is odd} \ \frac{x_{n/2} + x_{(n/2)+1}}{2} & \text{if } n \text{ is even} \end{cases} \end{equation} $$\text{Median}=\begin{cases} x_{\frac{n+1}{2}} & \text{if $n$ is odd} \ \frac{x_{\frac{n}{2}}+x_{\frac{n}{2}+1}}{2} & \text{if $n$ is even} \end{cases}$$

where x is the sorted data set.


Here is the formula for calculating the median of a dataset with an odd number of values:

$$\text{Median} = x_{\frac{n+1}{2}}$$

And here is the formula for calculating the median of a dataset with an even number of values:

$$\text{Median} = \frac{x_{\frac{n}{2}} + x_{\frac{n}{2}+1}}{2}$$ where \(x_{i}\) represents the \(i^{th}\) value of the dataset and \(n\) is the number of values in the dataset.

Example 1:

Here's an example of the median of a set of numbers:

Given the dataset \(X = {3, 6, 2, 8, 5} \), we can find the median as follows:

First, we need to arrange the dataset in order: \(X = {2, 3, 5, 6, 8} \).

If the number of observations \(n \) is odd, then the median \(M \) is the middle value in the ordered dataset. In this case, \(n = 5 \), which is odd, so the median is:

$$M = \frac{n + 1}{2} = \frac{5 + 1}{2} = 3$$

Thus, the median of the dataset \(X \) is \(M = 5 \).


Example 2:

Let's consider a dataset \(X = {4, 7, 9, 12, 16}\). To find the median of this dataset, we first need to order the numbers in ascending or descending order. In this case, the ordered dataset is \(X = {4, 7, 9, 12, 16}\).

If the number of observations \(n\) is odd, then the median \(M\) is the middle value in the ordered dataset. In this case, \(n = 5\), which is odd, so the median is:

\begin{equation} M = \frac{n + 1}{2} = \frac{5 + 1}{2} = 3 \end{equation}

Thus, the median of the dataset \(X\) is \(M = 9\).


Example 3:

Let's say we have a set of numbers: \(X =2, 5, 7, 10, 13, 14\) . To calculate the median of this set, we first need to order the numbers in ascending or descending order. In this case, the ordered set is: \(X = 2, 5, 7, 10, 13, 14\) .

If the number of observations \(n\) is even, then the median \(M\) is the average of the two middle values in the ordered dataset. In this case, \(n = 6\) , which is even, so the median is:

\begin{equation} M = \frac{\text{the } \frac{n}{2} \text{th observation} + \text{the } \frac{n}{2} + 1 \text{th observation}}{2} = \frac{7 + 10}{2} = 8.5 \end{equation}

Therefore, the median of the set of numbers \(2, 5, 7, 10, 13, 14\) is \(8.5\) .