Search
compute_all_example

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
import segregation
import libpysal
import numpy as np
from 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/libpysal/tree/master/libpysal/examples/sacramento2

s_map = gpd.read_file(libpysal.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

np.random.seed(123)
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.321420
8 Density Corrected Dissimilarity 0.295205
9 Correlation Ratio 0.091640
10 Modified Dissimilarity 0.310746
11 Modified Gini 0.421793
12 Minimun-Maximum 0.486965

Compute All Spatial Measures

np.random.seed(123)
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
14 Spatial Minimun-Maximum 0.171200

Compute All Segregation Measures

np.random.seed(123)
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.321420
8 Density Corrected Dissimilarity 0.295205
9 Correlation Ratio 0.091640
10 Modified Dissimilarity 0.310746
11 Modified Gini 0.421793
12 Minimun-Maximum 0.486965
13 Spatial Dissimilarity 0.261197
14 Absolute Centralization 0.689142
15 Absolute Clustering 0.005189
16 Absolute Concentration 0.851282
17 Delta 0.804497
18 Relative Centralization -0.111942
19 Relative Clustering 0.009096
20 Relative Concentration 0.127338
21 Distance Decay Exposure 0.839658
22 Distance Decay Isolation 0.156216
23 Spatial Proximity Profile 0.228473
24 Spatial Proximity 1.002662
25 Boundary Spatial Dissimilarity 0.266763
26 Perimeter Area Ratio Spatial Dissimilarity 0.311172
27 Spatial Minimun-Maximum 0.171200