Code covered by the BSD License  

Highlights from
GINI coefficient

Be the first to rate this file! 16 Downloads (last 30 days) File Size: 2.59 KB File ID: #26452
image thumbnail

GINI coefficient

by Oleg Komarov

 

22 Jan 2010 (Updated 15 Jun 2010)

A measure of statistical dispersion

| Watch this File

File Information
Description

A simple function to measure the statistical dispersion of a distribution. This statistic is commonly used to assess inequality in income or wealth.

The coefficients ranges from 1 (total inequality, one person receives ALL) to 0 (total equality, everyone receives the same amount).

The function ignores NaNs and can be computed with or without sample correction.
SYNTAXES:
(1) GINICOEFF(IN) One input syntax, columwise gini coeffs.
(2) GINICOEFF(...,DIM) Dim along which to compute the coeff (1 or 2)
(3) GINICOEFF(...,NOSAMPLECORR) Don't apply sample correction

[COEFF, IDXNEG] = ...
-- coeff : n by 1 vector with gini coefficients where n is the number of series in In.
-- IDX : n by 1 logical index. True means that the computation of the gini coefficient for that series has been skipped due to negative values or insufficient elements (less than 2).

NOTE: this statistical measure is meant to be applied only on positive values. If a series contains negative values or the elements of the less than 2, the coefficient yields NaN and a warning is issued if IDX is not called explicitly.

For details see help
For examples see the attached image.

Comments/suggestions/error reports are welcome.

p8v2.2

MATLAB release MATLAB 7.9 (2009b)
Other requirements Tested on R14SP3 (7.1) and on R2009b. In-between compatibility is assumed.
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (2)
04 Feb 2010 Jos (10584)

Nicely coded, with copious internal comments! As a suggestion for improvement, you could mention in the help that the coefficient can range from 0 (no dispersion, complete equality) to 1 (total inequality), as you do on the fex page. By the way, ginicoeff(ScalarValue) is now 0, but I think it should be 1, as it is total inequality since one gets all, but it is also equal ... I got confused.
And why is the correction not the default, so it truly ranges from 0 to 1?

04 Feb 2010 Oleg Komarov

Thanks Jos for the comments,
I will mention in the next release help the range of the coefficient.
Also, I'll switch the default behaviour to sample correction (statistically speaking the probability that somebody will apply this fcn to a sample than to the population is higher...)

The scalar input issue is tricky.
The formula with the sample correction yields NaN, without correction 0
I suppose it's better to write off this case somehow...
I think I'll extend the IDXneg behavior to include the one element case too, making a more general warning....

Please login to add a comment or rating.
Updates
04 Feb 2010

Edited description

05 Feb 2010

Per Jos (10584) suggestion: sample correction is now the default; if elements in a series < 2 --> NaN. Edited help. Added link to FEX page.

15 Jun 2010

NaNs were not ignored due to a misplacing in the lines of code

Tag Activity for this File
Tag Applied By Date/Time
gini Oleg Komarov 22 Jan 2010 10:56:24
coeff Oleg Komarov 22 Jan 2010 10:56:24
statistic Oleg Komarov 22 Jan 2010 10:56:24
dispersion Oleg Komarov 22 Jan 2010 10:56:24
measure Oleg Komarov 22 Jan 2010 10:56:24
distribution Oleg Komarov 22 Jan 2010 10:56:24
concentration Oleg Komarov 22 Jan 2010 10:56:24

Contact us at files@mathworks.com