title: Algorithm for Removing Outliers from a dataset of prices
body: <p>This is kind of a neat problem and I've enjoyed thinking it through...</p>
  <p>Assume that you run a &quot;Widget Rental&quot; website, and on your application and you want to allow prospective purchasers to sort the widgets based on prices. (Low to high or high to low).</p>
  <p>Each widget can have a different price based on the time of year. Some widgets will have dozens of different prices depending on the season as you get &quot;high&quot; seasons and &quot;low&quot; seasons.</p>
  <p>However, the sellers of the &quot;Widgets&quot; are <strong>especially mischievous</strong>, and have realised that if they set their widget to be really expensive for one day of the year, and also really cheap one day of the year, then they can easily appear at the low and high sort ranges.</p>
  <p>Currently, I took a very naive solution in order to calculate the &quot;lowest price&quot; for a Widget, which is to just take the <code>lowest( N )</code> value from a dataset.</p>
  <p>What I would like to is to get a &quot;lowest from price&quot; for a widget, which accurately portrays the price which it could be rented from.. and remove the lower/higher-band outliers.</p>
  <p>Take a look at this chart... with values...</p>
  <p><img src="https://i.stack.imgur.com/XSK90.png" alt="Chart" /></p>
  <blockquote>
  <p>X Axis - Time (each significant interval is a day)</p>
  <p>Y Axis - Price</p>
  </blockquote>
  <p>The X axis is time, and the Y axis is the price. Now, this contains a normal distribution, and there aren't any real statistical outliers in that dataset. It's common to see the price between the lowest value and the upper value to fluctuate as much as 200%.</p>
  <p>However, take a look at this second chart... It contains a single day tariff, which is only 20 ēuros...</p>
  <p><img src="https://i.stack.imgur.com/creNt.png" alt="enter image description here" /></p>
  <p>I've played around with using Grubbs test and it seems to work quite well.</p>
  <p>The important thing is that I want to get a &quot;from price&quot;. That is to say, I want to be able to say, &quot;You can rent this widget from XXXX&quot;. So it should be reflect the overall pricing taken as a whole and ignore clear outliers.</p>
  <p>PHP bonus points if you point me in the direction of anything that already exists. (But I'm happy to code this myself in PHP).</p>