Median

When analyzing a dataset, understanding its central tendency is crucial. While the mean (average) is a common measure, it can be heavily influenced by extreme values. The median offers an alternative, representing the exact middle value of an ordered dataset. It provides a robust measure of central tendency, making it particularly useful in situations where data might be skewed or contain outliers.

Median
The median is the middle value in a dataset that has been ordered from least to greatest. If there are two middle values, the median is the average of those two values.
Example: For the dataset [1, 3, 5, 7, 9], the median is 5. For [1, 3, 5, 7], the median is (3+5)/2 = 4.

Calculating the Median for Odd Data Sets

When a dataset contains an odd number of data points, calculating the median is straightforward. The first step is always to arrange all data points in ascending (or descending) order. Once ordered, the median is simply the value located at the exact center of this sorted list. This central position ensures that an equal number of data points lie above and below the median.

pythonMedian Calculation for Odd Number of Data Points
📐 Median Position (Odd N)

For a dataset with an odd number of observations, NN, the median is the value at the position (N+1)/2(N+1)/2 after sorting.

Calculating the Median for Even Data Sets

When a dataset contains an even number of data points, there isn't a single 'middle' value. In this scenario, after sorting the data, the median is calculated by taking the average of the two central values. This approach ensures that the median still represents the point where 50% of the data falls below it and 50% falls above it, maintaining its role as a measure of central tendency.

pythonMedian Calculation for Even Number of Data Points
📐 Median Position (Even N)

For a dataset with an even number of observations, NN, the median is the average of the values at positions N/2N/2 and (N/2)+1(N/2)+1 after sorting.

Check Your Understanding
You are given the dataset: [15, 22, 10, 30, 18, 25]. What is the median?

Median's Robustness to Outliers

One of the most significant advantages of the median over the mean is its robustness to outliers. An outlier is an extreme value that significantly deviates from other observations in a dataset. While a single outlier can drastically pull the mean towards its value, the median, being based on the position of values rather than their magnitude, remains relatively unaffected. This characteristic makes the median a more reliable measure of central tendency for skewed distributions or datasets with unusual extreme values.

Mean vs. Median: Impact of an Outlier
This chart compares the values of the mean and median for two datasets: one without an outlier and one with a significant outlier. Observe how the mean changes dramatically, while the median remains stable.
Loading chart...
Key Insight: The mean is highly sensitive to outliers, showing a large shift, whereas the median remains relatively stable, demonstrating its robustness.

When to Prefer the Median

Given its robustness, the median is often the preferred measure of central tendency in several real-world scenarios. It is particularly valuable when dealing with skewed distributions, such as income levels, housing prices, or response times, where a few extremely high or low values can distort the average. Additionally, for ordinal data, where values have a meaningful order but the differences between them are not necessarily uniform (e.g., survey ratings like 'poor', 'fair', 'good', 'excellent'), the median provides a more appropriate central measure than the mean.

Mean vs. Median: Choosing the Right Measure
FeatureMeanMedian
DefinitionAverage of all valuesMiddle value of sorted data
Sensitivity to OutliersHighly sensitiveRobust (less sensitive)
Data TypeInterval, RatioOrdinal, Interval, Ratio
Distribution TypeSymmetric, NormalSkewed, Non-normal
Uses all data values?Yes (magnitude)No (only position/order)
A quick guide to help decide between using the mean or the median based on data characteristics.
pythonMedian in a Skewed Dataset (Housing Prices)
Distribution of Housing Prices with Median and Outliers
This box plot visualizes the distribution of housing prices, clearly showing the median, quartiles, and the presence of high-value outliers. The median line indicates the central tendency, while the long upper whisker and individual outlier points highlight the skewness.
Loading chart...
Key Insight: The box plot visually confirms that the median (575k) is a more central representation of typical housing prices, with significant outliers pulling the distribution's upper tail.
Check Your Understanding
A company is reporting the 'average' salary of its employees. If the company has a few highly paid executives and many entry-level employees, which measure of central tendency would likely give a more representative picture of a 'typical' employee's salary?

Limitations of the Median

While the median's robustness is a significant strength, it also comes with certain limitations. Because it only considers the position of data points and not their actual magnitudes (beyond ordering), it doesn't utilize all available information in the dataset. This can make it less sensitive to changes in the extreme values of the distribution, which might be important in some analyses. For instance, if all values above the median increase significantly, the median itself might not change, unlike the mean which would reflect this shift.

Key Takeaways
  • The median is the middle value of a dataset when ordered, providing a robust measure of central tendency.

  • For an odd number of data points, the median is the single middle value after sorting.

  • For an even number of data points, the median is the average of the two middle values after sorting.

  • The median is highly robust to outliers and extreme values, unlike the mean, which can be significantly skewed.

  • Prefer the median for skewed distributions (e.g., income, housing prices) or ordinal data to get a more representative 'typical' value.

  • While robust, the median does not utilize the magnitude of all data points, only their order, which can be a limitation in some contexts.

← All lessons in Descriptive Statistics

Ready to keep this from fading?

Bitelrn turns lessons like this into a full course — quizzes, a knowledge map, and spaced review.

Get started free