<jupyter_start><jupyter_text>Multigroup aspatial indexes of segregation This is an example notebook of functionalities for multigroup aspatial indexes of the *segregation* module. Firstly, we need to import the packages we need:<jupyter_code>%%capture

import pysal.lib
from pysal.explore import segregation
import geopandas as gpd<jupyter_output><empty_output><jupyter_text>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<jupyter_code>input_df = gpd.read_file(pysal.lib.examples.get_path("sacramentot2.shp"))
input_df.columns<jupyter_output><empty_output><jupyter_text>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.<jupyter_code>groups_list = ['WHITE_', 'BLACK_', 'ASIAN_','HISP_']<jupyter_output><empty_output><jupyter_text>We also can plot the spatial distribution of the composition of each of these groups over the tracts of Sacramento:<jupyter_code>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')<jupyter_output><empty_output><jupyter_text>Multigroup Dissimilarity Index<jupyter_code>%%capture
from pysal.explore.segregation.aspatial import MultiDissim
index = MultiDissim(input_df, groups_list)
type(index)
index.statistic<jupyter_output><empty_output><jupyter_text>Multigroup Gini Index<jupyter_code>%%capture
from pysal.explore.segregation.aspatial import MultiGiniSeg
index = MultiGiniSeg(input_df, groups_list)
type(index)
index.statistic<jupyter_output><empty_output><jupyter_text>Multigroup Normalized Exposure Index<jupyter_code>%%capture
from pysal.explore.segregation.aspatial import MultiNormalizedExposure
index = MultiNormalizedExposure(input_df, groups_list)
type(index)
index.statistic<jupyter_output><empty_output><jupyter_text>Multigroup Information Theory Index<jupyter_code>%%capture
from pysal.explore.segregation.aspatial import MultiInformationTheory
index = MultiInformationTheory(input_df, groups_list)
type(index)
index.statistic<jupyter_output><empty_output><jupyter_text>Multigroup Relative Diversity Index<jupyter_code>%%capture
from pysal.explore.segregation.aspatial import MultiRelativeDiversity
index = MultiRelativeDiversity(input_df, groups_list)
type(index)
index.statistic<jupyter_output><empty_output><jupyter_text>Multigroup Squared Coefficient of Variation Index<jupyter_code>%%capture
from pysal.explore.segregation.aspatial import MultiSquaredCoefficientVariation
index = MultiSquaredCoefficientVariation(input_df, groups_list)
type(index)
index.statistic<jupyter_output><empty_output><jupyter_text>Multigroup Diversity Index<jupyter_code>%%capture
from pysal.explore.segregation.aspatial import MultiDiversity
index = MultiDiversity(input_df, groups_list)
type(index)
index.statistic
# Normalized version of the multigroup diversity index
normalized_index = MultiDiversity(input_df, groups_list, normalized = True)
normalized_index.statistic<jupyter_output><empty_output><jupyter_text>Simpson's Concentration Index (lambda)<jupyter_code>%%capture
from pysal.explore.segregation.aspatial import SimpsonsConcentration
index = SimpsonsConcentration(input_df, groups_list)
type(index)
index.statistic<jupyter_output><empty_output><jupyter_text>Simpson's Interaction Index (I)<jupyter_code>%%capture
from pysal.explore.segregation.aspatial import SimpsonsInteraction
index = SimpsonsInteraction(input_df, groups_list)
type(index)
index.statistic<jupyter_output><empty_output><jupyter_text>Multigroup Divergence Index<jupyter_code>%%capture
from pysal.explore.segregation.aspatial import MultiDivergence
index = MultiDivergence(input_df, groups_list)
type(index)
index.statistic<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1091820987654321, 'fraction_numerical': 0.011574074074074073, 'mean_word_length': 7.542009884678748, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 57, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '14', 'dir': 'jupyter-structured-clean-dedup', 'id': '461868', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1869, 'n_tokens_neox': 1774, 'n_words': 341, 'path': 'notebooks/explore/segregation/multigroup_aspatial_examples.ipynb', 'repo_name': 'AndrewAnnex/pysal', 'size': '5184'}