This is an example notebook of functionalities for multigroup aspatial indexes of the segregation module. Firstly, we need to import the packages we need:
In [1]:
%%capture
import pysal.lib
from pysal.explore import segregation
import geopandas as gpd
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
In [2]:
input_df = gpd.read_file(pysal.lib.examples.get_path("sacramentot2.shp"))
input_df.columns
Out[2]:
The groups of interest are White, Black, Asian and Hispanic population. Therefore, we create an auxiliary list with only the necessary columns for fitting the index.
In [3]:
groups_list = ['WHITE_', 'BLACK_', 'ASIAN_','HISP_']
We also can plot the spatial distribution of the composition of each of these groups over the tracts of Sacramento:
In [4]:
import matplotlib.pyplot as plt
for i in range(len(groups_list)):
input_df['comp_' + groups_list[i]] = input_df[groups_list[i]] / input_df['TOT_POP']
fig, axes = plt.subplots(ncols = 2, nrows = 2, figsize = (17, 10))
input_df.plot(column = 'comp_' + groups_list[0],
cmap = 'OrRd',
legend = True, ax = axes[0,0])
axes[0,0].set_title('Composition of ' + groups_list[0])
axes[0,0].set_xticks([])
axes[0,0].set_yticks([])
axes[0,0].set_facecolor('white')
input_df.plot(column = 'comp_' + groups_list[1],
cmap = 'OrRd',
legend = True, ax = axes[0,1])
axes[0,1].set_title('Composition of ' + groups_list[1])
axes[0,1].set_xticks([])
axes[0,1].set_yticks([])
axes[0,1].set_facecolor('white')
input_df.plot(column = 'comp_' + groups_list[2],
cmap = 'OrRd',
legend = True, ax = axes[1,0])
axes[1,0].set_title('Composition of ' + groups_list[2])
axes[1,0].set_xticks([])
axes[1,0].set_yticks([])
axes[1,0].set_facecolor('white')
input_df.plot(column = 'comp_' + groups_list[3],
cmap = 'OrRd',
legend = True, ax = axes[1,1])
axes[1,1].set_title('Composition of ' + groups_list[3])
axes[1,1].set_xticks([])
axes[1,1].set_yticks([])
axes[1,1].set_facecolor('white')
In [5]:
%%capture
from pysal.explore.segregation.aspatial import MultiDissim
In [6]:
index = MultiDissim(input_df, groups_list)
type(index)
Out[6]:
In [7]:
index.statistic
Out[7]:
In [8]:
%%capture
from pysal.explore.segregation.aspatial import MultiGiniSeg
In [9]:
index = MultiGiniSeg(input_df, groups_list)
type(index)
Out[9]:
In [10]:
index.statistic
Out[10]:
In [11]:
%%capture
from pysal.explore.segregation.aspatial import MultiNormalizedExposure
In [12]:
index = MultiNormalizedExposure(input_df, groups_list)
type(index)
Out[12]:
In [13]:
index.statistic
Out[13]:
In [14]:
%%capture
from pysal.explore.segregation.aspatial import MultiInformationTheory
In [15]:
index = MultiInformationTheory(input_df, groups_list)
type(index)
Out[15]:
In [16]:
index.statistic
Out[16]:
In [17]:
%%capture
from pysal.explore.segregation.aspatial import MultiRelativeDiversity
In [18]:
index = MultiRelativeDiversity(input_df, groups_list)
type(index)
Out[18]:
In [19]:
index.statistic
Out[19]:
In [20]:
%%capture
from pysal.explore.segregation.aspatial import MultiSquaredCoefficientVariation
In [21]:
index = MultiSquaredCoefficientVariation(input_df, groups_list)
type(index)
Out[21]:
In [22]:
index.statistic
Out[22]:
In [23]:
%%capture
from pysal.explore.segregation.aspatial import MultiDiversity
In [24]:
index = MultiDiversity(input_df, groups_list)
type(index)
Out[24]:
In [25]:
index.statistic
Out[25]:
In [26]:
# Normalized version of the multigroup diversity index
normalized_index = MultiDiversity(input_df, groups_list, normalized = True)
normalized_index.statistic
Out[26]:
In [27]:
%%capture
from pysal.explore.segregation.aspatial import SimpsonsConcentration
In [28]:
index = SimpsonsConcentration(input_df, groups_list)
type(index)
Out[28]:
In [29]:
index.statistic
Out[29]:
In [30]:
%%capture
from pysal.explore.segregation.aspatial import SimpsonsInteraction
In [31]:
index = SimpsonsInteraction(input_df, groups_list)
type(index)
Out[31]:
In [32]:
index.statistic
Out[32]:
In [33]:
%%capture
from pysal.explore.segregation.aspatial import MultiDivergence
In [34]:
index = MultiDivergence(input_df, groups_list)
type(index)
Out[34]:
In [35]:
index.statistic
Out[35]: