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.
(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.
Fwiw, `flipdim` is deprecated.
it is really helpful, thanks a lot
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....
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?
Moved to github
NaNs were not ignored due to a misplacing in the lines of code
Per Jos (10584) suggestion: sample correction is now the default; if elements in a series < 2 --> NaN. Edited help. Added link to FEX page.
Create scripts with code, output, and formatted text in a single executable document.