Submit a community

← Blog

What the Gini index is and why you need an adjusted one

Say you are looking at these numbers

MetricValue
Posts50
Authors5
Views1,000,000
MetricValue
Views per post20,000
Views per author200,000

Can you draw conclusions from this? Probably, but they will not be objective.

Per author the numbers look like this:

AuthorPostsViewsShare
@alice10990,00099.00%
@bob102,5000.25%
@carol102,5000.25%
@dave102,5000.25%
@erin102,5000.25%
Views by author: four bars are invisible - they are the 1%.

For a saner picture we can look at percentiles

PercentileViews per author
102,500
252,500
50 (median)2,500
752,500
mean200,000

Now we know for sure that 75% of authors get 2,500 views or fewer. But what if we want to express this as a single number? That is where the Gini index helps.

The Gini index is a measure of distribution inequality. 0 means every author collects the same, 1 means one author takes everything.

G=2i=1nixini=1nxin+1nG = \frac{2 \sum_{i=1}^{n} i \, x_i}{n \sum_{i=1}^{n} x_i} - \frac{n+1}{n}
SymbolMeaning
nnnumber of authors in the community
xix_iviews (or posts) of the author in ii-th place, with all authors sorted ascending: x1x2xnx_1 \le x_2 \le \dots \le x_n
iithe author's position in that sorted list, from 1 to nn
i=1nxi\sum_{i=1}^{n} x_itotal views of the community

As an example, take this community: The Startup.

The standard formula was meant for large datasets, so when we apply it to X communities with few authors the numbers come out wrong. For example:

Let x=[0,0,0,0,100]x = [0, 0, 0, 0, 100], so n=5n = 5. In the sum ixi\sum i \, x_i only the last term is non-zero, 5100=5005 \cdot 100 = 500, and total views are 100:

G=2500510065=21.2=0.8G = \frac{2 \cdot 500}{5 \cdot 100} - \frac{6}{5} = 2 - 1.2 = 0.8

Even with a total skew toward one author, the index comes out at 0.8.

The maximum of the index over nn authors is n1n\frac{n-1}{n}, not 1.

AuthorsMaximum GiniError
20.50050.0%
30.66733.3%
50.80020.0%
100.90010.0%
200.9505.0%
500.9802.0%
1000.9901.0%
Shortfall to 1 under a total skew. The error is noticeable for fewer than 50 authors.

So for fewer than 50 authors we use the adjusted Gini index:

Gadj=Gnn1G_{adj} = G \cdot \frac{n}{n-1}

On the same example: Gadj=0.854=1.0G_{adj} = 0.8 \cdot \frac{5}{4} = 1.0.

Use x-community.top for proper community analysis.