statistics
data analysis
robust computing
mean calculation
statistical methods

How to compute mean average robustly?

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

Computing the mean or average of a set of data points is a fundamental statistical operation. However, calculating a simple arithmetic mean can sometimes be misleading, especially in the presence of outliers or skewed data. To obtain a more robust estimate of the mean, various methods can be employed. This article explores several techniques and considerations for computing a robust mean.

Traditional Arithmetic Mean

The traditional arithmetic mean is given by:

Mean=1n_i=1nx_i\text{Mean} = \frac{1}{n} \sum\_{i=1}^{n} x\_i

where xix_i represents each data point and nn is the total number of data points. While this formula is straightforward and works well with symmetric distributions, it is sensitive to outliers.

Limitations of Arithmetic Mean

The arithmetic mean can be greatly impacted by extreme values. For example, consider a dataset representing the incomes of a neighborhood: `$30,000, 32,000, \31,000, 35,000, and \1,500,000. The mean would be $`325,600, which does not accurately represent the earnings of the majority.

Techniques for Robust Mean Estimation

To mitigate the influence of outliers, several alternative techniques can be employed:

1. Trimmed Mean

The trimmed mean involves removing a specified percentage of the smallest and largest values before calculating the mean. Typically, 5% or 10% of the data points from both ends are excluded.

For a dataset of 20 values, if a 10% trim is applied, the smallest 2 and largest 2 values are removed. Thus, the mean is calculated using the remaining 16 values.

Advantages:

• Reduces the influence of outliers. • Easy to understand and compute.

Disadvantages:

• Requires a subjective decision about what percentage to trim. • Loss of data points.

2. Winsorized Mean

Similar to the trimmed mean, the Winsorized mean replaces outliers with the nearest remaining values instead of discarding them.

For a 10% Winsorized mean: • The smallest 2 values are replaced with the 3rd smallest value. • The largest 2 values are replaced with the 3rd largest value.

Advantages:

• Retains all data points. • Reduces effects of extreme values more gently than trimming.

Disadvantages:

• Still requires choosing a trimming percentage. • More complex to calculate than a simple mean.

3. Median

The median, the middle value of a dataset, is extremely robust to outliers. For an odd number of data points, it is the central value; for an even number, it is the average of the two central values.

Advantages:

• Completely robust to outliers. • Simple to understand and compute.

Disadvantages:

• Does not take full data variability into account. • Less informative than mean in symmetric distributions.

4. Weighted Mean

In a weighted mean, each data point is assigned a weight, reflecting its importance or reliability.

Weighted Mean=_i=1nw_ix_i_i=1nw_i\text{Weighted Mean} = \frac{\sum\_{i=1}^{n} w\_i \cdot x\_i}{\sum\_{i=1}^{n} w\_i}

where wiw_i represents the weight of each data point.

Advantages:

• Allows customization of data points' influence. • Useful for aggregated data from different sources.

Disadvantages:

• Selecting appropriate weights can be subjective. • Not specifically designed to reduce outlier impact.

5. Huber Mean

The Huber mean is a compromise between the mean and median, controlled by a parameter cc. Values within cc of the mean are averaged normally. Values outside are weighted less.

Advantages:

• Adjusts smoothly between mean and median-like behavior. • Provides a continuum of robustness depending on cc.

Disadvantages:

• Requires parameter tuning. • Computationally more intensive.

Summary of Robust Mean Techniques

MethodRobustness to OutliersData LossComplexitySubjectivity
Trimmed MeanModerateYesLowYes
Winsorized MeanModerateNoModerateYes
MedianHighNoLowNone
Weighted MeanLow to Moderate (depends on weights) | NoModerateYes
Huber MeanHighNoHighYes

Conclusion

Choosing the right technique to compute a robust mean depends on the nature of the data and the analysis goals. Each method comes with trade-offs in terms of simplicity, robustness, and data retention. By understanding these methods, analysts can select the most appropriate one, ensuring a more reliable representation of central tendency even in the presence of outliers or skewed data distributions.


Related reading
Course
Intermediate
27 lessons
15 hours
DSA Fundamentals

Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

All Rights Reserved.