{"id":3483,"date":"2026-03-01T20:47:45","date_gmt":"2026-03-01T19:47:45","guid":{"rendered":"https:\/\/www.gironi.it\/blog\/the-gini-index-what-it-is-why-it-matters-and-how-to-compute-it-in-r\/"},"modified":"2026-07-16T11:29:41","modified_gmt":"2026-07-16T10:29:41","slug":"the-gini-index-what-it-is-why-it-matters-and-how-to-compute-it-in-r","status":"publish","type":"post","link":"https:\/\/www.gironi.it\/blog\/en\/the-gini-index-what-it-is-why-it-matters-and-how-to-compute-it-in-r\/","title":{"rendered":"The Gini Index: How to Measure SEO Traffic Concentration (with R code)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Ever noticed how just a handful of pages on your site get the lion&rsquo;s share of traffic?<br>The homepage, the blog, the product page &mdash; and then a long tail of pages that together weigh less than those few.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It&rsquo;s the Pareto principle, we know it well. But &ldquo;80% of traffic comes from 20% of pages&rdquo; is a heuristic, not a measurement.<br>How do we know if our site is more or less concentrated than average? And what if we want to compare two sites &mdash; or the same site at two different points in time?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We need an index that quantifies concentration in a single number.<br>A number that equals <strong>0<\/strong> when everything is evenly distributed, and <strong>1<\/strong> when a single page takes it all. In between, the space of all real distributions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That number exists. It&rsquo;s called the <strong>Gini index<\/strong>, and it measures the concentration of a <strong>transferable quantitative variable<\/strong> (a quantity that can be redistributed without changing its total: income, traffic, market share). It was introduced in 1912 by the Italian statistician <strong>Corrado Gini<\/strong> specifically to study inequality in income distribution.<br>Since then, it has become one of the most widely used indicators in economics, sociology &mdash; and yes, in SEO analysis too.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let&rsquo;s see how it works.<\/p>\n\n\n<!--more-->\n\n\n<p class=\"wp-block-paragraph\">Before we get to the index itself, let&rsquo;s start with a graphical representation that Gini borrowed from the work of Max Otto Lorenz (1905): the <strong>Lorenz curve<\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Lorenz curve<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The idea is simple. We sort pages from least to most traffic. On the x-axis we place the <strong>cumulative fraction of pages<\/strong> (from 0 to 100%). On the y-axis we place the <strong>cumulative fraction of traffic<\/strong> (also from 0 to 100%). Then we connect the dots.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"975\" height=\"825\" src=\"https:\/\/www.gironi.it\/blog\/wp-content\/uploads\/2026\/07\/gini-lorenz-seo-en.png\" alt=\"Lorenz curve of SEO traffic: 30 pages, Gini = 0.614\" class=\"wp-image-4335\" srcset=\"https:\/\/www.gironi.it\/blog\/wp-content\/uploads\/2026\/07\/gini-lorenz-seo-en.png 975w, https:\/\/www.gironi.it\/blog\/wp-content\/uploads\/2026\/07\/gini-lorenz-seo-en-300x254.png 300w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">The dashed 45&deg; line is the <strong>equality line<\/strong>: if every page received exactly the same amount of traffic, the Lorenz curve would coincide with this line.<br>The blue curve is the <strong>Lorenz curve<\/strong> for real data: it deviates from the diagonal the more traffic is concentrated in few pages.<br>The blue-shaded area between the line and the curve is the <strong>concentration area<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The key point: the Lorenz curve makes <em>visible<\/em> what a single number cannot tell &mdash; the <strong>shape<\/strong> of inequality.<br>Two sites with the same Gini index can have very different curves, as we&rsquo;ll see shortly.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-style-rounded\"><img loading=\"lazy\" decoding=\"async\" width=\"249\" height=\"326\" src=\"https:\/\/www.gironi.it\/blog\/wp-content\/uploads\/2020\/11\/Corrado_Gini-1.jpg\" alt=\"Corrado Gini\" style=\"border-radius:50%;shape-outside:margin-box;margin-bottom:1.2em\" class=\"wp-image-1925\" srcset=\"https:\/\/www.gironi.it\/blog\/wp-content\/uploads\/2020\/11\/Corrado_Gini-1.jpg 249w, https:\/\/www.gironi.it\/blog\/wp-content\/uploads\/2020\/11\/Corrado_Gini-1-229x300.jpg 229w\" sizes=\"auto, (max-width: 249px) 85vw, 249px\" \/><figcaption class=\"wp-element-caption\" style=\"text-align:center;font-style:italic;font-size:0.85em;color:#666\">Corrado Gini (1884\u20131965)<\/figcaption>\n<\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">Gini published his work &ldquo;<em>Variabilit&agrave; e mutabilit&agrave;<\/em>&rdquo; (Variability and Mutability) in 1912, building on Lorenz&rsquo;s ideas. The index that bears his name comes from there: it <strong>measures the area between the Lorenz curve and the 45&deg; line, relative to the total area of the triangle underneath<\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">From curve to index<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The Gini index (often denoted by <strong>R<\/strong>, from &ldquo;concentration ratio&rdquo;) can be defined independently of the curve.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong>mean absolute difference<\/strong> is the average of the absolute differences between all possible pairs of values in the distribution: it measures how far apart the values are from each other on average.<\/p>\n\n\n\n<p style=\"text-align:center;font-style:italic;font-size:1.1em\">\n  R = <span style=\"font-size:0.9em\">mean absolute difference<\/span> \/ <span style=\"font-size:0.9em\">(2 &times; mean of values)<\/span>\n<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A value of <strong>R = 0<\/strong> means perfect equality (all pages have the same traffic).<br><strong>R = 1<\/strong> means maximum concentration (a single page holds all traffic).<br>In reality, we move between these extremes: the graph above shows R \u2248 0.61, a medium-high concentration value typical of many real websites.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For context: the Gini index for income distribution in Italy is around 0.33 (<a href=\"https:\/\/www.istat.it\/en\/archivio\/286184\" target=\"_blank\" rel=\"noopener noreferrer\">ISTAT 2023 data<\/a>).<br>A website typically has much higher values, because traffic tends to concentrate more extremely than income.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>An important limitation.<\/strong> The Gini index is a synthetic indicator: it summarises concentration in a single number, but two very different distributions can produce the same value. A site with a few extremely strong pages and many near-zero ones can have Gini = 0.6, exactly like a site with a more gradual distribution. The Lorenz curve helps see the difference &mdash; but the number alone is not enough.<\/p>\n\n\n<p class=\"wp-block-paragraph\">In the digital world, traffic often follows a <strong>power law<\/strong> (sometimes called Zipf&rsquo;s law), with a very long tail of pages receiving very few visits. Gini does not distinguish this type of distribution from one with a shorter tail: the same value can hide very different tails, which is why it should always be accompanied by the Lorenz curve.<\/p>\n\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Beware when comparing sites of different sizes.<\/strong> The Gini estimator computed on few pages (say n &lt; 50) tends to overestimate true concentration: this is a known bias, which is why a corrected version multiplies by n\/(n&minus;1). A small site will appear structurally more concentrated than a large one, even with the same underlying distribution. Comparing Gini values computed on very different numbers of pages is misleading.<\/p>\n\n\n\n<p class=\"has-light-gray-background-color has-background wp-block-paragraph\"><strong>Three common mistakes with the Gini index<\/strong><br><br>\n1. <strong>&ldquo;Gini tells us how many pages concentrate traffic&rdquo;<\/strong> &mdash; No. Gini tells us <em>how unequal<\/em> the distribution is, not <em>how many<\/em> pages are above a certain threshold. Two sites with Gini = 0.6 can have very different patterns: one with a few very strong pages and many near-zero, another with a more gradual distribution. The Lorenz curve helps distinguish the cases.<br><br>\n2. <strong>&ldquo;Gini can be used on any variable&rdquo;<\/strong> &mdash; Careful. Gini only makes sense for <strong>transferable variables<\/strong>, that is, variables where summing values and redistributing them is meaningful. Income qualifies (the sum of incomes is total income). Traffic sessions qualify (the sum of sessions is total traffic). Conversion rate does not: &ldquo;redistributing&rdquo; conversion rates makes no sense.<br><br>\n3. <strong>&ldquo;Gini is the same as standard deviation&rdquo;<\/strong> &mdash; No. Standard deviation measures <em>absolute<\/em> dispersion, Gini measures <em>relative<\/em> concentration. Two distributions with the same standard deviation can have very different Gini indices, and vice versa.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Try it yourself<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Here are the session counts (last 30 days) for 8 pages on an imaginary site:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody>\n<tr><td><strong>Page<\/strong><\/td><td><strong>Sessions<\/strong><\/td><\/tr>\n<tr><td>Homepage<\/td><td>8,200<\/td><\/tr>\n<tr><td>Blog<\/td><td>5,100<\/td><\/tr>\n<tr><td>Products<\/td><td>2,800<\/td><\/tr>\n<tr><td>About us<\/td><td>950<\/td><\/tr>\n<tr><td>Contact<\/td><td>720<\/td><\/tr>\n<tr><td>Services<\/td><td>450<\/td><\/tr>\n<tr><td>Client area<\/td><td>310<\/td><\/tr>\n<tr><td>Work with us<\/td><td>180<\/td><\/tr>\n<\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Try to answer:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>At a glance: do you think the Gini index will be closer to <strong>0.3<\/strong>, <strong>0.5<\/strong>, or <strong>0.7<\/strong>?<\/li>\n<li>Which are the top two pages by traffic? What fraction of total traffic do they account for?<\/li>\n<li>If we added a ninth page with 50 sessions, would the Gini index increase or decrease?<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Take a moment to think &mdash; then let&rsquo;s work through the solution in R.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Computing the Gini index in R<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Let&rsquo;s calculate the Gini index on the exercise data. In R we can implement the definition directly:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Delta &lt;- function(variable) {\n  n &lt;- length(variable)\n  avg &lt;- mean(variable)\n  sorted_var &lt;- sort(variable)\n  (4 * sum((1:n) * sorted_var) \/ n - 2 * avg * (n + 1)) \/ (n - 1)\n}\n\nsessions &lt;- c(8200, 5100, 2800, 950, 720, 450, 310, 180)\n\n# Note: this formula avoids computing all\n# n(n-1)\/2 pairs explicitly (efficient rewrite)\ngini &lt;- Delta(sessions) \/ (2 * mean(sessions))\ngini\n\n# Lorenz curve in one go with the ineq package\nlibrary(ineq)\ngini_ineq <- Gini(sessions)\nlc <- Lc(sessions)\nplot(lc)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The result? <strong>R \u2248 0.58<\/strong>. A high concentration value, as expected for a site with a dominant homepage.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Answers:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Was it closer to 0.7? Actually 0.58, but if you thought &ldquo;between 0.5 and 0.7&rdquo; you were on the right track.<\/li>\n<li>Homepage and Blog together make 13,300 out of 18,710 total sessions &mdash; about <strong>71%<\/strong>. Just over 70% of traffic concentrated in 25% of the pages.<\/li>\n<li>A ninth page with 50 sessions would <strong>increase<\/strong> the Gini index, because we&rsquo;re adding a tail page with very little traffic (50 becomes the new minimum). In general, though, the effect depends on where the new value falls: if it were close to the mean, the outcome would be ambiguous.<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"wp-block-paragraph\">The Gini index tells us <em>how much<\/em> traffic is concentrated, but not <em>why<\/em>.<br>Two sites with the same Gini can have completely different dynamics: one because very few pages perform extremely well, another because a great many pages perform very poorly. The diagnosis is the same (high concentration), but the cure differs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the next article, we&rsquo;ll look at breaking down concentration by traffic source (organic, direct, social, referral) &mdash; and figure out where to act first.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Further reading<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">For a brilliant exploration of statistical thinking, inequality measures, and how to read numbers without being fooled: <a href=\"https:\/\/www.amazon.it\/dp\/0241258766?tag=consulenzeinf-21\" rel=\"nofollow sponsored noopener\" target=\"_blank\"><em>The Art of Statistics<\/em><\/a> by David Spiegelhalter offers a masterful blend of rigour and clarity, with illuminating pages on the Gini index and the Lorenz curve.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ever noticed how just a handful of pages on your site get the lion&rsquo;s share of traffic?The homepage, the blog, the product page &mdash; and then a long tail of pages that together weigh less than those few. It&rsquo;s the Pareto principle, we know it well. But &ldquo;80% of traffic comes from 20% of pages&rdquo; &hellip; <a href=\"https:\/\/www.gironi.it\/blog\/en\/the-gini-index-what-it-is-why-it-matters-and-how-to-compute-it-in-r\/\" class=\"more-link\">Leggi tutto<span class=\"screen-reader-text\"> &#8220;The Gini Index: How to Measure SEO Traffic Concentration (with R code)&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","footnotes":""},"categories":[161],"tags":[],"class_list":["post-3483","post","type-post","status-publish","format-standard","hentry","category-statistics"],"lang":"en","translations":{"en":3483,"it":633},"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"post-thumbnail":false},"uagb_author_info":{"display_name":"Paolo Gironi","author_link":"https:\/\/www.gironi.it\/blog\/author\/autore-articoli\/"},"uagb_comment_info":0,"uagb_excerpt":"Ever noticed how just a handful of pages on your site get the lion&rsquo;s share of traffic?The homepage, the blog, the product page &mdash; and then a long tail of pages that together weigh less than those few. It&rsquo;s the Pareto principle, we know it well. But &ldquo;80% of traffic comes from 20% of pages&rdquo;&hellip;","_links":{"self":[{"href":"https:\/\/www.gironi.it\/blog\/wp-json\/wp\/v2\/posts\/3483","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gironi.it\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gironi.it\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gironi.it\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gironi.it\/blog\/wp-json\/wp\/v2\/comments?post=3483"}],"version-history":[{"count":5,"href":"https:\/\/www.gironi.it\/blog\/wp-json\/wp\/v2\/posts\/3483\/revisions"}],"predecessor-version":[{"id":4351,"href":"https:\/\/www.gironi.it\/blog\/wp-json\/wp\/v2\/posts\/3483\/revisions\/4351"}],"wp:attachment":[{"href":"https:\/\/www.gironi.it\/blog\/wp-json\/wp\/v2\/media?parent=3483"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gironi.it\/blog\/wp-json\/wp\/v2\/categories?post=3483"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gironi.it\/blog\/wp-json\/wp\/v2\/tags?post=3483"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}