concentrationMetrics icon indicating copy to clipboard operation
concentrationMetrics copied to clipboard

Gini formula looks wrong (but works)

Open timotta opened this issue 7 years ago • 1 comments

Looking for the formula here http://www.openriskmanual.org/wiki/Gini_Index

image

It seem that this code is wrong (but it works perfectly)

(1.0 - 2.0 * np.multiply(i, weights).sum())/n + 1.0

I think the right code would be:

(2.0 * np.multiply(i/n, weights).sum()) - (n - 1.0)/n

or following the other formula

image

(n + 1.0)/n - (2.0 * np.multiply((n + 1 - i)/n, weights).sum())

Those two codes that match the formulas have a problem, they get the results as negative numbers

timotta avatar May 08 '18 02:05 timotta

Thanks for spotting this. The manual had the Gini formula with the opposite sign (both conventions are used). Modified the manual documentation so that it is consistent. The latest release includes some further tests (gini_test.py)

open-risk avatar May 09 '18 19:05 open-risk

Fixed in documentation

open-risk avatar Apr 19 '24 09:04 open-risk