Method to remove outliers from a set of values I'm removing outliers from a set of data using the method described here.

The method removes the outliers and returns the quartile values of the set after all outliers have been removed.

(Quartiles is a class I wrote with properties for Q1, Q2, Q3, and the Inter-quartile range, IQR. The .Quartiles() returns these values for a sequence of decimals.)

public Quartiles RemoveOutliers(ICollection&lt;MyObject&gt; objects)
{
    if (objects.Count == 0)
    {
        return new Quartiles();
    }

    // Calculate Mean value of the set.
    decimal meanValue = objects.Average(o =&gt; o.MyProperty);

    // Find the Object whose value is farthest from the Mean.
    MyObject objectFarthestFromMean = objects.OrderByDescending(o =&gt; Math.Abs(o.MyProperty - meanValue)).First();
    Quartiles quartiles = objects.Quartiles(o =&gt; o.MyProperty);

    // Remove Object if its value is more than 1.5*IQR from the Mean.
    decimal minValue = meanValue - (1.5m * quartiles.IQR);
    decimal maxValue = meanValue + (1.5m * quartiles.IQR);

    if ((objectFarthestFromMean.MyProperty &lt; minValue) || (objectFarthestFromMean.MyProperty &gt; maxValue))
    {
        objects.Remove(objectFarthestFromMean);

        return RemoveOutliers(objects);
    }

    // No outlier found, we're finished.
    return quartiles;
}


Looking for any ways to improve or fix any pitfalls I haven't encountered in testing.
You used Math.Abs(o.MyProperty - meanValue) to check both upper and lower cases.

But then you do specify minValue and maxValue separately. You could apply the same logic here:

decimal maxRange = (1.5m * quartiles.IQR);

if (Math.Abs(objectFarthestFromMean.MyProperty - meanValue) &gt; maxRange)
{


Other than that, the calculation logic seems about as efficient as it can be (keeping readability in mind).