poli-sci-kit 2.0.3__tar.gz → 2.0.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {poli_sci_kit-2.0.3 → poli_sci_kit-2.0.5}/NOTICE.txt +1 -1
- {poli_sci_kit-2.0.3/src/poli_sci_kit.egg-info → poli_sci_kit-2.0.5}/PKG-INFO +50 -49
- {poli_sci_kit-2.0.3 → poli_sci_kit-2.0.5}/README.md +44 -43
- {poli_sci_kit-2.0.3 → poli_sci_kit-2.0.5}/pyproject.toml +10 -10
- {poli_sci_kit-2.0.3 → poli_sci_kit-2.0.5/src/poli_sci_kit.egg-info}/PKG-INFO +50 -49
- poli_sci_kit-2.0.5/src/poli_sci_kit.egg-info/requires.txt +7 -0
- poli_sci_kit-2.0.3/src/poli_sci_kit.egg-info/requires.txt +0 -7
- {poli_sci_kit-2.0.3 → poli_sci_kit-2.0.5}/LICENSE.txt +0 -0
- {poli_sci_kit-2.0.3 → poli_sci_kit-2.0.5}/setup.cfg +0 -0
- {poli_sci_kit-2.0.3 → poli_sci_kit-2.0.5}/src/poli_sci_kit/__init__.py +0 -0
- {poli_sci_kit-2.0.3 → poli_sci_kit-2.0.5}/src/poli_sci_kit/appointment/__init__.py +0 -0
- {poli_sci_kit-2.0.3 → poli_sci_kit-2.0.5}/src/poli_sci_kit/appointment/checks.py +0 -0
- {poli_sci_kit-2.0.3 → poli_sci_kit-2.0.5}/src/poli_sci_kit/appointment/methods.py +0 -0
- {poli_sci_kit-2.0.3 → poli_sci_kit-2.0.5}/src/poli_sci_kit/appointment/metrics.py +0 -0
- {poli_sci_kit-2.0.3 → poli_sci_kit-2.0.5}/src/poli_sci_kit/plot/__init__.py +0 -0
- {poli_sci_kit-2.0.3 → poli_sci_kit-2.0.5}/src/poli_sci_kit/plot/disproportionality_bar_plot.py +0 -0
- {poli_sci_kit-2.0.3 → poli_sci_kit-2.0.5}/src/poli_sci_kit/plot/parliament_plot.py +0 -0
- {poli_sci_kit-2.0.3 → poli_sci_kit-2.0.5}/src/poli_sci_kit/utils.py +0 -0
- {poli_sci_kit-2.0.3 → poli_sci_kit-2.0.5}/src/poli_sci_kit.egg-info/SOURCES.txt +0 -0
- {poli_sci_kit-2.0.3 → poli_sci_kit-2.0.5}/src/poli_sci_kit.egg-info/dependency_links.txt +0 -0
- {poli_sci_kit-2.0.3 → poli_sci_kit-2.0.5}/src/poli_sci_kit.egg-info/top_level.txt +0 -0
- {poli_sci_kit-2.0.3 → poli_sci_kit-2.0.5}/tests/test_utils.py +0 -0
|
@@ -52,7 +52,7 @@ the USERS to familiarize themselves with any changes to this NOTICE.
|
|
|
52
52
|
3. Contact
|
|
53
53
|
|
|
54
54
|
If you have any questions, concerns, or suggestions about this NOTICE,
|
|
55
|
-
do not hesitate to visit https://
|
|
55
|
+
do not hesitate to visit https://codeberg.org/andrewtavis/poli-sci-kit.
|
|
56
56
|
The person responsible for such inquiries is Andrew Tavis McAllister.
|
|
57
57
|
|
|
58
58
|
4. Effective Date
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: poli-sci-kit
|
|
3
|
-
Version: 2.0.
|
|
3
|
+
Version: 2.0.5
|
|
4
4
|
Summary: Political elections, appointment, analysis and visualization in Python
|
|
5
5
|
Author-email: Andrew Tavis McAllister <andrew.t.mcallister@gmail.com>
|
|
6
|
-
Project-URL: Homepage, https://
|
|
6
|
+
Project-URL: Homepage, https://codeberg.org/andrewtavis/poli-sci-kit
|
|
7
7
|
Keywords: politics,analysis,voting,democracy,political-science,elections,appointment,political-appointment-analysis,disproportionality
|
|
8
8
|
Classifier: Development Status :: 5 - Production/Stable
|
|
9
9
|
Classifier: Intended Audience :: Developers
|
|
@@ -21,30 +21,30 @@ Description-Content-Type: text/markdown
|
|
|
21
21
|
License-File: LICENSE.txt
|
|
22
22
|
License-File: NOTICE.txt
|
|
23
23
|
Requires-Dist: colormath>=3.0.0
|
|
24
|
-
Requires-Dist: matplotlib>=3.11.
|
|
25
|
-
Requires-Dist: numpy>=2.5.
|
|
24
|
+
Requires-Dist: matplotlib>=3.11.2
|
|
25
|
+
Requires-Dist: numpy>=2.5.3
|
|
26
26
|
Requires-Dist: packaging>=26.3
|
|
27
|
-
Requires-Dist: pandas>=3.0.
|
|
28
|
-
Requires-Dist: scipy>=1.18.
|
|
27
|
+
Requires-Dist: pandas>=3.0.6
|
|
28
|
+
Requires-Dist: scipy>=1.18.1
|
|
29
29
|
Requires-Dist: seaborn>=0.13.2
|
|
30
30
|
Dynamic: license-file
|
|
31
31
|
|
|
32
32
|
<a id="top"></a>
|
|
33
33
|
|
|
34
34
|
<div align="center">
|
|
35
|
-
<a href="https://
|
|
35
|
+
<a href="https://codeberg.org/andrewtavis/poli-sci-kit"><img src="https://codeberg.org/andrewtavis/poli-sci-kit/raw/branch/main/.forgejo/resources/logo/poli-sci-kit_logo_transparent.png" height=250></a>
|
|
36
36
|
</div>
|
|
37
37
|
|
|
38
38
|
<ol></ol>
|
|
39
39
|
|
|
40
40
|
[](http://poli-sci-kit.readthedocs.io/en/latest/)
|
|
41
|
-
[](https://codeberg.org/andrewtavis/poli-sci-kit/actions?workflow=ci_static_analysis.yaml)
|
|
42
|
+
[](https://codeberg.org/andrewtavis/poli-sci-kit/actions/?workflow=ci_pytest.yaml)
|
|
43
43
|
[](https://pypi.org/project/poli-sci-kit/)
|
|
44
44
|
[](https://pypi.org/project/poli-sci-kit/)
|
|
45
45
|
[](https://pypi.org/project/poli-sci-kit/)
|
|
46
|
-
[](https://
|
|
47
|
-
[](https://
|
|
46
|
+
[](https://codeberg.org/andrewtavis/poli-sci-kit/src/branch/main/LICENSE.txt)
|
|
47
|
+
[](https://codeberg.org/andrewtavis/poli-sci-kit/src/branch/main/.forgejo/CODE_OF_CONDUCT.md)
|
|
48
48
|
[](https://colab.research.google.com/github/andrewtavis/poli-sci-kit)
|
|
49
49
|
|
|
50
50
|
### Political elections, appointment, analysis and visualization in Python
|
|
@@ -53,14 +53,19 @@ Dynamic: license-file
|
|
|
53
53
|
|
|
54
54
|
# Contents
|
|
55
55
|
|
|
56
|
-
- [
|
|
57
|
-
- [
|
|
58
|
-
- [
|
|
59
|
-
|
|
60
|
-
- [
|
|
61
|
-
- [
|
|
62
|
-
- [
|
|
63
|
-
- [
|
|
56
|
+
- [Maintenance](#maintenance)
|
|
57
|
+
- [Installation](#installation)
|
|
58
|
+
- [Appointment](#appointment)
|
|
59
|
+
- [Plotting](#plotting)
|
|
60
|
+
- [Parliament Plots](#parliament-plots)
|
|
61
|
+
- [Disproportionality Bar Plot](#disproportionality-bar-plot)
|
|
62
|
+
- [Examples](#examples)
|
|
63
|
+
- [Development environment](#development-environment)
|
|
64
|
+
- [To-Do](#to-do)
|
|
65
|
+
|
|
66
|
+
# Maintenance
|
|
67
|
+
|
|
68
|
+
`poli-sci-kit` is maintained at [codeberg.org/andrewtavis/poli-sci-kit](https://codeberg.org/andrewtavis/poli-sci-kit). Please visit this remote repository for issues and pull requests.
|
|
64
69
|
|
|
65
70
|
# Installation
|
|
66
71
|
|
|
@@ -79,7 +84,8 @@ pip install poli-sci-kit
|
|
|
79
84
|
### For Development Build
|
|
80
85
|
|
|
81
86
|
```bash
|
|
82
|
-
git clone https://
|
|
87
|
+
git clone https://codeberg.org/andrewtavis/poli-sci-kit.git
|
|
88
|
+
# git clone https://codeberg.org/<your-username>/poli-sci-kit.git
|
|
83
89
|
cd poli-sci-kit
|
|
84
90
|
|
|
85
91
|
# With uv (recommended):
|
|
@@ -102,13 +108,13 @@ import poli_sci_kit
|
|
|
102
108
|
|
|
103
109
|
# Appointment
|
|
104
110
|
|
|
105
|
-
[appointment.methods](https://
|
|
111
|
+
[appointment.methods](https://codeberg.org/andrewtavis/poli-sci-kit/src/branch/main/src/poli_sci_kit/appointment/methods.py) includes functions to allocate parliamentary seats based on population or vote shares. Included methods are:
|
|
106
112
|
|
|
107
113
|
#### Largest Remainder: Hare, Droop, Hagenbach–Bischoff (incl Hamilton, Vinton, Hare–Niemeyer)
|
|
108
114
|
|
|
109
115
|
#### Highest Averages: Jefferson, Webster, Huntington-Hill
|
|
110
116
|
|
|
111
|
-
Arguments to allow allocation thresholds, minimum allocations per group, tie break conditions, and other election features are also provided. Along with deriving results for visualization and reporting, these functions allow the user to analyze outcomes given systematic or situational changes. The [appointment.metrics](https://
|
|
117
|
+
Arguments to allow allocation thresholds, minimum allocations per group, tie break conditions, and other election features are also provided. Along with deriving results for visualization and reporting, these functions allow the user to analyze outcomes given systematic or situational changes. The [appointment.metrics](https://codeberg.org/andrewtavis/poli-sci-kit/src/branch/main/src/poli_sci_kit/appointment/metrics.py) module further provides diagnostics to analyze the results of elections, apportionments, and other political science scenarios.
|
|
112
118
|
|
|
113
119
|
A basic example of political appointment using poli-sci-kit is:
|
|
114
120
|
|
|
@@ -139,9 +145,7 @@ We can then compute various metrics to derive disproportionality:
|
|
|
139
145
|
```python
|
|
140
146
|
# The Gallagher method is a measure of absolute difference similar to summing square residuals.
|
|
141
147
|
disproportionality = appointment.metrics.disproportionality_index(
|
|
142
|
-
shares=vote_counts,
|
|
143
|
-
allocations=ha_allocations,
|
|
144
|
-
metric_type='Gallagher'
|
|
148
|
+
shares=vote_counts, allocations=ha_allocations, metric_type="Gallagher"
|
|
145
149
|
)
|
|
146
150
|
|
|
147
151
|
disproportionality
|
|
@@ -151,16 +155,13 @@ disproportionality
|
|
|
151
155
|
We can also check that the allocations pass the [quota condition](https://en.wikipedia.org/wiki/Quota_rule):
|
|
152
156
|
|
|
153
157
|
```python
|
|
154
|
-
passes_qc = appointment.checks.quota_condition(
|
|
155
|
-
shares=vote_counts,
|
|
156
|
-
seats=ha_allocations
|
|
157
|
-
)
|
|
158
|
+
passes_qc = appointment.checks.quota_condition(shares=vote_counts, seats=ha_allocations)
|
|
158
159
|
|
|
159
160
|
passes_qc
|
|
160
161
|
# True
|
|
161
162
|
```
|
|
162
163
|
|
|
163
|
-
Allocation consistency can further be checked using dataframes of shares and seats given electoral settings. See [appointment.checks](https://
|
|
164
|
+
Allocation consistency can further be checked using dataframes of shares and seats given electoral settings. See [appointment.checks](https://codeberg.org/andrewtavis/poli-sci-kit/src/branch/main/src/poli_sci_kit/appointment/checks.py) and [the documentation](https://poli-sci-kit.readthedocs.io/en/latest/) for explanations of method checks.
|
|
164
165
|
|
|
165
166
|
<sub><a href="#top">Back to top.</a></sub>
|
|
166
167
|
|
|
@@ -175,15 +176,15 @@ import matplotlib.pyplot as plt
|
|
|
175
176
|
import poli_sci_kit
|
|
176
177
|
|
|
177
178
|
# German political parties.
|
|
178
|
-
parties = [
|
|
179
|
-
party_colors = [
|
|
179
|
+
parties = ["CDU/CSU", "FDP", "Greens", "Die Linke", "SPD", "AfD"]
|
|
180
|
+
party_colors = ["#000000", "#ffed00", "#64a12d", "#be3075", "#eb001f", "#009ee0"]
|
|
180
181
|
```
|
|
181
182
|
|
|
182
183
|
<sub><a href="#top">Back to top.</a></sub>
|
|
183
184
|
|
|
184
185
|
### Parliament Plots
|
|
185
186
|
|
|
186
|
-
poli_sci_kit provides implementations of both rectangular and semicircle [parliament plots](https://
|
|
187
|
+
poli_sci_kit provides implementations of both rectangular and semicircle [parliament plots](https://codeberg.org/andrewtavis/poli-sci-kit/src/branch/main/src/poli_sci_kit/plot/parliament_plot.py):
|
|
187
188
|
|
|
188
189
|
```python
|
|
189
190
|
fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2)
|
|
@@ -214,15 +215,15 @@ plt.show()
|
|
|
214
215
|
```
|
|
215
216
|
|
|
216
217
|
<p align="middle">
|
|
217
|
-
<img src="https://
|
|
218
|
-
<img src="https://
|
|
218
|
+
<img src="https://codeberg.org/andrewtavis/poli-sci-kit/raw/branch/main/.forgejo/resources/images/rectangle_parliament_plot.png" width="400" />
|
|
219
|
+
<img src="https://codeberg.org/andrewtavis/poli-sci-kit/raw/branch/main/.forgejo/resources/images/semicircle_parliament_plot.png" width="400" />
|
|
219
220
|
</p>
|
|
220
221
|
|
|
221
222
|
<sub><a href="#top">Back to top.</a></sub>
|
|
222
223
|
|
|
223
224
|
### Disproportionality Bar Plot
|
|
224
225
|
|
|
225
|
-
A novel addition to social science analysis is the [disproportionality bar plot](https://
|
|
226
|
+
A novel addition to social science analysis is the [disproportionality bar plot](https://codeberg.org/andrewtavis/poli-sci-kit/src/branch/main/src/poli_sci_kit/plot/disproportionality_bar_plot.py), which graphically depicts the disproportionality between expected and realized results. Bar widths are the proportion of shares (ex: votes received), and heights are the difference or relative difference between shares and allocations (ex: parliament seats received).
|
|
226
227
|
|
|
227
228
|
An example follows:
|
|
228
229
|
|
|
@@ -264,15 +265,15 @@ ax.legend(
|
|
|
264
265
|
framealpha=1,
|
|
265
266
|
)
|
|
266
267
|
|
|
267
|
-
ax.axes.set_title(
|
|
268
|
-
ax.set_xlabel(
|
|
269
|
-
ax.set_ylabel(
|
|
268
|
+
ax.axes.set_title("Seat to Vote Share Disproportionality", fontsize=30)
|
|
269
|
+
ax.set_xlabel("Parties", fontsize=20)
|
|
270
|
+
ax.set_ylabel("Percent Shift", fontsize=20)
|
|
270
271
|
|
|
271
272
|
plt.show()
|
|
272
273
|
```
|
|
273
274
|
|
|
274
275
|
<p align="middle">
|
|
275
|
-
<img src="https://
|
|
276
|
+
<img src="https://codeberg.org/andrewtavis/poli-sci-kit/raw/branch/main/.forgejo/resources/images/disproportionality_bar_plot.png" width="600" />
|
|
276
277
|
</p>
|
|
277
278
|
|
|
278
279
|
<sub><a href="#top">Back to top.</a></sub>
|
|
@@ -281,10 +282,10 @@ plt.show()
|
|
|
281
282
|
|
|
282
283
|
Examples in poli-sci-kit use publicly available Wikidata statistics sourced via the Python package [wikirepo](https://github.com/andrewtavis/wikirepo). Current examples include:
|
|
283
284
|
|
|
284
|
-
- [US HoR](https://
|
|
285
|
+
- [US HoR](https://codeberg.org/andrewtavis/poli-sci-kit/src/branch/main/examples/us_house_of_rep.ipynb) [(Open in Colab)](https://colab.research.google.com/github/andrewtavis/poli-sci-kit/blob/main/examples/us_house_of_rep.ipynb)
|
|
285
286
|
- Allocates seats to a version of the US House of Representatives that includes all US territories and Washington DC given census data, with this further being used to derive relative vote strengths of state citizens in the US presidential election
|
|
286
287
|
|
|
287
|
-
- [Global Parliament](https://
|
|
288
|
+
- [Global Parliament](https://codeberg.org/andrewtavis/poli-sci-kit/src/branch/main/examples/global_parliament.ipynb) [(Open in Colab)](https://colab.research.google.com/github/andrewtavis/poli-sci-kit/blob/main/examples/global_parliament.ipynb)
|
|
288
289
|
- Analyzes the allocation of seats in a hypothetical global parliament given the prevalence of certain countries and organizations, the distribution of seats based on Freedom House indexes, as well as disproportionality metrics
|
|
289
290
|
|
|
290
291
|
<sub><a href="#top">Back to top.</a></sub>
|
|
@@ -297,11 +298,11 @@ Please follow the steps below to set up your development environment for poli-sc
|
|
|
297
298
|
|
|
298
299
|
```bash
|
|
299
300
|
# Clone your fork of the repo into the current directory.
|
|
300
|
-
git clone https://
|
|
301
|
+
git clone https://codeberg.org/<your-username>/poli-sci-kit.git
|
|
301
302
|
# Navigate to the newly cloned directory.
|
|
302
303
|
cd poli-sci-kit
|
|
303
304
|
# Assign the original repo to a remote called "upstream".
|
|
304
|
-
git remote add upstream https://
|
|
305
|
+
git remote add upstream https://codeberg.org/andrewtavis/poli-sci-kit.git
|
|
305
306
|
```
|
|
306
307
|
|
|
307
308
|
- Now, if you run `git remote -v` you should see two remote repositories named:
|
|
@@ -367,18 +368,18 @@ uv run prek run --all-files
|
|
|
367
368
|
|
|
368
369
|
# To-Do
|
|
369
370
|
|
|
370
|
-
Please see the [contribution guidelines](https://
|
|
371
|
+
Please see the [contribution guidelines](https://codeberg.org/andrewtavis/poli-sci-kit/src/branch/main/CONTRIBUTING.md) if you are interested in contributing to this project. Work that is in progress or could be implemented includes:
|
|
371
372
|
|
|
372
|
-
- Adding the [Adams method](https://en.wikipedia.org/wiki/Highest_averages_method) to [appointment.methods.highest_averages](https://
|
|
373
|
+
- Adding the [Adams method](https://en.wikipedia.org/wiki/Highest_averages_method) to [appointment.methods.highest_averages](https://codeberg.org/andrewtavis/poli-sci-kit/src/branch/main/src/poli_sci_kit/appointment/methods.py) ([see issue](https://codeberg.org/andrewtavis/poli-sci-kit/issues/21))
|
|
373
374
|
|
|
374
|
-
- Deriving further needed arguments to assure that all current and historic appointment systems can be simulated using poli-sci-kit ([see issue](https://
|
|
375
|
+
- Deriving further needed arguments to assure that all current and historic appointment systems can be simulated using poli-sci-kit ([see issue](https://codeberg.org/andrewtavis/poli-sci-kit/issues/22))
|
|
375
376
|
|
|
376
|
-
- Potentially indexing preset versions of [appointment.methods](https://
|
|
377
|
+
- Potentially indexing preset versions of [appointment.methods](https://codeberg.org/andrewtavis/poli-sci-kit/src/branch/main/src/poli_sci_kit/appointment/methods.py) that coincide with the systems used by governments around the world
|
|
377
378
|
- This would allow quick comparisons of actual systems with variations
|
|
378
379
|
|
|
379
380
|
- Adding methods such as quadratic voting to poli-sci-kit to allow for preference based simulations
|
|
380
381
|
|
|
381
|
-
- Creating, improving and sharing [examples](https://
|
|
382
|
+
- Creating, improving and sharing [examples](https://codeberg.org/andrewtavis/poli-sci-kit/tree/main/examples)
|
|
382
383
|
|
|
383
384
|
<sub><a href="#top">Back to top.</a></sub>
|
|
384
385
|
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
<a id="top"></a>
|
|
2
2
|
|
|
3
3
|
<div align="center">
|
|
4
|
-
<a href="https://
|
|
4
|
+
<a href="https://codeberg.org/andrewtavis/poli-sci-kit"><img src="https://codeberg.org/andrewtavis/poli-sci-kit/raw/branch/main/.forgejo/resources/logo/poli-sci-kit_logo_transparent.png" height=250></a>
|
|
5
5
|
</div>
|
|
6
6
|
|
|
7
7
|
<ol></ol>
|
|
8
8
|
|
|
9
9
|
[](http://poli-sci-kit.readthedocs.io/en/latest/)
|
|
10
|
-
[](https://codeberg.org/andrewtavis/poli-sci-kit/actions?workflow=ci_static_analysis.yaml)
|
|
11
|
+
[](https://codeberg.org/andrewtavis/poli-sci-kit/actions/?workflow=ci_pytest.yaml)
|
|
12
12
|
[](https://pypi.org/project/poli-sci-kit/)
|
|
13
13
|
[](https://pypi.org/project/poli-sci-kit/)
|
|
14
14
|
[](https://pypi.org/project/poli-sci-kit/)
|
|
15
|
-
[](https://
|
|
16
|
-
[](https://
|
|
15
|
+
[](https://codeberg.org/andrewtavis/poli-sci-kit/src/branch/main/LICENSE.txt)
|
|
16
|
+
[](https://codeberg.org/andrewtavis/poli-sci-kit/src/branch/main/.forgejo/CODE_OF_CONDUCT.md)
|
|
17
17
|
[](https://colab.research.google.com/github/andrewtavis/poli-sci-kit)
|
|
18
18
|
|
|
19
19
|
### Political elections, appointment, analysis and visualization in Python
|
|
@@ -22,14 +22,19 @@
|
|
|
22
22
|
|
|
23
23
|
# Contents
|
|
24
24
|
|
|
25
|
-
- [
|
|
26
|
-
- [
|
|
27
|
-
- [
|
|
28
|
-
|
|
29
|
-
- [
|
|
30
|
-
- [
|
|
31
|
-
- [
|
|
32
|
-
- [
|
|
25
|
+
- [Maintenance](#maintenance)
|
|
26
|
+
- [Installation](#installation)
|
|
27
|
+
- [Appointment](#appointment)
|
|
28
|
+
- [Plotting](#plotting)
|
|
29
|
+
- [Parliament Plots](#parliament-plots)
|
|
30
|
+
- [Disproportionality Bar Plot](#disproportionality-bar-plot)
|
|
31
|
+
- [Examples](#examples)
|
|
32
|
+
- [Development environment](#development-environment)
|
|
33
|
+
- [To-Do](#to-do)
|
|
34
|
+
|
|
35
|
+
# Maintenance
|
|
36
|
+
|
|
37
|
+
`poli-sci-kit` is maintained at [codeberg.org/andrewtavis/poli-sci-kit](https://codeberg.org/andrewtavis/poli-sci-kit). Please visit this remote repository for issues and pull requests.
|
|
33
38
|
|
|
34
39
|
# Installation
|
|
35
40
|
|
|
@@ -48,7 +53,8 @@ pip install poli-sci-kit
|
|
|
48
53
|
### For Development Build
|
|
49
54
|
|
|
50
55
|
```bash
|
|
51
|
-
git clone https://
|
|
56
|
+
git clone https://codeberg.org/andrewtavis/poli-sci-kit.git
|
|
57
|
+
# git clone https://codeberg.org/<your-username>/poli-sci-kit.git
|
|
52
58
|
cd poli-sci-kit
|
|
53
59
|
|
|
54
60
|
# With uv (recommended):
|
|
@@ -71,13 +77,13 @@ import poli_sci_kit
|
|
|
71
77
|
|
|
72
78
|
# Appointment
|
|
73
79
|
|
|
74
|
-
[appointment.methods](https://
|
|
80
|
+
[appointment.methods](https://codeberg.org/andrewtavis/poli-sci-kit/src/branch/main/src/poli_sci_kit/appointment/methods.py) includes functions to allocate parliamentary seats based on population or vote shares. Included methods are:
|
|
75
81
|
|
|
76
82
|
#### Largest Remainder: Hare, Droop, Hagenbach–Bischoff (incl Hamilton, Vinton, Hare–Niemeyer)
|
|
77
83
|
|
|
78
84
|
#### Highest Averages: Jefferson, Webster, Huntington-Hill
|
|
79
85
|
|
|
80
|
-
Arguments to allow allocation thresholds, minimum allocations per group, tie break conditions, and other election features are also provided. Along with deriving results for visualization and reporting, these functions allow the user to analyze outcomes given systematic or situational changes. The [appointment.metrics](https://
|
|
86
|
+
Arguments to allow allocation thresholds, minimum allocations per group, tie break conditions, and other election features are also provided. Along with deriving results for visualization and reporting, these functions allow the user to analyze outcomes given systematic or situational changes. The [appointment.metrics](https://codeberg.org/andrewtavis/poli-sci-kit/src/branch/main/src/poli_sci_kit/appointment/metrics.py) module further provides diagnostics to analyze the results of elections, apportionments, and other political science scenarios.
|
|
81
87
|
|
|
82
88
|
A basic example of political appointment using poli-sci-kit is:
|
|
83
89
|
|
|
@@ -108,9 +114,7 @@ We can then compute various metrics to derive disproportionality:
|
|
|
108
114
|
```python
|
|
109
115
|
# The Gallagher method is a measure of absolute difference similar to summing square residuals.
|
|
110
116
|
disproportionality = appointment.metrics.disproportionality_index(
|
|
111
|
-
shares=vote_counts,
|
|
112
|
-
allocations=ha_allocations,
|
|
113
|
-
metric_type='Gallagher'
|
|
117
|
+
shares=vote_counts, allocations=ha_allocations, metric_type="Gallagher"
|
|
114
118
|
)
|
|
115
119
|
|
|
116
120
|
disproportionality
|
|
@@ -120,16 +124,13 @@ disproportionality
|
|
|
120
124
|
We can also check that the allocations pass the [quota condition](https://en.wikipedia.org/wiki/Quota_rule):
|
|
121
125
|
|
|
122
126
|
```python
|
|
123
|
-
passes_qc = appointment.checks.quota_condition(
|
|
124
|
-
shares=vote_counts,
|
|
125
|
-
seats=ha_allocations
|
|
126
|
-
)
|
|
127
|
+
passes_qc = appointment.checks.quota_condition(shares=vote_counts, seats=ha_allocations)
|
|
127
128
|
|
|
128
129
|
passes_qc
|
|
129
130
|
# True
|
|
130
131
|
```
|
|
131
132
|
|
|
132
|
-
Allocation consistency can further be checked using dataframes of shares and seats given electoral settings. See [appointment.checks](https://
|
|
133
|
+
Allocation consistency can further be checked using dataframes of shares and seats given electoral settings. See [appointment.checks](https://codeberg.org/andrewtavis/poli-sci-kit/src/branch/main/src/poli_sci_kit/appointment/checks.py) and [the documentation](https://poli-sci-kit.readthedocs.io/en/latest/) for explanations of method checks.
|
|
133
134
|
|
|
134
135
|
<sub><a href="#top">Back to top.</a></sub>
|
|
135
136
|
|
|
@@ -144,15 +145,15 @@ import matplotlib.pyplot as plt
|
|
|
144
145
|
import poli_sci_kit
|
|
145
146
|
|
|
146
147
|
# German political parties.
|
|
147
|
-
parties = [
|
|
148
|
-
party_colors = [
|
|
148
|
+
parties = ["CDU/CSU", "FDP", "Greens", "Die Linke", "SPD", "AfD"]
|
|
149
|
+
party_colors = ["#000000", "#ffed00", "#64a12d", "#be3075", "#eb001f", "#009ee0"]
|
|
149
150
|
```
|
|
150
151
|
|
|
151
152
|
<sub><a href="#top">Back to top.</a></sub>
|
|
152
153
|
|
|
153
154
|
### Parliament Plots
|
|
154
155
|
|
|
155
|
-
poli_sci_kit provides implementations of both rectangular and semicircle [parliament plots](https://
|
|
156
|
+
poli_sci_kit provides implementations of both rectangular and semicircle [parliament plots](https://codeberg.org/andrewtavis/poli-sci-kit/src/branch/main/src/poli_sci_kit/plot/parliament_plot.py):
|
|
156
157
|
|
|
157
158
|
```python
|
|
158
159
|
fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2)
|
|
@@ -183,15 +184,15 @@ plt.show()
|
|
|
183
184
|
```
|
|
184
185
|
|
|
185
186
|
<p align="middle">
|
|
186
|
-
<img src="https://
|
|
187
|
-
<img src="https://
|
|
187
|
+
<img src="https://codeberg.org/andrewtavis/poli-sci-kit/raw/branch/main/.forgejo/resources/images/rectangle_parliament_plot.png" width="400" />
|
|
188
|
+
<img src="https://codeberg.org/andrewtavis/poli-sci-kit/raw/branch/main/.forgejo/resources/images/semicircle_parliament_plot.png" width="400" />
|
|
188
189
|
</p>
|
|
189
190
|
|
|
190
191
|
<sub><a href="#top">Back to top.</a></sub>
|
|
191
192
|
|
|
192
193
|
### Disproportionality Bar Plot
|
|
193
194
|
|
|
194
|
-
A novel addition to social science analysis is the [disproportionality bar plot](https://
|
|
195
|
+
A novel addition to social science analysis is the [disproportionality bar plot](https://codeberg.org/andrewtavis/poli-sci-kit/src/branch/main/src/poli_sci_kit/plot/disproportionality_bar_plot.py), which graphically depicts the disproportionality between expected and realized results. Bar widths are the proportion of shares (ex: votes received), and heights are the difference or relative difference between shares and allocations (ex: parliament seats received).
|
|
195
196
|
|
|
196
197
|
An example follows:
|
|
197
198
|
|
|
@@ -233,15 +234,15 @@ ax.legend(
|
|
|
233
234
|
framealpha=1,
|
|
234
235
|
)
|
|
235
236
|
|
|
236
|
-
ax.axes.set_title(
|
|
237
|
-
ax.set_xlabel(
|
|
238
|
-
ax.set_ylabel(
|
|
237
|
+
ax.axes.set_title("Seat to Vote Share Disproportionality", fontsize=30)
|
|
238
|
+
ax.set_xlabel("Parties", fontsize=20)
|
|
239
|
+
ax.set_ylabel("Percent Shift", fontsize=20)
|
|
239
240
|
|
|
240
241
|
plt.show()
|
|
241
242
|
```
|
|
242
243
|
|
|
243
244
|
<p align="middle">
|
|
244
|
-
<img src="https://
|
|
245
|
+
<img src="https://codeberg.org/andrewtavis/poli-sci-kit/raw/branch/main/.forgejo/resources/images/disproportionality_bar_plot.png" width="600" />
|
|
245
246
|
</p>
|
|
246
247
|
|
|
247
248
|
<sub><a href="#top">Back to top.</a></sub>
|
|
@@ -250,10 +251,10 @@ plt.show()
|
|
|
250
251
|
|
|
251
252
|
Examples in poli-sci-kit use publicly available Wikidata statistics sourced via the Python package [wikirepo](https://github.com/andrewtavis/wikirepo). Current examples include:
|
|
252
253
|
|
|
253
|
-
- [US HoR](https://
|
|
254
|
+
- [US HoR](https://codeberg.org/andrewtavis/poli-sci-kit/src/branch/main/examples/us_house_of_rep.ipynb) [(Open in Colab)](https://colab.research.google.com/github/andrewtavis/poli-sci-kit/blob/main/examples/us_house_of_rep.ipynb)
|
|
254
255
|
- Allocates seats to a version of the US House of Representatives that includes all US territories and Washington DC given census data, with this further being used to derive relative vote strengths of state citizens in the US presidential election
|
|
255
256
|
|
|
256
|
-
- [Global Parliament](https://
|
|
257
|
+
- [Global Parliament](https://codeberg.org/andrewtavis/poli-sci-kit/src/branch/main/examples/global_parliament.ipynb) [(Open in Colab)](https://colab.research.google.com/github/andrewtavis/poli-sci-kit/blob/main/examples/global_parliament.ipynb)
|
|
257
258
|
- Analyzes the allocation of seats in a hypothetical global parliament given the prevalence of certain countries and organizations, the distribution of seats based on Freedom House indexes, as well as disproportionality metrics
|
|
258
259
|
|
|
259
260
|
<sub><a href="#top">Back to top.</a></sub>
|
|
@@ -266,11 +267,11 @@ Please follow the steps below to set up your development environment for poli-sc
|
|
|
266
267
|
|
|
267
268
|
```bash
|
|
268
269
|
# Clone your fork of the repo into the current directory.
|
|
269
|
-
git clone https://
|
|
270
|
+
git clone https://codeberg.org/<your-username>/poli-sci-kit.git
|
|
270
271
|
# Navigate to the newly cloned directory.
|
|
271
272
|
cd poli-sci-kit
|
|
272
273
|
# Assign the original repo to a remote called "upstream".
|
|
273
|
-
git remote add upstream https://
|
|
274
|
+
git remote add upstream https://codeberg.org/andrewtavis/poli-sci-kit.git
|
|
274
275
|
```
|
|
275
276
|
|
|
276
277
|
- Now, if you run `git remote -v` you should see two remote repositories named:
|
|
@@ -336,18 +337,18 @@ uv run prek run --all-files
|
|
|
336
337
|
|
|
337
338
|
# To-Do
|
|
338
339
|
|
|
339
|
-
Please see the [contribution guidelines](https://
|
|
340
|
+
Please see the [contribution guidelines](https://codeberg.org/andrewtavis/poli-sci-kit/src/branch/main/CONTRIBUTING.md) if you are interested in contributing to this project. Work that is in progress or could be implemented includes:
|
|
340
341
|
|
|
341
|
-
- Adding the [Adams method](https://en.wikipedia.org/wiki/Highest_averages_method) to [appointment.methods.highest_averages](https://
|
|
342
|
+
- Adding the [Adams method](https://en.wikipedia.org/wiki/Highest_averages_method) to [appointment.methods.highest_averages](https://codeberg.org/andrewtavis/poli-sci-kit/src/branch/main/src/poli_sci_kit/appointment/methods.py) ([see issue](https://codeberg.org/andrewtavis/poli-sci-kit/issues/21))
|
|
342
343
|
|
|
343
|
-
- Deriving further needed arguments to assure that all current and historic appointment systems can be simulated using poli-sci-kit ([see issue](https://
|
|
344
|
+
- Deriving further needed arguments to assure that all current and historic appointment systems can be simulated using poli-sci-kit ([see issue](https://codeberg.org/andrewtavis/poli-sci-kit/issues/22))
|
|
344
345
|
|
|
345
|
-
- Potentially indexing preset versions of [appointment.methods](https://
|
|
346
|
+
- Potentially indexing preset versions of [appointment.methods](https://codeberg.org/andrewtavis/poli-sci-kit/src/branch/main/src/poli_sci_kit/appointment/methods.py) that coincide with the systems used by governments around the world
|
|
346
347
|
- This would allow quick comparisons of actual systems with variations
|
|
347
348
|
|
|
348
349
|
- Adding methods such as quadratic voting to poli-sci-kit to allow for preference based simulations
|
|
349
350
|
|
|
350
|
-
- Creating, improving and sharing [examples](https://
|
|
351
|
+
- Creating, improving and sharing [examples](https://codeberg.org/andrewtavis/poli-sci-kit/tree/main/examples)
|
|
351
352
|
|
|
352
353
|
<sub><a href="#top">Back to top.</a></sub>
|
|
353
354
|
|
|
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
|
|
|
6
6
|
|
|
7
7
|
[project]
|
|
8
8
|
name = "poli-sci-kit"
|
|
9
|
-
version = "2.0.
|
|
9
|
+
version = "2.0.5"
|
|
10
10
|
description = "Political elections, appointment, analysis and visualization in Python"
|
|
11
11
|
readme = "README.md"
|
|
12
12
|
requires-python = ">=3.12"
|
|
@@ -44,32 +44,32 @@ classifiers = [
|
|
|
44
44
|
|
|
45
45
|
dependencies = [
|
|
46
46
|
"colormath>=3.0.0",
|
|
47
|
-
"matplotlib>=3.11.
|
|
48
|
-
"numpy>=2.5.
|
|
47
|
+
"matplotlib>=3.11.2",
|
|
48
|
+
"numpy>=2.5.3",
|
|
49
49
|
"packaging>=26.3",
|
|
50
|
-
"pandas>=3.0.
|
|
51
|
-
"scipy>=1.18.
|
|
50
|
+
"pandas>=3.0.6",
|
|
51
|
+
"scipy>=1.18.1",
|
|
52
52
|
"seaborn>=0.13.2",
|
|
53
53
|
]
|
|
54
54
|
|
|
55
55
|
[dependency-groups]
|
|
56
56
|
dev = [
|
|
57
|
-
"prek>=0.
|
|
57
|
+
"prek>=0.5.5",
|
|
58
58
|
"pytest>=9.1.1",
|
|
59
59
|
"pytest-cov>=7.1.0",
|
|
60
|
-
"ruff>=0.16.
|
|
61
|
-
"ty>=0.0.
|
|
60
|
+
"ruff>=0.16.10",
|
|
61
|
+
"ty>=0.0.84",
|
|
62
62
|
]
|
|
63
63
|
|
|
64
64
|
docs = [
|
|
65
65
|
# Keep docs dependencies formatted in this way with ruff to allow for upgrades via VS Code extension.
|
|
66
66
|
"myst-parser>=5.1.0",
|
|
67
|
-
"numpydoc>=1.
|
|
67
|
+
"numpydoc>=1.11.0",
|
|
68
68
|
"sphinx-rtd-theme>=3.1.0",
|
|
69
69
|
]
|
|
70
70
|
|
|
71
71
|
[project.urls]
|
|
72
|
-
Homepage = "https://
|
|
72
|
+
Homepage = "https://codeberg.org/andrewtavis/poli-sci-kit"
|
|
73
73
|
|
|
74
74
|
[tool.setuptools]
|
|
75
75
|
package-dir = { "" = "src" }
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: poli-sci-kit
|
|
3
|
-
Version: 2.0.
|
|
3
|
+
Version: 2.0.5
|
|
4
4
|
Summary: Political elections, appointment, analysis and visualization in Python
|
|
5
5
|
Author-email: Andrew Tavis McAllister <andrew.t.mcallister@gmail.com>
|
|
6
|
-
Project-URL: Homepage, https://
|
|
6
|
+
Project-URL: Homepage, https://codeberg.org/andrewtavis/poli-sci-kit
|
|
7
7
|
Keywords: politics,analysis,voting,democracy,political-science,elections,appointment,political-appointment-analysis,disproportionality
|
|
8
8
|
Classifier: Development Status :: 5 - Production/Stable
|
|
9
9
|
Classifier: Intended Audience :: Developers
|
|
@@ -21,30 +21,30 @@ Description-Content-Type: text/markdown
|
|
|
21
21
|
License-File: LICENSE.txt
|
|
22
22
|
License-File: NOTICE.txt
|
|
23
23
|
Requires-Dist: colormath>=3.0.0
|
|
24
|
-
Requires-Dist: matplotlib>=3.11.
|
|
25
|
-
Requires-Dist: numpy>=2.5.
|
|
24
|
+
Requires-Dist: matplotlib>=3.11.2
|
|
25
|
+
Requires-Dist: numpy>=2.5.3
|
|
26
26
|
Requires-Dist: packaging>=26.3
|
|
27
|
-
Requires-Dist: pandas>=3.0.
|
|
28
|
-
Requires-Dist: scipy>=1.18.
|
|
27
|
+
Requires-Dist: pandas>=3.0.6
|
|
28
|
+
Requires-Dist: scipy>=1.18.1
|
|
29
29
|
Requires-Dist: seaborn>=0.13.2
|
|
30
30
|
Dynamic: license-file
|
|
31
31
|
|
|
32
32
|
<a id="top"></a>
|
|
33
33
|
|
|
34
34
|
<div align="center">
|
|
35
|
-
<a href="https://
|
|
35
|
+
<a href="https://codeberg.org/andrewtavis/poli-sci-kit"><img src="https://codeberg.org/andrewtavis/poli-sci-kit/raw/branch/main/.forgejo/resources/logo/poli-sci-kit_logo_transparent.png" height=250></a>
|
|
36
36
|
</div>
|
|
37
37
|
|
|
38
38
|
<ol></ol>
|
|
39
39
|
|
|
40
40
|
[](http://poli-sci-kit.readthedocs.io/en/latest/)
|
|
41
|
-
[](https://codeberg.org/andrewtavis/poli-sci-kit/actions?workflow=ci_static_analysis.yaml)
|
|
42
|
+
[](https://codeberg.org/andrewtavis/poli-sci-kit/actions/?workflow=ci_pytest.yaml)
|
|
43
43
|
[](https://pypi.org/project/poli-sci-kit/)
|
|
44
44
|
[](https://pypi.org/project/poli-sci-kit/)
|
|
45
45
|
[](https://pypi.org/project/poli-sci-kit/)
|
|
46
|
-
[](https://
|
|
47
|
-
[](https://
|
|
46
|
+
[](https://codeberg.org/andrewtavis/poli-sci-kit/src/branch/main/LICENSE.txt)
|
|
47
|
+
[](https://codeberg.org/andrewtavis/poli-sci-kit/src/branch/main/.forgejo/CODE_OF_CONDUCT.md)
|
|
48
48
|
[](https://colab.research.google.com/github/andrewtavis/poli-sci-kit)
|
|
49
49
|
|
|
50
50
|
### Political elections, appointment, analysis and visualization in Python
|
|
@@ -53,14 +53,19 @@ Dynamic: license-file
|
|
|
53
53
|
|
|
54
54
|
# Contents
|
|
55
55
|
|
|
56
|
-
- [
|
|
57
|
-
- [
|
|
58
|
-
- [
|
|
59
|
-
|
|
60
|
-
- [
|
|
61
|
-
- [
|
|
62
|
-
- [
|
|
63
|
-
- [
|
|
56
|
+
- [Maintenance](#maintenance)
|
|
57
|
+
- [Installation](#installation)
|
|
58
|
+
- [Appointment](#appointment)
|
|
59
|
+
- [Plotting](#plotting)
|
|
60
|
+
- [Parliament Plots](#parliament-plots)
|
|
61
|
+
- [Disproportionality Bar Plot](#disproportionality-bar-plot)
|
|
62
|
+
- [Examples](#examples)
|
|
63
|
+
- [Development environment](#development-environment)
|
|
64
|
+
- [To-Do](#to-do)
|
|
65
|
+
|
|
66
|
+
# Maintenance
|
|
67
|
+
|
|
68
|
+
`poli-sci-kit` is maintained at [codeberg.org/andrewtavis/poli-sci-kit](https://codeberg.org/andrewtavis/poli-sci-kit). Please visit this remote repository for issues and pull requests.
|
|
64
69
|
|
|
65
70
|
# Installation
|
|
66
71
|
|
|
@@ -79,7 +84,8 @@ pip install poli-sci-kit
|
|
|
79
84
|
### For Development Build
|
|
80
85
|
|
|
81
86
|
```bash
|
|
82
|
-
git clone https://
|
|
87
|
+
git clone https://codeberg.org/andrewtavis/poli-sci-kit.git
|
|
88
|
+
# git clone https://codeberg.org/<your-username>/poli-sci-kit.git
|
|
83
89
|
cd poli-sci-kit
|
|
84
90
|
|
|
85
91
|
# With uv (recommended):
|
|
@@ -102,13 +108,13 @@ import poli_sci_kit
|
|
|
102
108
|
|
|
103
109
|
# Appointment
|
|
104
110
|
|
|
105
|
-
[appointment.methods](https://
|
|
111
|
+
[appointment.methods](https://codeberg.org/andrewtavis/poli-sci-kit/src/branch/main/src/poli_sci_kit/appointment/methods.py) includes functions to allocate parliamentary seats based on population or vote shares. Included methods are:
|
|
106
112
|
|
|
107
113
|
#### Largest Remainder: Hare, Droop, Hagenbach–Bischoff (incl Hamilton, Vinton, Hare–Niemeyer)
|
|
108
114
|
|
|
109
115
|
#### Highest Averages: Jefferson, Webster, Huntington-Hill
|
|
110
116
|
|
|
111
|
-
Arguments to allow allocation thresholds, minimum allocations per group, tie break conditions, and other election features are also provided. Along with deriving results for visualization and reporting, these functions allow the user to analyze outcomes given systematic or situational changes. The [appointment.metrics](https://
|
|
117
|
+
Arguments to allow allocation thresholds, minimum allocations per group, tie break conditions, and other election features are also provided. Along with deriving results for visualization and reporting, these functions allow the user to analyze outcomes given systematic or situational changes. The [appointment.metrics](https://codeberg.org/andrewtavis/poli-sci-kit/src/branch/main/src/poli_sci_kit/appointment/metrics.py) module further provides diagnostics to analyze the results of elections, apportionments, and other political science scenarios.
|
|
112
118
|
|
|
113
119
|
A basic example of political appointment using poli-sci-kit is:
|
|
114
120
|
|
|
@@ -139,9 +145,7 @@ We can then compute various metrics to derive disproportionality:
|
|
|
139
145
|
```python
|
|
140
146
|
# The Gallagher method is a measure of absolute difference similar to summing square residuals.
|
|
141
147
|
disproportionality = appointment.metrics.disproportionality_index(
|
|
142
|
-
shares=vote_counts,
|
|
143
|
-
allocations=ha_allocations,
|
|
144
|
-
metric_type='Gallagher'
|
|
148
|
+
shares=vote_counts, allocations=ha_allocations, metric_type="Gallagher"
|
|
145
149
|
)
|
|
146
150
|
|
|
147
151
|
disproportionality
|
|
@@ -151,16 +155,13 @@ disproportionality
|
|
|
151
155
|
We can also check that the allocations pass the [quota condition](https://en.wikipedia.org/wiki/Quota_rule):
|
|
152
156
|
|
|
153
157
|
```python
|
|
154
|
-
passes_qc = appointment.checks.quota_condition(
|
|
155
|
-
shares=vote_counts,
|
|
156
|
-
seats=ha_allocations
|
|
157
|
-
)
|
|
158
|
+
passes_qc = appointment.checks.quota_condition(shares=vote_counts, seats=ha_allocations)
|
|
158
159
|
|
|
159
160
|
passes_qc
|
|
160
161
|
# True
|
|
161
162
|
```
|
|
162
163
|
|
|
163
|
-
Allocation consistency can further be checked using dataframes of shares and seats given electoral settings. See [appointment.checks](https://
|
|
164
|
+
Allocation consistency can further be checked using dataframes of shares and seats given electoral settings. See [appointment.checks](https://codeberg.org/andrewtavis/poli-sci-kit/src/branch/main/src/poli_sci_kit/appointment/checks.py) and [the documentation](https://poli-sci-kit.readthedocs.io/en/latest/) for explanations of method checks.
|
|
164
165
|
|
|
165
166
|
<sub><a href="#top">Back to top.</a></sub>
|
|
166
167
|
|
|
@@ -175,15 +176,15 @@ import matplotlib.pyplot as plt
|
|
|
175
176
|
import poli_sci_kit
|
|
176
177
|
|
|
177
178
|
# German political parties.
|
|
178
|
-
parties = [
|
|
179
|
-
party_colors = [
|
|
179
|
+
parties = ["CDU/CSU", "FDP", "Greens", "Die Linke", "SPD", "AfD"]
|
|
180
|
+
party_colors = ["#000000", "#ffed00", "#64a12d", "#be3075", "#eb001f", "#009ee0"]
|
|
180
181
|
```
|
|
181
182
|
|
|
182
183
|
<sub><a href="#top">Back to top.</a></sub>
|
|
183
184
|
|
|
184
185
|
### Parliament Plots
|
|
185
186
|
|
|
186
|
-
poli_sci_kit provides implementations of both rectangular and semicircle [parliament plots](https://
|
|
187
|
+
poli_sci_kit provides implementations of both rectangular and semicircle [parliament plots](https://codeberg.org/andrewtavis/poli-sci-kit/src/branch/main/src/poli_sci_kit/plot/parliament_plot.py):
|
|
187
188
|
|
|
188
189
|
```python
|
|
189
190
|
fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2)
|
|
@@ -214,15 +215,15 @@ plt.show()
|
|
|
214
215
|
```
|
|
215
216
|
|
|
216
217
|
<p align="middle">
|
|
217
|
-
<img src="https://
|
|
218
|
-
<img src="https://
|
|
218
|
+
<img src="https://codeberg.org/andrewtavis/poli-sci-kit/raw/branch/main/.forgejo/resources/images/rectangle_parliament_plot.png" width="400" />
|
|
219
|
+
<img src="https://codeberg.org/andrewtavis/poli-sci-kit/raw/branch/main/.forgejo/resources/images/semicircle_parliament_plot.png" width="400" />
|
|
219
220
|
</p>
|
|
220
221
|
|
|
221
222
|
<sub><a href="#top">Back to top.</a></sub>
|
|
222
223
|
|
|
223
224
|
### Disproportionality Bar Plot
|
|
224
225
|
|
|
225
|
-
A novel addition to social science analysis is the [disproportionality bar plot](https://
|
|
226
|
+
A novel addition to social science analysis is the [disproportionality bar plot](https://codeberg.org/andrewtavis/poli-sci-kit/src/branch/main/src/poli_sci_kit/plot/disproportionality_bar_plot.py), which graphically depicts the disproportionality between expected and realized results. Bar widths are the proportion of shares (ex: votes received), and heights are the difference or relative difference between shares and allocations (ex: parliament seats received).
|
|
226
227
|
|
|
227
228
|
An example follows:
|
|
228
229
|
|
|
@@ -264,15 +265,15 @@ ax.legend(
|
|
|
264
265
|
framealpha=1,
|
|
265
266
|
)
|
|
266
267
|
|
|
267
|
-
ax.axes.set_title(
|
|
268
|
-
ax.set_xlabel(
|
|
269
|
-
ax.set_ylabel(
|
|
268
|
+
ax.axes.set_title("Seat to Vote Share Disproportionality", fontsize=30)
|
|
269
|
+
ax.set_xlabel("Parties", fontsize=20)
|
|
270
|
+
ax.set_ylabel("Percent Shift", fontsize=20)
|
|
270
271
|
|
|
271
272
|
plt.show()
|
|
272
273
|
```
|
|
273
274
|
|
|
274
275
|
<p align="middle">
|
|
275
|
-
<img src="https://
|
|
276
|
+
<img src="https://codeberg.org/andrewtavis/poli-sci-kit/raw/branch/main/.forgejo/resources/images/disproportionality_bar_plot.png" width="600" />
|
|
276
277
|
</p>
|
|
277
278
|
|
|
278
279
|
<sub><a href="#top">Back to top.</a></sub>
|
|
@@ -281,10 +282,10 @@ plt.show()
|
|
|
281
282
|
|
|
282
283
|
Examples in poli-sci-kit use publicly available Wikidata statistics sourced via the Python package [wikirepo](https://github.com/andrewtavis/wikirepo). Current examples include:
|
|
283
284
|
|
|
284
|
-
- [US HoR](https://
|
|
285
|
+
- [US HoR](https://codeberg.org/andrewtavis/poli-sci-kit/src/branch/main/examples/us_house_of_rep.ipynb) [(Open in Colab)](https://colab.research.google.com/github/andrewtavis/poli-sci-kit/blob/main/examples/us_house_of_rep.ipynb)
|
|
285
286
|
- Allocates seats to a version of the US House of Representatives that includes all US territories and Washington DC given census data, with this further being used to derive relative vote strengths of state citizens in the US presidential election
|
|
286
287
|
|
|
287
|
-
- [Global Parliament](https://
|
|
288
|
+
- [Global Parliament](https://codeberg.org/andrewtavis/poli-sci-kit/src/branch/main/examples/global_parliament.ipynb) [(Open in Colab)](https://colab.research.google.com/github/andrewtavis/poli-sci-kit/blob/main/examples/global_parliament.ipynb)
|
|
288
289
|
- Analyzes the allocation of seats in a hypothetical global parliament given the prevalence of certain countries and organizations, the distribution of seats based on Freedom House indexes, as well as disproportionality metrics
|
|
289
290
|
|
|
290
291
|
<sub><a href="#top">Back to top.</a></sub>
|
|
@@ -297,11 +298,11 @@ Please follow the steps below to set up your development environment for poli-sc
|
|
|
297
298
|
|
|
298
299
|
```bash
|
|
299
300
|
# Clone your fork of the repo into the current directory.
|
|
300
|
-
git clone https://
|
|
301
|
+
git clone https://codeberg.org/<your-username>/poli-sci-kit.git
|
|
301
302
|
# Navigate to the newly cloned directory.
|
|
302
303
|
cd poli-sci-kit
|
|
303
304
|
# Assign the original repo to a remote called "upstream".
|
|
304
|
-
git remote add upstream https://
|
|
305
|
+
git remote add upstream https://codeberg.org/andrewtavis/poli-sci-kit.git
|
|
305
306
|
```
|
|
306
307
|
|
|
307
308
|
- Now, if you run `git remote -v` you should see two remote repositories named:
|
|
@@ -367,18 +368,18 @@ uv run prek run --all-files
|
|
|
367
368
|
|
|
368
369
|
# To-Do
|
|
369
370
|
|
|
370
|
-
Please see the [contribution guidelines](https://
|
|
371
|
+
Please see the [contribution guidelines](https://codeberg.org/andrewtavis/poli-sci-kit/src/branch/main/CONTRIBUTING.md) if you are interested in contributing to this project. Work that is in progress or could be implemented includes:
|
|
371
372
|
|
|
372
|
-
- Adding the [Adams method](https://en.wikipedia.org/wiki/Highest_averages_method) to [appointment.methods.highest_averages](https://
|
|
373
|
+
- Adding the [Adams method](https://en.wikipedia.org/wiki/Highest_averages_method) to [appointment.methods.highest_averages](https://codeberg.org/andrewtavis/poli-sci-kit/src/branch/main/src/poli_sci_kit/appointment/methods.py) ([see issue](https://codeberg.org/andrewtavis/poli-sci-kit/issues/21))
|
|
373
374
|
|
|
374
|
-
- Deriving further needed arguments to assure that all current and historic appointment systems can be simulated using poli-sci-kit ([see issue](https://
|
|
375
|
+
- Deriving further needed arguments to assure that all current and historic appointment systems can be simulated using poli-sci-kit ([see issue](https://codeberg.org/andrewtavis/poli-sci-kit/issues/22))
|
|
375
376
|
|
|
376
|
-
- Potentially indexing preset versions of [appointment.methods](https://
|
|
377
|
+
- Potentially indexing preset versions of [appointment.methods](https://codeberg.org/andrewtavis/poli-sci-kit/src/branch/main/src/poli_sci_kit/appointment/methods.py) that coincide with the systems used by governments around the world
|
|
377
378
|
- This would allow quick comparisons of actual systems with variations
|
|
378
379
|
|
|
379
380
|
- Adding methods such as quadratic voting to poli-sci-kit to allow for preference based simulations
|
|
380
381
|
|
|
381
|
-
- Creating, improving and sharing [examples](https://
|
|
382
|
+
- Creating, improving and sharing [examples](https://codeberg.org/andrewtavis/poli-sci-kit/tree/main/examples)
|
|
382
383
|
|
|
383
384
|
<sub><a href="#top">Back to top.</a></sub>
|
|
384
385
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{poli_sci_kit-2.0.3 → poli_sci_kit-2.0.5}/src/poli_sci_kit/plot/disproportionality_bar_plot.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|