version 1.3.0.0 (7.76 KB) by
Liber Eleutherios

Inequality Metrics: Gini Coefficient associated to the Lorenz Curve, Theil and Atkinson indexes

Package on Inequality Metrics: the Gini Coefficient associated to the Lorenz Curve, the Theil and the Atkinson indexes.

For more references:

http://en.wikipedia.org/wiki/Lorenz_curve

http://en.wikipedia.org/wiki/Gini_coefficient

http://en.wikipedia.org/wiki/Theil_index

http://en.wikipedia.org/wiki/Atkinson_index

***************************

Note that contributions #15376 and #28080 DO NOT return the correct Gini coefficient, while #26452 does not apply to populations but only to individuals.

***************************

The zip file contains:

ginicoeff.m

lorenzcurve.m

theilt.m

theill.m

atkinsonineq.m

***************************

% Example for ginicoeff.m:

N = 1000;

p = rand(N, 1); w = rand(N, 1);

y = ginicoeff(p, w)

% ***************************

% Example for lorenzcurve.m:

N = 1000;

p = rand(N, 1);

w = exp(randn(N, 1));

h = lorenzcurve(p, w);

% ***************************

% Example for theilt.m:

N = 1000;

w = rand(N, 1);

y = theilt(w)

% ***************************

% Example for theill.m:

N = 1000;

w = rand(N, 1);

y = theill(w)

% ***************************

% Example for atkinsonineq.m:

N = 1000;

w = rand(N, 1);

epsilon = rand;

y = atkinsonineq(w, epsilon)

Liber Eleutherios (2021). Inequality Package (https://www.mathworks.com/matlabcentral/fileexchange/19968-inequality-package), MATLAB Central File Exchange. Retrieved .

Created with
R14

Compatible with any release

**Inspired by:**
Gini coefficient - population weighted

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!Create scripts with code, output, and formatted text in a single executable document.

jingwen wuBGot it thanks for the clarification, I didn't realize yours used the total size of the population.

Liber EleutheriosHi B, thank you for your question about a point that is often misunderstood. Let us try to clarify this point once and for all.

In my function, FEX 19968, ginicoeff requires two variables: p and w, respectively the size of the population and the TOTAL value associated with that population (for example population and TOTAL GDP).

In the function FEX 28080, gini requires two variables: pop and val, respectively the size of the population and the AVERAGE value associated with that population (for example population and PER-CAPITA GDP).

Let

p = (1:100)'; % Population

w = (1:100)'; % Total GDP

g1 = ginicoeff(p, w)

FEX 19968 will return zero because 1 individual has a total value of 1, two individuals have a total value of 2, etc., and 100 individuals have a total value of 100. On average everyone has a value of 1, therefore this is the case of maximum dispersion, i.e. minimum inequality.

FEX 28080 will also return zero, IF you divide w by p:

g2 = gini(p, w ./ p)

I hope this helps.

BI downloaded this package for the lorenze curve plotting. However I was calculating the gini using this function and comparing it to an old calculation I had and to another package on FileExchange (http://www.mathworks.com/matlabcentral/fileexchange/28080-gini-coefficient-and-the-lorentz-curve) it seemed to differ. Has anyone else noticed the gini disagreeing with their own calculations? Maybe this gini requires a different format or something, but I didn't seem to notice a difference. The gini from the package was coming out higher than expected. Cheers

Liber Eleutherios@Martin, thank you for your comment but check it again: the Gini coefficient of your example IS NOT zero but some random number.

@Robert, thank you for your comment - I would use random data or the GDP and Population of a selection of countries.

Robert RootExcited to find this package. I'd like to use it in my courses. Where can I find actual data in the format this package accepts?

martinI want ask a question, why I set p=rand(100,1); w=p, and the GiniCoeff(p,w) is not o. Theoratically, the answer should be zero!

martinvery good, Thank you!