locality-splitting
Code to score locality (e.g. county, community-of-interest) splitting in political districting plans
Science Score: 46.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
✓Academic publication links
Links to: arxiv.org -
✓Committers with academic emails
1 of 4 committers (25.0%) from academic institutions -
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (10.8%) to scientific vocabulary
Repository
Code to score locality (e.g. county, community-of-interest) splitting in political districting plans
Basic Info
Statistics
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
- Releases: 0
Metadata Files
README.md
Metrics of locality splitting/preservation in district maps
Description
This code accompanies the Center for Democracy & Technology report, Split Decisions: Guidance for Measuring Locality Preservation in District Maps, by Jacob Wachspress and William T. Adler.
This repository contains Python code that implements a number of metrics for quantifying locality (e.g. county, community of interest) splitting in districting plans. The metrics implemented are: - Geography-based - Number of localities split - Number of locality-district intersections - Population-based - Effective splits1 - Conditional entropy2 - Square root entropy3 - Split pairs4
Options are provided to ignore zero-population regions and to calculate symmetric splitting scores.
A description of the metrics (with formulas) can be found in the report, linked above.
Installation
If using pip, do pip install locality-splitting
Example use
The required input is a pandas DataFrame with a row for each unit (usually census block or precinct) used to build the districts. The DataFrame must have a column denoting each unit's population, district, and locality. For U.S. Census provides a table with census blocks and their corresponding districts, called "block equivalency files." We have provided code to download block equivalency files from the U.S. Census website for the congressional and state legislative (upper and lower chamber) plans used in the 2012, 2014, 2016, and 2018 elections.
```python from localitysplitting import blockequivalencyfile as bef year = 2018 plantype = 'cd' df = bef.getblockequivalencyfile(year, plantype)
df.head(10) ```
| BLOCKID | cd_2018 | |
|---|---|---|
| 0 | 011290440001080 | 01 |
| 1 | 011290440001010 | 01 |
| 2 | 011290440001092 | 01 |
| 3 | 011290440001091 | 01 |
| 4 | 011290440001090 | 01 |
| 5 | 011290440001089 | 01 |
| 6 | 011290440001088 | 01 |
| 7 | 011290440001087 | 01 |
| 8 | 011290440001086 | 01 |
| 9 | 011290440001085 | 01 |
Next we have to pick a state and merge in populations from the census API. We will use Pennsylvania as an example, which has FIPS code 42. State FIPS codes can be looked up here.
python
fips_code = '42'
df_pop = bef.merge_state_census_block_pops(fips_code, df)
df_pop.head(10)
| BLOCKID | pop | cd_2018 | |
|---|---|---|---|
| 0 | 420010301011000 | 6 | 13 |
| 1 | 420010301011001 | 30 | 13 |
| 2 | 420010301011002 | 15 | 13 |
| 3 | 420010301011003 | 77 | 13 |
| 4 | 420010301011004 | 27 | 13 |
| 5 | 420010301011005 | 25 | 13 |
| 6 | 420010301011006 | 12 | 13 |
| 7 | 420010301011007 | 0 | 13 |
| 8 | 420010301011008 | 4 | 13 |
| 9 | 420010301011009 | 62 | 13 |
To calculate these metrics for county splitting, we need a column for the county. Conveniently, the first two digits of the census BLOCKID correspond to the state FIPS code, and the next three digits correspond to the county FIPS code.
python
df_pop['county'] = df_pop['BLOCKID'].str[2:5]
df_pop.head(10)
| BLOCKID | pop | cd_2018 | county | |
|---|---|---|---|---|
| 0 | 420010301011000 | 6 | 13 | 001 |
| 1 | 420010301011001 | 30 | 13 | 001 |
| 2 | 420010301011002 | 15 | 13 | 001 |
| 3 | 420010301011003 | 77 | 13 | 001 |
| 4 | 420010301011004 | 27 | 13 | 001 |
| 5 | 420010301011005 | 25 | 13 | 001 |
| 6 | 420010301011006 | 12 | 13 | 001 |
| 7 | 420010301011007 | 0 | 13 | 001 |
| 8 | 420010301011008 | 4 | 13 | 001 |
| 9 | 420010301011009 | 62 | 13 | 001 |
Then if you write the following python code:
```python from locality_splitting import metrics
metrics.calculateallmetrics(dfpop, 'cd2018', lcltycol='county')
you will get an output like this:
python
{'plan': 'cd2018',
'splitsall': 14.0,
'splitspop': 13.0,
'intersectionsall': 85.0,
'intersectionspop': 84.0,
'effectivesplits': 10.160339912460943,
'conditionalentropy': 0.47256386411416673,
'sqrtentropy': 1.22572584704072,
'splitpairs': 0.21090396242846743,
'splitspopsym': 14.0,
'intersectionspopsym': 84.0,
'effectivesplitssym': 6.3402186767789255,
'conditionalentropysym': 0.9622343161303942,
'sqrtentropysym': 1.5503698835379716,
'splitpairssym': 0.34663230810650736}
```
References
- Samuel Wang, Sandra J. Chen, Richard Ober, Bernard Grofman, Kyle Barnes, and Jonathan Cervas. (2021). Turning Communities Of Interest Into A Rigorous Standard For Fair Districting. Stanford Journal of Civil Rights and Civil Liberties, Forthcoming.
- Larry Guth, Ari Nieh, and Thomas Weighill. (2020). Three Applications of Entropy to Gerrymandering. arXiv.
- Moon Duchin. (2018). Outlier analysis for Pennsylvania congressional redistricting.
- Jacob Wachspress and William T. Adler. (2021). Split Decisions: Guidance for Measuring Locality Preservation in District Maps. Center for Democracy and Technology.
Owner
- Name: Jacob Wachspress
- Login: jacobwachspress
- Kind: user
- Repositories: 2
- Profile: https://github.com/jacobwachspress
GitHub Events
Total
Last Year
Committers
Last synced: about 3 years ago
All Time
- Total Commits: 70
- Total Committers: 4
- Avg Commits per committer: 17.5
- Development Distribution Score (DDS): 0.629
Top Committers
| Name | Commits | |
|---|---|---|
| jacobwachspress | j****w@p****u | 26 |
| Jacob Wachspress | j****s@g****m | 24 |
| connormoffatt | c****4@g****m | 14 |
| Will Adler | w****l@w****m | 6 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 8 months ago
All Time
- Total issues: 0
- Total pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Total issue authors: 0
- Total pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 33 last-month
- Total dependent packages: 0
- Total dependent repositories: 1
- Total versions: 9
- Total maintainers: 1
pypi.org: locality-splitting
Implementation of locality splitting metrics for political redistricing plans
- Homepage: https://github.com/jacobwachspress/locality-splitting
- Documentation: https://locality-splitting.readthedocs.io/
- License: MIT License
-
Latest release: 0.2.1
published over 4 years ago
