Skip to content

Commit

Permalink
Merge pull request #93 from sjsrey/b16
Browse files Browse the repository at this point in the history
Fix inconsistency in efficient gini
  • Loading branch information
sjsrey authored Jan 16, 2025
2 parents 9655a59 + 5c6ea81 commit 0660ce1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
2 changes: 2 additions & 0 deletions inequality/gini.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ def _gini(x):
http://www.statsdirect.com/help/default.htm#nonparametric_methods/gini.htm.
"""

n = len(x)
try:
x_sum = x.sum()
except AttributeError:
x = numpy.asarray(x)
x_sum = x.sum()
n_x_sum = n * x_sum
x = x.ravel() # ensure shape is (n,)
r_x = (2.0 * numpy.arange(1, len(x) + 1) * x[numpy.argsort(x)]).sum()
return (r_x - n_x_sum - x_sum) / n_x_sum

Expand Down
1 change: 1 addition & 0 deletions inequality/tests/test_theil.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def test___init__(self):
]
),
)

y = numpy.array([0, 0, 0, 10, 10, 10])
regions = numpy.array([0, 0, 0, 1, 1, 1])
theil_d = TheilD(y, regions)
Expand Down

0 comments on commit 0660ce1

Please sign in to comment.