Gini Coefficient

By ET

The Gini coefficient is a measure of inequality. It is usually used to measure income inequality, but can be used to measure any form of uneven distribution. It is closely related to Lorenz Curve

(figure courtesy to WikiPedia)

I usually use perl to manipulate my datasets, and I could not find a procedure to calculate gini coefficient in perl. So I wrote one. :-)

The definition of Gini coefficient is:G==(sum_(i==1)^(n)sum_(j==1)^(n)|x_i-x_j|)/(2n^2mu)

but,The Gini coefficient is often calculated with the more practical Brown Formula shown below:

G = | 1 - \sum_{k=1}^{n} (X_{k} - X_{k-1}) (Y_{k} + Y_{k-1}) |

G: Gini coefficient
Xk: cumulated proportion of the population variable, for k = 0,…,n, with X0 = 0, Xn = 1
Yk: cumulated proportion of the income variable, for k = 0,…,n, with Y0 = 0, Yn = 1

In the following program, I use yet another formula, which is even concise and straightforward:

G==(sum_(i==1)^(n)(2i-n-1)x_i^')/(n^2mu) (see Dixon et al. 1988, Damgaard and Weiner 2000)

Okey, the program itself:

#!/usr/bin/perl

my @origx=(20, 23, 18, 25, 28, 18);

my $gini=calc_gini(@origx);
print "$gini\n";
exit;

sub calc_gini{

my @origx=@_;
my @x = sort { $a <=> $b } @origx;

my $ginisum=0;
my $sum=0;
my $count=@x;

for (my $i=1;$i<=$count;$i++) {

$ginisum=$ginisum+(2*$i-$count-1)*$x[$i-1];
$sum=$sum+$x[$i-1];

}

my $gini=$ginisum/($count-1)/$sum;
return $gini;

}

References:

Damgaard, C. and Weiner, J. "Describing Inequality in Plant Size or Fecundity." Ecology 81, 1139-1142, 2000.

Dixon, P. M.; Weiner, J.; Mitchell-Olds, T.; and Woodley, R. "Erratum to ‘Bootstrapping the Gini Coefficient of Inequality.’ " Ecology 69, 1307, 1988.

 

2 Responses to “Gini Coefficient”

  1. Patterson Says:

    Very Interesting and Illuminating

  2. Stewart Derider Says:

    I like the design of this website

Leave a Reply


BlogTimer
You are visitor number several since September 1, 2001

Copyright Xiaoquan (Michael) Zhang, 2004-2020. All rights reserved.
All trademarks property of their owners.