Example of use of computing several measures of the PySAL segregation module: using ComputeAll classes

The Compute_All classes comprises simple and quick functions to assess multiple segregation measures at once in a dataset. It uses all the default parameters and returns an object that has an attribute (.computed) of a dictionary with summary of all values fitted.

The wrappers have currently three classes: ComputeAllAspatialSegregation, ComputeAllSpatialSegregation and ComputeAllSegregation which comprises all the measures available.

Firstly, we need to import the libraries and functions to be used.

%matplotlib inline

import geopandas as gpd
from pysal.explore import segregation
import pysal.lib
from pysal.explore.segregation.compute_all import ComputeAllAspatialSegregation, ComputeAllSpatialSegregation, ComputeAllSegregation

Then it’s time to load some data to estimate segregation. We use the data of 2000 Census Tract Data for the metropolitan area of Sacramento, CA, USA.

We use a geopandas dataframe available in PySAL examples repository.

For more information about the data: https://github.com/pysal/pysal.lib/tree/master/pysal.lib/examples/sacramento2

s_map = gpd.read_file(pysal.lib.examples.get_path("sacramentot2.shp"))
s_map.columns

Index(['FIPS', 'MSA', 'TOT_POP', 'POP_16', 'POP_65', 'WHITE_', 'BLACK_',
       'ASIAN_', 'HISP_', 'MULTI_RA', 'MALES', 'FEMALES', 'MALE1664',
       'FEM1664', 'EMPL16', 'EMP_AWAY', 'EMP_HOME', 'EMP_29', 'EMP_30',
       'EMP16_2', 'EMP_MALE', 'EMP_FEM', 'OCC_MAN', 'OCC_OFF1', 'OCC_INFO',
       'HH_INC', 'POV_POP', 'POV_TOT', 'HSG_VAL', 'FIPSNO', 'POLYID',
       'geometry'],
      dtype='object')

The data have several demographic variables. We are going to assess the segregation of the Hispanic Population (variable ‘HISP_’). For this, we only extract some columns of the geopandas dataframe.

gdf = s_map[['geometry', 'HISP_', 'TOT_POP']]

Compute All Aspatial Measures

aspatial_fit = ComputeAllAspatialSegregation(gdf, 'HISP_', 'TOT_POP')
aspatial_fit.computed

Measure Value
0 Dissimilarity 0.321847
1 Gini 0.435065
2 Entropy 0.094598
3 Atkinson 0.150793
4 Exposure 0.768038
5 Isolation 0.231962
6 Concentration Profile 0.137687
7 Bias Corrected Dissimilarity 0.321431
8 Density Corrected Dissimilarity 0.295205
9 Correlation Ratio 0.091640
10 Modified Dissimilarity 0.310733
11 Modified Gini 0.421795

Compute All Spatial Measures

spatial_fit = ComputeAllSpatialSegregation(gdf, 'HISP_', 'TOT_POP')
spatial_fit.computed

Measure Value
0 Spatial Dissimilarity 0.261197
1 Absolute Centralization 0.689142
2 Absolute Clustering 0.005189
3 Absolute Concentration 0.851282
4 Delta 0.804497
5 Relative Centralization -0.111942
6 Relative Clustering 0.009096
7 Relative Concentration 0.127338
8 Distance Decay Exposure 0.839658
9 Distance Decay Isolation 0.156216
10 Spatial Proximity Profile 0.228473
11 Spatial Proximity 1.002662
12 Boundary Spatial Dissimilarity 0.266763
13 Perimeter Area Ratio Spatial Dissimilarity 0.311172

Compute All Segregation Measures

segregation_fit = ComputeAllSegregation(gdf, 'HISP_', 'TOT_POP')
segregation_fit.computed

Measure Value
0 Dissimilarity 0.321847
1 Gini 0.435065
2 Entropy 0.094598
3 Atkinson 0.150793
4 Exposure 0.768038
5 Isolation 0.231962
6 Concentration Profile 0.137687
7 Bias Corrected Dissimilarity 0.321369
8 Density Corrected Dissimilarity 0.295205
9 Correlation Ratio 0.091640
10 Modified Dissimilarity 0.310738
11 Modified Gini 0.421745
12 Spatial Dissimilarity 0.261197
13 Absolute Centralization 0.689142
14 Absolute Clustering 0.005189
15 Absolute Concentration 0.851282
16 Delta 0.804497
17 Relative Centralization -0.111942
18 Relative Clustering 0.009096
19 Relative Concentration 0.127338
20 Distance Decay Exposure 0.839658
21 Distance Decay Isolation 0.156216
22 Spatial Proximity Profile 0.228473
23 Spatial Proximity 1.002662
24 Boundary Spatial Dissimilarity 0.266763
25 Perimeter Area Ratio Spatial Dissimilarity 0.311172