title: Implementing Sn and Qn (Rousseeuw and Croux) for outlier detection in Postgres
body: <p>I'm reviewing and experimenting with outlier flagging strategies, and keep running into references to <em>Sn</em> and <em>Qn</em> from Rousseeuw and Croux in <em>Alternatives to the Median Absolute Deviation</em>.</p>
  <p><a href="http://web.ipac.caltech.edu/staff/fmasci/home/astro_refs/BetterThanMAD.pdf" rel="nofollow noreferrer">http://web.ipac.caltech.edu/staff/fmasci/home/astro_refs/BetterThanMAD.pdf</a></p>
  <p>They sound quite excellent, and seem to be widely used in academic and applied stats across disciplines. I checked Google Scholar, and that paper has over 2,100 citations.</p>
  <p>The appealing feature of this technique is that it isn't heavily impacted by asymmetric distributions. Which is what we've got, most of the time. Sometimes quite extremely.</p>
  <p>This is of course available in R, but I'm not a stats person, we don't have server-side access to R (or Python), and would like to do some searches directly in Postgres. I haven't been able to find anything in any SQL idiom, and am hoping that some stats lover out there has some Postgres code up their sleeve.</p>