{"id":23373055,"url":"https://github.com/polettif/proporz","last_synced_at":"2025-04-10T17:53:54.701Z","repository":{"id":177807777,"uuid":"256542398","full_name":"polettif/proporz","owner":"polettif","description":"Calculate seat apportionment for legislative bodies using different established methods, including biproportional apportionment.","archived":false,"fork":false,"pushed_at":"2024-04-04T10:58:32.000Z","size":1222,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-09-16T14:18:39.324Z","etag":null,"topics":["apportionment","apportionment-methods","biproportional","election-analysis"],"latest_commit_sha":null,"homepage":"https://polettif.github.io/proporz/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/polettif.png","metadata":{"files":{"readme":"README.md","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-17T15:35:24.000Z","updated_at":"2024-03-01T14:37:21.000Z","dependencies_parsed_at":"2023-12-11T09:31:08.417Z","dependency_job_id":"d75aebb8-6214-470e-8153-ada9f7e7111f","html_url":"https://github.com/polettif/proporz","commit_stats":null,"previous_names":["polettif/proporz"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polettif%2Fproporz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polettif%2Fproporz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polettif%2Fproporz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polettif%2Fproporz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/polettif","download_url":"https://codeload.github.com/polettif/proporz/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248262434,"owners_count":21074308,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["apportionment","apportionment-methods","biproportional","election-analysis"],"created_at":"2024-12-21T16:52:35.421Z","updated_at":"2025-04-10T17:53:54.696Z","avatar_url":"https://github.com/polettif.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"# proporz \u003cimg src=\"man/figures/logo.png\" align=\"right\" height=\"138\" alt = \"proporz logo\"/\u003e\n\nCalculate seat apportionment for legislative bodies with various methods. These\nmethods include divisor methods (e.g. D'Hondt, Webster or Adams), largest \nremainder methods and biproportional apportionment.\n\n_Mit diesem R-Package können mittels verschiedener Sitzzuteilungsverfahren \nWählerstimmen in Abgeordnetensitze umgerechnet werden. Das Package beinhaltet \nQuoten-, Divisor- und biproportionale Verfahren (Doppelproporz oder \n\"Doppelter Pukelsheim\")._\n\n## Installation\nInstall the package from CRAN:\n\n```r\ninstall.packages(\"proporz\")\n```\n\nAlternatively, install the development version from Github:\n\n```r\n# install.packages(\"remotes\")\nremotes::install_github(\"polettif/proporz\")\n```\n\n## Apportionment methods overview\n\n### Proportional Apportionment\n\n[`proporz()`](https://polettif.github.io/proporz/reference/proporz.html) distributes \nseats proportionally for a vector of votes according to the following methods:\n\n- **Divisor methods** ([Wikipedia](https://en.wikipedia.org/wiki/Highest_averages_method))\n    - D'Hondt, Jefferson, Hagenbach-Bischoff\n    - Sainte-Laguë, Webster\n    - Adams\n    - Dean\n    - Huntington-Hill\n- **Largest remainder method** ([Wikipedia](https://en.wikipedia.org/wiki/Largest_remainder_method))\n    - Hare-Niemeyer, Hamilton, Vinton\n\n``` r\nlibrary(proporz)\nvotes = c(\"Party A\" = 651, \"Party B\" = 349, \"Party C\" = 50)\n\nproporz(votes, n_seats = 10, method = \"sainte-lague\")\n#\u003e Party A Party B Party C \n#\u003e       7       3       0\n\nproporz(votes, 10, \"huntington-hill\", quorum = 0.05)\n#\u003e Party A Party B Party C \n#\u003e       6       4       0\n```\n\n### Biproportional Apportionment\n\nBiproportional apportionment ([Wikipedia](https://en.wikipedia.org/wiki/Biproportional_apportionment)) \nis a method to proportionally allocate seats among parties and districts.\n\nWe can use the provided [`uri2020`](https://polettif.github.io/proporz/reference/uri2020.html) \ndata set to illustrate biproportional apportionment with [`biproporz()`](https://polettif.github.io/proporz/reference/biproporz.html).\nYou need a 'votes matrix' as input which shows the number of votes for each party\n(rows) and district (columns). You also need to define the number of seats per district.\n\n``` r\n(votes_matrix \u003c- uri2020$votes_matrix)\n#\u003e      Altdorf Bürglen Erstfeld Schattdorf\n#\u003e CVP    11471    2822     2309       4794\n#\u003e SPGB   11908    1606     1705       2600\n#\u003e FDP     9213    1567      946       2961\n#\u003e SVP     7756    2945     1573       3498\n\n(district_seats \u003c- uri2020$seats_vector)\n#\u003e    Altdorf    Bürglen   Erstfeld Schattdorf \n#\u003e         15          7          6          9\n\nbiproporz(votes_matrix, district_seats)\n#\u003e      Altdorf Bürglen Erstfeld Schattdorf\n#\u003e CVP        5       2        2          3\n#\u003e SPGB       4       1        2          2\n#\u003e FDP        3       1        1          2\n#\u003e SVP        3       3        1          2\n```\n\nYou can use [`pukelsheim()`](https://polettif.github.io/proporz/reference/pukelsheim.html) \nfor dataframes in long format as input data. It is a wrapper for `biproporz()`. [`zug2018`](https://polettif.github.io/proporz/reference/zug2018.html) shows an actual election \nresult for the Canton of Zug in a dataframe. We use this data set to create input data for \n`pukelsheim()`. The other parameters are set to reflect the actual election system.\n\n``` r\n# In this data set, parties are called 'lists' and districts 'entities'.\nvotes_df = unique(zug2018[c(\"list_id\", \"entity_id\", \"list_votes\")])\ndistrict_seats_df = unique(zug2018[c(\"entity_id\", \"election_mandates\")])\n\nseats_df = pukelsheim(votes_df,\n                      district_seats_df,\n                      quorum = quorum_any(any_district = 0.05, total = 0.03),\n                      winner_take_one = TRUE)\n\nhead(seats_df)\n#\u003e   list_id entity_id list_votes seats\n#\u003e 1       2      1701       8108     2\n#\u003e 2       1      1701       2993     0\n#\u003e 3       3      1701      19389     3\n#\u003e 4       4      1701      14814     2\n#\u003e 5       5      1701       4486     1\n#\u003e 6       6      1701      15695     3\n```\n\nThe [**Apportionment scenarios vignette**](https://polettif.github.io/proporz/articles/apportionment_scenarios.html) \ncontains more examples. \nHow to adapt `biproporz` for special use cases is demonstrated in the [**Modifying biproporz() vignette**](https://polettif.github.io/proporz/articles/modifying_biproporz.html).\n\n## Shiny app\n\nThe package provides a basic Shiny app where you can calculate biproportional\napportionment on an interactive dashboard. You need to have the packages `shiny` \nand `shinyMatrix` installed. [Try it out on shinyapps.io](https://polettif.shinyapps.io/proporz/)\n\n```r\n# install.packages(\"shiny\")\n# install.packages(\"shinyMatrix\")\nproporz::run_app()\n```\n\u003cimg src=\"man/figures/shinyapp-example.gif\" style = \"width:70%;\" alt = \"shiny app gif\"\u003e\n\n\n## Function details\n\n[**Full function reference**](https://polettif.github.io/proporz/reference/index.html)\n\n#### Divisor methods\n\nYou can use divisor methods directly:\n\n``` r\nvotes = c(\"Party A\" = 690, \"Party B\" = 370, \"Party C\" = 210, \"Party D\" = 10)\n\n# D'Hondt, Jefferson or Hagenbach-Bischoff method\ndivisor_floor(votes, 10)\n#\u003e Party A Party B Party C Party D \n#\u003e       6       3       1       0\n\n# Sainte-Laguë or Webster method\ndivisor_round(votes, 10)\n#\u003e Party A Party B Party C Party D \n#\u003e       5       3       2       0\n\n# Adams method\ndivisor_ceiling(votes, 10)\n#\u003e Party A Party B Party C Party D \n#\u003e       4       3       2       1\n\n# Dean method\ndivisor_harmonic(votes, 10)\n#\u003e Party A Party B Party C Party D \n#\u003e       5       2       2       1\n\n# Huntington-Hill method\ndivisor_geometric(votes, 10)\n#\u003e Party A Party B Party C Party D \n#\u003e       5       3       1       1\n```\n\n#### Largest remainder method\n\nThe largest remainder method is also accessible directly:\n\n``` r\nvotes = c(\"I\" = 16200, \"II\" = 47000, \"III\" = 12700)\n\n# Hamilton, Hare-Niemeyer or Vinton method\nlargest_remainder_method(votes, 20)\n#\u003e   I  II III \n#\u003e   4  13   3\n```\n\n## See also\nThere are other R packages available that provide apportionment functions, some with\nmore focus on analysis. However, biproportional apportionment is missing from the \npure R packages and RBazi needs rJava with an accompanying jar.\n\n- [RBazi](https://www.math.uni-augsburg.de/htdocs/emeriti/pukelsheim/bazi/RBazi.html): Package using rJava to access the functions of [BAZI](https://www.math.uni-augsburg.de/htdocs/emeriti/pukelsheim/bazi/welcome.html).\n- [seatdist](https://github.com/jmedzihorsky/seatdist): Package for seat apportionment and disproportionality measurement.\n- [disprr](https://github.com/pierzgal/disprr): Simulate election results and examine disproportionality of apportionment methods.\n- [apportR](https://github.com/jalapic/apportR): Package containing various apportionment methods, with particular relevance for the problem of apportioning seats in the House of Representatives.\n- [apportion](https://github.com/christopherkenny/apportion): Convert populations into integer number of seats for legislative bodies, focusing on the United States.\n\n### Contributing\n\nPlease feel free to issue a pull request or [open an issue](https://github.com/polettif/proporz/issues/new).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolettif%2Fproporz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpolettif%2Fproporz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolettif%2Fproporz/lists"}