proporz
Calculate seat apportionment for legislative bodies using different established methods, including biproportional apportionment.
Science Score: 13.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
-
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (13.9%) to scientific vocabulary
Keywords
Repository
Calculate seat apportionment for legislative bodies using different established methods, including biproportional apportionment.
Basic Info
- Host: GitHub
- Owner: polettif
- License: gpl-3.0
- Language: R
- Default Branch: master
- Homepage: https://polettif.github.io/proporz/
- Size: 5.05 MB
Statistics
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
- Releases: 6
Topics
Metadata Files
README.md
proporz 
Calculate seat apportionment for legislative bodies with various methods. These methods include divisor methods (e.g. D'Hondt, Webster or Adams), largest remainder methods and biproportional apportionment.
Mit diesem R-Package können mittels verschiedener Sitzzuteilungsverfahren Wählerstimmen in Abgeordnetensitze umgerechnet werden. Das Package beinhaltet Quoten-, Divisor- und biproportionale Verfahren (Doppelproporz oder "Doppelter Pukelsheim").
Installation
Install the package from CRAN:
r
install.packages("proporz")
Alternatively, install the development version from Github:
```r
install.packages("remotes")
remotes::install_github("polettif/proporz") ```
Apportionment methods overview
Proportional Apportionment
proporz() distributes
seats proportionally for a vector of votes according to the following methods:
- Divisor methods (Wikipedia)
- D'Hondt, Jefferson, Hagenbach-Bischoff
- Sainte-Laguë, Webster
- Adams
- Dean
- Huntington-Hill
- Largest remainder method (Wikipedia)
- Hare-Niemeyer, Hamilton, Vinton
``` r library(proporz) votes = c("Party A" = 651, "Party B" = 349, "Party C" = 50)
proporz(votes, n_seats = 10, method = "sainte-lague")
> Party A Party B Party C
> 7 3 0
proporz(votes, 10, "huntington-hill", quorum = 0.05)
> Party A Party B Party C
> 6 4 0
```
Biproportional Apportionment
Biproportional apportionment (Wikipedia)
is a method to proportionally allocate seats among parties and districts.
The method is implemented in biproporz().
We can use the provided uri2020
data set to illustrate biproportional apportionment with biproporz().
You need a 'votes matrix' as input which shows the number of votes for each party
(rows) and district (columns). You also need to define the number of seats per district.
``` r (votesmatrix <- uri2020$votesmatrix)
> Altdorf Bürglen Erstfeld Schattdorf
> CVP 11471 2822 2309 4794
> SPGB 11908 1606 1705 2600
> FDP 9213 1567 946 2961
> SVP 7756 2945 1573 3498
(districtseats <- uri2020$seatsvector)
> Altdorf Bürglen Erstfeld Schattdorf
> 15 7 6 9
biproporz(votesmatrix, districtseats)
> Altdorf Bürglen Erstfeld Schattdorf
> CVP 5 2 2 3
> SPGB 4 1 2 2
> FDP 3 1 1 2
> SVP 3 3 1 2
```
You can use pukelsheim()
for dataframes in long format as input data. It is a wrapper for biproporz(). zug2018 shows an actual election
result for the Canton of Zug in a dataframe. We use this data set to create input data for
pukelsheim(). The other parameters are set to reflect the actual election system.
``` r
In this data set, parties are called 'lists' and districts 'entities'.
votesdf = unique(zug2018[c("listid", "entityid", "listvotes")]) districtseatsdf = unique(zug2018[c("entityid", "electionmandates")])
seatsdf = pukelsheim(votesdf, districtseatsdf, quorum = quorumany(anydistrict = 0.05, total = 0.03), winnertakeone = TRUE)
head(seats_df)
> listid entityid list_votes seats
> 1 2 1701 8108 2
> 2 1 1701 2993 0
> 3 3 1701 19389 3
> 4 4 1701 14814 2
> 5 5 1701 4486 1
> 6 6 1701 15695 3
```
The Apportionment scenarios vignette
contains more examples.
How to adapt biproporz for special use cases is demonstrated in the Modifying biproporz() vignette.
Shiny app
The package provides a basic Shiny app where you can calculate biproportional
apportionment on an interactive dashboard. You need to have the packages shiny
and shinyMatrix installed.
```r
install.packages("shiny")
install.packages("shinyMatrix")
proporz::run_app()
```

Function details
Divisor methods
You can use divisor methods directly:
``` r votes = c("Party A" = 690, "Party B" = 370, "Party C" = 210, "Party D" = 10)
D'Hondt, Jefferson or Hagenbach-Bischoff method
divisor_floor(votes, 10)
> Party A Party B Party C Party D
> 6 3 1 0
Sainte-Laguë or Webster method
divisor_round(votes, 10)
> Party A Party B Party C Party D
> 5 3 2 0
Adams method
divisor_ceiling(votes, 10)
> Party A Party B Party C Party D
> 4 3 2 1
Dean method
divisor_harmonic(votes, 10)
> Party A Party B Party C Party D
> 5 2 2 1
Huntington-Hill method
divisor_geometric(votes, 10)
> Party A Party B Party C Party D
> 5 3 1 1
```
Largest remainder method
The largest remainder method is also accessible directly:
``` r votes = c("I" = 16200, "II" = 47000, "III" = 12700)
Hamilton, Hare-Niemeyer or Vinton method
largestremaindermethod(votes, 20)
> I II III
> 4 13 3
```
See also
There are other R packages available that provide apportionment functions, some with more focus on analysis. However, biproportional apportionment is missing from the pure R packages and RBazi needs rJava with an accompanying jar.
- RBazi: Package using rJava to access the functions of BAZI.
- seatdist: Package for seat apportionment and disproportionality measurement.
- disprr: Simulate election results and examine disproportionality of apportionment methods.
- apportR: Package containing various apportionment methods, with particular relevance for the problem of apportioning seats in the House of Representatives.
- apportion: Convert populations into integer number of seats for legislative bodies, focusing on the United States.
Contributing
Please feel free to issue a pull request or open an issue.
Owner
- Name: Flavio Poletti
- Login: polettif
- Kind: user
- Company: TEAMverkehr.zug
- Repositories: 15
- Profile: https://github.com/polettif
GitHub Events
Total
- Create event: 11
- Release event: 1
- Issues event: 3
- Delete event: 9
- Issue comment event: 4
- Push event: 53
- Pull request event: 4
Last Year
- Create event: 11
- Release event: 1
- Issues event: 3
- Delete event: 9
- Issue comment event: 4
- Push event: 53
- Pull request event: 4
Issues and Pull Requests
Last synced: 9 months ago
All Time
- Total issues: 9
- Total pull requests: 10
- Average time to close issues: about 1 month
- Average time to close pull requests: about 8 hours
- Total issue authors: 4
- Total pull request authors: 1
- Average comments per issue: 0.89
- Average comments per pull request: 0.1
- Merged pull requests: 8
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 2
- Pull requests: 6
- Average time to close issues: N/A
- Average time to close pull requests: about 8 hours
- Issue authors: 2
- Pull request authors: 1
- Average comments per issue: 0.0
- Average comments per pull request: 0.17
- Merged pull requests: 4
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- polettif (6)
- martial00120 (1)
- NickGlaettli (1)
- rauhanisti (1)
Pull Request Authors
- polettif (12)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- cran 193 last-month
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 3
- Total maintainers: 1
cran.r-project.org: proporz
Proportional Apportionment
- Homepage: https://polettif.github.io/proporz/
- Documentation: http://cran.r-project.org/web/packages/proporz/proporz.pdf
- License: GPL (≥ 3)
-
Latest release: 1.5.1
published about 1 year ago
Rankings
Maintainers (1)
Dependencies
- actions/checkout v2 composite
- r-lib/actions/check-r-package v2 composite
- r-lib/actions/setup-pandoc v2 composite
- r-lib/actions/setup-r v2 composite
- r-lib/actions/setup-r-dependencies v2 composite
- actions/cache v2 composite
- actions/checkout v2 composite
- r-lib/actions/setup-pandoc v2 composite
- r-lib/actions/setup-r v2 composite
- R >= 3.6.0 depends
- shiny * suggests
- shinyMatrix * suggests
- testthat * suggests