# Median/Quartile Function for Price Sources

A staple of statistical analysis is the detection of outliers. Huge deviations from the true value of an item are what make up one of the greatest problems that any market analysis site faces. All of the skinning knives that trolls put on the AH for thousands of gold make the market value skyrocket when those prices should be ignored.

The addition of a median function would be a step in the right direction to deal with these outliers. Having upper and lower quartile functions would finish the job. In statistics, an outlier is defined as being 1.5 times the interquartile range outside of that range.

Median is simple. It returns the middle-valued element, or the average between the two middle-valued elements. Med(market, historical, avgsell, minbuyout, vendorsell) might evaluate to Med(1, 3, 2, 5, 4), in which case it would return 3 because 3 is the median of that set. Med(1, 2) would return 1.5 because that is the average of 1 and 2.

The quartile functions are the medians of the upper or lower half of the set. Let's say I have the function UQ(1, 3, 2, 5, 4). Sorted, the set is {1, 2, 3, 4, 5}. The numbers greater than or equal to the median are {3, 4, 5}. The median of {3, 4, 5} is 4, so it would return 4.

Besides being good complements to min and max, this functionality would allow me to look at a bunch of sources and disregard any that are outside the set. The custom price would still be a massive string, but at least the functionality would exist.

(In the following example, sources is a placeholder for a list of sources I would like to average along with vendorSell: "TUJMarket, DBMarket, DBRegionMarketAvg, TUJGlobalMean, TUJRecent, DBMinBuyout, vendorSell")

My goal: check(TUJMarket - 2.5*UQ(sources) + 1.5*LQ(sources), 0, TUJMarket)

That should return TUJMarket if it is within the range, or return 0 if it is an outlier of my set of sources. Do that for each source, then get the average of what's left, and you have a more reasonable price source that won't get so affected by the one guy who just posted a 100 gold item for 100k.

**7**votes