<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/compare-outlier-detection-methods-with-the-outlierso3-package/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://blog.revolutionanalytics.com/2018/03/outliers.html"> Revolutions</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<div>
<p><em>by Antony Unwin, </em><em>University of Augsburg, Germany</em></p>
<p>There are many different methods for identifying outliers and a lot of them are available in <strong>R</strong>. But are outliers a matter of opinion? Do all methods give the same results?</p>
<p>Articles on outlier methods use a mixture of theory and practice. Theory is all very well, but outliers are outliers because they don’t follow theory. Practice involves testing methods on data, sometimes with data simulated based on theory, better with `real’ datasets. A method can be considered successful if it finds the outliers we all agree on, but do we all agree on which cases are outliers?</p>
<p>The Overview Of Outliers (O3) plot is designed to help compare and understand the results of outlier methods. It is implemented in the <a rel="nofollow" href="https://cran.r-project.org/package=OutliersO3" target="_blank"><strong>OutliersO3</strong> package</a> and was <a rel="nofollow" href="https://channel9.msdn.com/Events/useR-international-R-User-conferences/useR-International-R-User-2017-Conference/When-is-an-Outlier-an-Outlier-The-O3-plot" target="_blank">presented at last year’s useR! in Brussels</a>. Six methods from other <strong>R</strong> packages are included (and, as usual, thanks are due to the authors for making their functions available in packages).</p>
<div><a rel="nofollow" href="http://a1.typepad.com/6a0105360ba1c6970c01b7c955e619970b-pi" target="_blank"><img border="0" alt="Unwin-fig1" title="Unwin-fig1" src="http://a1.typepad.com/6a0105360ba1c6970c01b7c955e619970b-800wi"></a>
<div>An O3 plot of the stackloss dataset. There is one row for each variable combination (defined by the columns to the left) for which outliers were found, and one column for each case identified as an outlier (the columns to the right).</div>
</div>
<p>The starting point was a recent proposal of Wilkinson’s, his <a rel="nofollow" href="https://www.ncbi.nlm.nih.gov/pubmed/28866555" target="_blank">HDoutliers algorithm</a>. The plot above shows the default O3 plot for this method applied to the stackloss dataset. (Detailed explanations of O3 plots are in the <a rel="nofollow" href="https://mran.microsoft.com/package/OutliersO3" target="_blank"><strong>OutliersO3</strong> vignettes</a>.) The <a rel="nofollow" href="https://www.rdocumentation.org/packages/datasets/versions/3.4.3/topics/stackloss?tap_a=5644-dce66f&tap_s=10907-287229" target="_blank">stackloss dataset</a> is a small example (21 cases and 4 variables) and there is an illuminating and entertaining article (<a rel="nofollow" href="https://link.springer.com/chapter/10.1007/978-1-4612-2380-1_7" target="_blank"><span>Dodge, 1996</span></a>) that tells you a lot about it.</p>
<p>Wilkinson’s algorithm finds 6 outliers for the whole dataset (the bottom row of the plot). Overall, for various combinations of variables, 14 of the cases are found to be potential outliers (out of 21!). There are no rows for 11 of the possible 15 combinations of variables because no outliers are found with them. If using a tolerance level of 0.05 seems a little bit lax, using 0.01 finds no outliers at all for any variable combination.</p>
<div><a rel="nofollow" href="http://a2.typepad.com/6a0105360ba1c6970c01bb09f92e92970d-pi" target="_blank"><img border="0" alt="Unwin-fig2" title="Unwin-fig2" src="http://a2.typepad.com/6a0105360ba1c6970c01bb09f92e92970d-800wi"></a>
<div>An O3plot comparing outliers identified by HDoutliers and mvBACON in the stackloss dataset.</div>
</div>
<p>Trying another method with tolerance level=0.05 (<em>mvBACON</em> from <strong>robustX</strong>) identifies 5 outliers, all ones found for more than one variable combination by <em>HDoutliers</em>. However, no outliers are found for the whole dataset and only one of the three variable combinations where outliers are found is a combination where <em>HDoutliers</em> finds outliers. Of course, the two methods are quite different and it would be strange if they agreed completely. Is it strange that they do not agree more?</p>
<p>There are four other methods available in <strong>OutliersO3</strong> and using all six methods on stackloss a tolerance level of 0.05 identifies the following numbers of outliers:</p>
<pre><code>##    HDo    PCS    BAC adjOut    DDC    MCD 
##     14      4      5      0      6      5</code></pre>
<div><a rel="nofollow" href="http://a0.typepad.com/6a0105360ba1c6970c01b7c955e6a8970b-pi" target="_blank"><img border="0" alt="Unwin-fig3" title="Unwin-fig3" src="http://a0.typepad.com/6a0105360ba1c6970c01b7c955e6a8970b-800wi"></a>
<div>An O3 plot of stackloss using the methods <code><em>HDoutliers</em></code>, <code>FastPCS</code>, <code>mvBACON</code>, <code>adjOutlyingness</code>, <code>DectectDeviatingCells</code>, <code>covMCD</code>. The darker the cell, the more methods agree. If they all agree, the cell is coloured red and if all but one agree then orange. No case is identified by all the methods as an outlier for any combination of variables when the tolerance level is set at 0.05 for all.</div>
</div>
<p>Each method uses what I have called the tolerance level in a rather different way. Sometimes it is called alpha and sometimes (1-alpha). As so often with <strong>R</strong>, you start wondering if more consistency would not be out of place, even at the expense of a little individuality. <strong>OutliersO3</strong> transforms where necessary to ensure that lower tolerance level values mean fewer outliers for all methods, but no attempt has been made to calibrate them equivalently. This is probably why <code>adjOutlyingness</code> finds few or no outliers (results of this method are mildly random). The default value, according to <code>adjOutlyingness</code>’s help page, is an alpha of 0.25.</p>
<p>The stackloss dataset is an odd dataset and small enough that each individual case can be studied in detail (cf. Dodge’s paper for just how much detail). However, similar results have been found with other datasets (milk, Election2005, diamonds, …). The main conclusion so far is that different outlier methods identify different numbers of different cases for different combinations of variables as different from the bulk of the data (i.e. as potential outliers)—or are these datasets just outlying examples?</p>
<p>There are other outlier methods available in <strong>R</strong> and they will doubtless give yet more different results. The recommendation has to be to proceed with care. Outliers may be interesting in their own right, they may be errors of some kind—and we may not agree whether they are outliers at all.</p>
<p>[Find the R code for generating the above plots here: <a rel="nofollow" href="https://gist.github.com/revodavid/162943fcc49af20f0a978f9dfa5aa162" target="_blank">OutliersUnwin.Rmd</a>]</p>
</div>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://blog.revolutionanalytics.com/2018/03/outliers.html"> Revolutions</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/vHxYndU50SA" height="1"></a></div>