Multi-group Segregation Indices¶
[1]:
%load_ext watermark
%watermark -a 'eli knaap' -v -d -u -p segregation,geopandas,libpysal,pandana
Author: eli knaap
Last updated: 2021-05-09
Python implementation: CPython
Python version : 3.9.2
IPython version : 7.23.1
segregation: 2.0.0
geopandas : 0.9.0
libpysal : 4.3.0
pandana : 0.6.1
Classes for computing multigroup segregation indices are in the multigroup
module
[2]:
import geopandas as gpd
import matplotlib.pyplot as plt
from libpysal.examples import load_example
from segregation.multigroup import MultiDissim, MultiInfoTheory
[3]:
sacramento = gpd.read_file(load_example("Sacramento1").get_path("sacramentot2.shp"))
sacramento = sacramento.to_crs(sacramento.estimate_utm_crs())
Aspatial Segregation Indices¶
[4]:
multi_dissim = MultiDissim(sacramento, groups=['WHITE', 'BLACK', 'HISP'])
[5]:
multi_dissim.statistic
[5]:
0.42469982288295693
[6]:
multi_info = MultiInfoTheory(sacramento, groups=['WHITE', 'BLACK', 'HISP'])
[7]:
multi_info.statistic
[7]:
0.1800803002655424
Spatial Segregation Indices¶
As with single group measures, generalized spatial versions of multigroup indices can be created by passing a distance parameter or a W
/Network
object.
[8]:
spatial_multi_dissim = MultiDissim(sacramento, groups=['WHITE', 'BLACK', 'HISP'], distance=2000)
[9]:
spatial_multi_dissim.statistic
[9]:
0.3776841098505291
[10]:
from pandana import Network
[11]:
net = Network.from_hdf5("../40900.h5")
[12]:
net_multi_dissim = MultiDissim(sacramento, groups=['WHITE', 'BLACK', 'HISP'], distance=2000, network=net, decay='linear')
[13]:
net_multi_dissim.statistic
[13]:
0.3997196467720179
Batch-Computing Multi-Group Measures¶
To compute all single group indices in one go, the package provides a wrapper function in the batch
module similar to single-group indices
[14]:
from segregation.batch import batch_compute_multigroup
[16]:
all_multigroup = batch_compute_multigroup(sacramento, groups=['WHITE', 'BLACK', 'HISP'],)
[17]:
all_multigroup
[17]:
Statistic | |
---|---|
MultiDissim | 0.424700 |
MultiDivergence | 0.131709 |
MultiDiversity | 0.731390 |
MultiGini | 0.556467 |
MultiInfoTheory | 0.180080 |
MultiNormExposure | 0.191362 |
MultiRelativeDiversity | 0.168574 |
MultiSquaredCoefVar | 0.145315 |
SimpsonsConcentration | 0.587698 |
SimpsonsInteraction | 0.412302 |
[ ]: