<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/relative-error-distributions-without-the-heavy-tail-theatrics/"></div></div><div><a data-url="https://www.r-bloggers.com/relative-error-distributions-without-the-heavy-tail-theatrics/" data-counturl="https://www.r-bloggers.com/relative-error-distributions-without-the-heavy-tail-theatrics/" data-count="horizontal" data-text="Relative error distributions, without the heavy tail theatrics" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.win-vector.com/blog/2016/09/relative-error-distributions-without-the-heavy-tail-theatrics/"> R – Win-Vector Blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><a target="_blank" href="http://www.win-vector.com/site/staff/nina-zumel/">Nina Zumel</a> prepared an excellent article on the consequences of working with relative error distributed quantities (such as wealth, income, sales, and many more) called “<a target="_blank" href="http://www.win-vector.com/blog/2010/02/living-in-a-lognormal-world/">Living in A Lognormal World</a>.” The article emphasizes that if you are dealing with such quantities you are already seeing effects of relative error distributions (so it isn’t an exotic idea you bring to analysis, it is a likely fact about the world that comes at you). The article is a good example of how to plot and reason about such situations.</p>
<p>I am just going to add a few additional references (mostly from Nina) and some more discussion on log-normal distributions versus <a target="_blank" href="https://en.wikipedia.org/wiki/Zeta_distribution">Zipf-style distributions</a> or <a target="_blank" href="https://en.wikipedia.org/wiki/Pareto_distribution">Pareto distributions</a>.<span></span></p>
<p>
<h2>The theory</h2>
<p>In analytics, data science, and statistics we often assume we are dealing with nice or tightly concentrated distributions such as the <a target="_blank" href="https://en.wikipedia.org/wiki/Normal_distribution">normal or Gaussian distribution</a>. Analysis tends to be very easy in these situation and not require much data. However, for many quantities of interest (wealth, company sizes, sales, and many more) it becomes obvious that we cannot be dealing with such a distribution. The telltale sign is usually when relative error is more plausible than absolute error. For example it is much more plausible we know our net worth to within plus or minus 10% than to within plus or minus $10.</p>
<p>In such cases you have to deal with the consequences of slightly more wild distributions such as at least the log-normal distribution. In fact this is the important point and I suggest you read <a target="_blank" href="http://www.win-vector.com/blog/2010/02/living-in-a-lognormal-world/">Nina’s article</a> for motivation, explanation, and methods. We have found this article useful both in working with data scientists and in working with executives and other business decision makers. The article formalizes ideas all of these people already “get” or anticipate into concrete examples.</p>
<p>In addition to trying to use mathematics to make things more clear, there is a mystic sub-population of mathematicians that try to use mathematics to make things more esoteric. They are literally disappointed when things make sense. For this population it isn’t enough to see if switching from a normal to log-normal distribution will fix the issues in their analysis. They want to move on to even more exotic distributions such as Pareto (which has even more consequences) with or without any evidence of such a need.</p>
<p>The issue is: in a log-normal distribution we see rare large events much more often than in a standard normal distribution. Modeling this can be crucial as it tells us not to be lulled into to strong a sense of security by small samples. This concern <em>can</em> be axiomatized into “<a target="_blank" href="https://en.wikipedia.org/wiki/Heavy-tailed_distribution">heavy tailed</a>” or “<a target="_blank" href="https://en.wikipedia.org/wiki/Fat-tailed_distribution">fat tailed</a>” distributions, but be aware: these distributions tend to be more extreme than what is implied by a relative error model. The usual heavy tail examples are <a target="_blank" href="https://en.wikipedia.org/wiki/Zeta_distribution">Zipf-style distributions</a> or <a target="_blank" href="https://en.wikipedia.org/wiki/Pareto_distribution">Pareto distributions</a> (people tend to ignore the truly nasty example the <a target="_blank" href="https://en.wikipedia.org/wiki/Cauchy_distribution">Cauchy distribution</a>, possibly because it dates back the 17th century and thus doesn’t seem hip).</p>
<p>The hope seems to be that one is saving the day by brining in new esoteric or exotic knowledge such as fractal dimension or Zipf’s law. The actual fact is this sort of power-law structure has been know for a very long time under many names. Here are some more references:</p>
<ul>
<li><a target="_blank" href="http://www-personal.umich.edu/~mejn/courses/2006/cmplxsys899/">“Power laws, Pareto distributions and Zipf’s law”, Mark Newman, Complex Systems 899, Winter 2006: Theory of Complex Systems.</a></li>
<li><a target="_blank" href="https://www.wired.com/2004/10/tail/">“The Long Tail”, Chris Anderson, Wired 10.01.04.</a></li>
<li><a target="_blank" href="http://projecteuclid.org/download/pdf_1/euclid.im/1089229510">“A Brief History of Generative Models for Power Law and Lognormal Distributions”, Michael Mitzenmacher, Internet Mathematics Vol. 1, No. 2: 226-251.</a></li>
<li><a target="_blank" href="https://colala.bcs.rochester.edu/papers/piantadosi2014zipfs.pdf">“Zipf’s word frequency law in natural language: a critical review and future directions”, Steven T. Piantadosi, June 2, 2015.</a></li>
<li><a target="_blank" href="http://www.csl.sri.com/users/neumann/belevitch.pdf">“On the statistical laws of linguistic distribution”, Vitold Belevitch, Annales de la Société Scientifique de Bruxelles, vol.3, iss.73, pp. 310–326.</a></li>
<li><a target="_blank" href="http://www.win-vector.com/blog/2010/02/living-in-a-lognormal-world/">“Living in a Lognormal World,” Nina Zumel, Win-Vector blog, February 3, 2010.</a></li>
</ul>
<p>Reading these we see that the relevant statistical issues have been well known since at least the 1920’s (so were not a new discovery by the later loud and famous popularizers). The usual claim of old wine in new bottles is that there is some small detail (and mathematics is a detailed field) that is now set differently. To this I put forward a quote from Banach (from <em>Adventures of a Mathematician</em> S.M. Ulam, University of California Press, 1991, page 203):</p>
<blockquote><p>Good mathematicians see analogies between theorems or theories, the very best ones see analogies between analogies.</p>
</blockquote>
<p>Drowning in removable differences and distinctions is the world of the tyro, not the master.</p>
<p>From Piantadosi we have:</p>
<blockquote><p>The apparent simplicity of the distribution is an artifact of how the distribution is plotted. The standard method for visualizing the word frequency distribution is to count how often each word occurs in a corpus, and sort the word frequency counts by decreasing magnitude. The frequency f(r) of the r’th most frequent word is then plotted against the frequency rank r, yielding typically a mostly linear curve on a log-log plot (Zipf, 1936), corresponding to roughly a power law distribution. This approach— though essentially universal since Zipf—commits a serious error of data visualization. In estimating the frequency-rank relationship this way, the frequency f(r) and frequency rank r of a word are estimated on the same corpus, leading to correlated errors between the x-location r and y-location f(r) of points in the plot.</p>
</blockquote>
<h2>An Example</h2>
<p>Let us work through this one detailed criticism using <a target="_blank" href="https://cran.r-project.org/">R</a> (all synthetic data/graphs found <a target="_blank" href="http://winvector.github.io/Zipf/FalseZipf.html">here</a>). We start with the problem and a couple of observations.</p>
<p>Suppose we are running a business and organize our sales data as follows. We compute what fraction of our sales each item is (be it a count, or be it in dollars) and then rank them (item 1 is top selling, item 2 is next, and so on). </p>
<p>The insight of the Pareto-ists and Zipfians is if we plot sales intensity (probability or frequency) as a function of sales rank we are in fact very likely to get a graph that looks like the following:</p>
<p><img title="NewImage.png" alt="NewImage" src="http://i0.wp.com/www.win-vector.com/blog/wp-content/uploads/2016/09/NewImage.png?resize=599%2C428" border="0" data-recalc-dims="1"></p>
<p>Instead of all items selling at the same rate we see the top selling item can often make up a signficant fraction of the sales (such as 20%). There are a lot of <a target="_blank" href="https://en.wikipedia.org/wiki/Pareto_principle">80/20 rule</a>s based on this empirical observation.</p>
<p>Notice also the graph is fairly illegible, the curve hugs the axes and most of the visual space is wasted. The next suggestion is to plot on “log-log paper” or plot the logarithm of frequency as a function of logarithm of rank. That gives us a graph that looks like the following:</p>
<p><img title="NewImage.png" alt="NewImage" src="http://i1.wp.com/www.win-vector.com/blog/wp-content/uploads/2016/09/NewImage-1.png?resize=599%2C428" border="0" data-recalc-dims="1"></p>
<p>If the original data is Zipfian distributed (as it is in the artificial example) the graph becomes a very legible straight line. The slope of the line is the important feature of the distribution and is (in a very loose sense) the “fractal dimension” of this data. The mystics think that by identifying the slope you have identified some key esoteric fact about the data and can then somehow “make hay” with this knowledge (though they never go on to explain how).</p>
<p>Chris Anderson in his writings on the “long tail” (including his <a target="_blank" href="https://en.wikipedia.org/wiki/The_Long_Tail_(book)">book</a>) clearly described a very practical use of such graphs. Suppose instead of assuming the line on log-log plots is a consequence of something special, suppose it is a consequence of something mundane. Maybe graphs tend to look like this for catalogs, sales, wealth, company sizes, and so on. So instead of saying the perfect fit is telling us something, look at defects in fit. Perhaps they indicate something. For example: suppose something we are selling products online and something is wrong with a great part of our online catalogue. Perhaps many of the products don’t have pictures, don’t have good descriptions, or some other common defect. We might expect our rank/frequency graph to look more like the following:</p>
<p><img title="NewImage.png" alt="NewImage" src="http://i0.wp.com/www.win-vector.com/blog/wp-content/uploads/2016/09/NewImage-2.png?resize=599%2C428" border="0" data-recalc-dims="1"></p>
<p>What happened is after product 20 something went wrong. In this case (because the problem happened early at an important low rank) can see it, but it is even more legible on the log-log plot.</p>
<p><img title="NewImage.png" alt="NewImage" src="https://i2.wp.com/www.win-vector.com/blog/wp-content/uploads/2016/09/NewImage-3.png?resize=599%2C428" border="0" data-recalc-dims="1"></p>
<p>The business advice is: look for that jump, sample items above and below the jump, and look for a difference. As we said the difference could be no images on such items, no free shipping, or some other sensible business impediment. The reason we care is this large population of low-volume items could represent a non-negligible fraction of sales. Below is the theoretical graph if we fixed whatever is wrong with the rarer items and plotted sales:</p>
<p><img title="NewImage.png" alt="NewImage" src="http://i0.wp.com/www.win-vector.com/blog/wp-content/uploads/2016/09/NewImage-4.png?resize=599%2C428" border="0" data-recalc-dims="1"></p>
<p>From this graph we can calculate that the missing sales represent a loss of about 32% of revenue. If we could service these sales cheaply we would want them.</p>
<h2>The flaw in analysis</h2>
<p>In the above I used a theoretical Zipfian world to generate my example. But suppose the world isn’t Zipfian (there are many situations where log-normal is a much more plausible situation). Just because the analyst wishes things were exotic (requiring their unique heroic contribution) doesn’t mean they are in fact exotic. Log-log paper is legible because it reprocesses the data fairly violently. As Piantadosi said: we may see patterns in such plots that are features of the analysis technique, and not features of the world.</p>
<p>Suppose the underlying sales dates is log-normal distributed instead of Zipfian distributed (a plausible assumption until eliminated). If we had full knowledge of every possible sale for all time we could make a log-log plot over all time and get the following graph.</p>
<p><img title="NewImage.png" alt="NewImage" src="https://i2.wp.com/www.win-vector.com/blog/wp-content/uploads/2016/09/NewImage-5.png?resize=599%2C428" border="0" data-recalc-dims="1"></p>
<p>What we want to point out is: this is not a line. The hook down at the right side means that rare items have far fewer sales than a Zipfian model would imply. It isn’t just a bit of noise to be ignored. This means when one assumes a Zipfian model one is assuming the rare items as a group are in fact very important. This may be true or may be false, which is why you want to measure such a property and not assume it one way or the other.</p>
<p>The above graph doesn’t look so bad. The honest empiricist may catch the defect and say it doesn’t look like a line (though obviously a quantitive test of distributions would also be called for). But this graph was plotting all sales over all time. We would never see that. Statistically we usually model observed sales as a sample drawn from this larger ideal sampling population. Let’s take a look at what that graph may look like. An example is given below.</p>
<p><img title="NewImage.png" alt="NewImage" src="https://i2.wp.com/www.win-vector.com/blog/wp-content/uploads/2016/09/NewImage-6.png?resize=599%2C428" border="0" data-recalc-dims="1"></p>
<p>I’ll confess, I’d have a hard time arguing this wasn’t a line. It may or may not be a line, but it is certainly not strong evidence of a non-line. This data did not come from a Zipfian distribution (I know I drew it from a log-normal distribution), yet I would have a hard time convincing a Zipfian that it wasn’t from a Zipfian source.</p>
<p>And this brings us back to Piantadosi’s point. We used the same sample to estimate both sales frequencies and sales ranks. Neither of those are actually known to us (we can only estimate them from samples). And when we use the same sample to estimate both, they necessarily come out very related due to the sampling procedure. Some of the biases seem harmless such as frequency monotone decreasing in rank (which is true for unknown true values). But remember: relations that are true in the full population are not always true in the sample. Suppose we had a peek at the answers and instead of estimating the ranks took them from the theoretical source. In this case we could plot true rank versus estimated frequency:</p>
<p><img title="NewImage.png" alt="NewImage" src="http://i0.wp.com/www.win-vector.com/blog/wp-content/uploads/2016/09/NewImage-7.png?resize=599%2C428" border="0" data-recalc-dims="1"></p>
<p>This graph is much less orderly because we have eliminated some of the plotting bias which was introducing its own order. There are still analysis artifacts visible, but that is better than hidden artifacts. For example the horizontal strips are items that occurred with the same frequency in our sample, but had different theoretical ranks. In fact our sample is size 1000, so the rarest frequency we can measures is 1/1000 which creates the lowest horizontal stripe. The neatness of the previous graph were dots standing on top of each other as we estimated frequency as function of rank.</p>
<p>We are not advocating specific changes, we are just saying the log-log plot is a fairly refined view, and as such many of its features are details of processing- not all correctly inferred or estimated features of the world. Again, for a more useful applied view we suggest <a target="_blank" href="http://www.win-vector.com/blog/2010/02/living-in-a-lognormal-world/">Nina Zumel’s living in a log-normal world</a>.</p>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="https://www.r-bloggers.com/relative-error-distributions-without-the-heavy-tail-theatrics/"></div></div><div><a data-url="https://www.r-bloggers.com/relative-error-distributions-without-the-heavy-tail-theatrics/" data-counturl="https://www.r-bloggers.com/relative-error-distributions-without-the-heavy-tail-theatrics/" data-count="vertical" data-text="Relative error distributions, without the heavy tail theatrics" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://www.win-vector.com/blog/2016/09/relative-error-distributions-without-the-heavy-tail-theatrics/"> R – Win-Vector Blog</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 title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/Nw4M_DKfZE4"></a></div>