inequality.theil.TheilDSim#
- class inequality.theil.TheilDSim(y, partition, permutations=99, column=None)[source]#
Random permutation based inference on Theil’s inequality decomposition. Provides for computationally based inference regarding the inequality decomposition using random spatial permutations. See [RSastreGutierrez10].
- 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.- 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.
- permutations
int The number of random spatial permutations for computationally based inference on the decomposition.
- column
strorlistofstr,optional Name(s) of the column(s) holding the values when
yis apandas.DataFrame.
- y
- Attributes:
- observed
numpy.array An array in the shape \((n,t)\) or \((n,)\) representing a
TheilDinstance for the observed data.- bg
numpy.array An array in the shape
(permutations+1, t)representing between group inequality.- bg_pvalue
numpy.array An array in the shape \((t,1)\) representing the \(p\)-value for the between group measure. Measures the percentage of the realized values that were greater than or equal to the observed
bgvalue. Includes the observed value.- wg
numpy.array An array in the shape
(permutations+1)representing within group inequality. Depending on the shape ofy, the array may be 1- or 2-dimensional.
- observed
Examples
>>> import libpysal >>> import numpy >>> from inequality.theil import TheilDSim
>>> 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')) >>> numpy.random.seed(10) >>> theil_ds = TheilDSim(y, regimes, 999)
>>> theil_ds.bg_pvalue array([0.4 , 0.344, 0.001, 0.001, 0.034, 0.072, 0.032])
Methods
__init__(y, partition[, permutations, column])