inequality.theil.TheilD#

class inequality.theil.TheilD(y, partition, column=None)[source]#

Decomposition of Theil’s T based on partitioning of observations into exhaustive and mutually exclusive groups.

Parameters:
ynumpy.array, pandas.Series, or pandas.DataFrame

An array in the shape \((n,t)\) or \((n,)\) with \(n\) taken as the observations across which inequality is calculated. If y is \((n,)\) then a scalar inequality value is determined. If y is \((n,t)\) then an array of inequality values are determined, one value for each column in y. For a pandas.DataFrame, pass column (a name or list of names) to select the values.

partitionarray_like or pandas.Series

An array in the shape \((n,)\) of elements indicating which partition each observation belongs to. These are assumed to be exhaustive.

columnstr or list of str, optional

Name(s) of the column(s) holding the values when y is a pandas.DataFrame.

Attributes:
Tnumpy.array

An array in the shape \((t,)\) or \((1,)\) containing the global inequality T.

bgnumpy.array

An array in the shape \((n,t)\) or \((n,)\) representing between group inequality.

wgnumpy.array

An array in the shape \((n,t)\) or \((n,)\) representing within group inequality.

Examples

>>> import libpysal
>>> import numpy
>>> from inequality.theil import TheilD
>>> f = libpysal.io.open(libpysal.examples.get_path('mexico.csv'))
>>> vnames = [f'pcgdp{dec}' for dec in range(1940, 2010, 10)]
>>> y = numpy.array([f.by_col[v] for v in vnames]).T
>>> regimes = numpy.array(f.by_col('hanson98'))
>>> theil_d = TheilD(y, regimes)
>>> theil_d.bg
array([0.0345889 , 0.02816853, 0.05260921, 0.05931219, 0.03205257,
       0.02963731, 0.03635872])
>>> theil_d.wg
array([0.17435454, 0.12405598, 0.0521202 , 0.04263506, 0.06354856,
       0.07547525, 0.0702496 ])
__init__(y, partition, column=None)[source]#

Methods

__init__(y, partition[, column])