inequality.theil.Theil#
- class inequality.theil.Theil(y, column=None)[source]#
Classic Theil measure of inequality.
\[T = \sum_{i=1}^n \left( \frac{y_i}{\sum_{i=1}^n y_i} \ln \left[ N \frac{y_i}{\sum_{i=1}^n y_i}\right] \right )\]- Parameters:
- y
numpy.array,pandas.Series,orpandas.DataFrame An array in the shape \((n,t)\) or \((n,)\) with \(n\) taken as the observations across which inequality is calculated. If
yis \((n,)\) then a scalar inequality value is determined. Ifyis \((n,t)\) then an array of inequality values are determined, one value for each column iny. For apandas.DataFrame, passcolumn(a name or list of names) to select the values.- column
strorlistofstr,optional Name(s) of the column(s) holding the values when
yis apandas.DataFrame.
- y
- Attributes:
- T
numpy.array An array in the shape \((t,)\) or \((1,)\) containing Theil’s T for each column of
y.
- T
Notes
This computation involves natural logs. To prevent
ln[0]from occurring, a small value is added to each element ofybefore beginning the computation.Examples
>>> import libpysal >>> import numpy >>> from inequality.theil import Theil
>>> 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 >>> theil_y = Theil(y)
>>> theil_y.T array([0.20894344, 0.15222451, 0.10472941, 0.10194725, 0.09560113, 0.10511256, 0.10660832])
Methods
__init__(y[, column])