{"id":21236675,"url":"https://github.com/maxg87/clear-or-close","last_synced_at":"2025-07-12T07:33:13.054Z","repository":{"id":130666916,"uuid":"210616210","full_name":"MaxG87/clear-or-close","owner":"MaxG87","description":"Decide if an election was close in a statistical sense","archived":false,"fork":false,"pushed_at":"2023-06-26T10:00:41.000Z","size":38,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-15T03:14:02.823Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","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/MaxG87.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2019-09-24T13:56:46.000Z","updated_at":"2022-12-09T20:58:11.000Z","dependencies_parsed_at":"2023-07-06T20:45:49.137Z","dependency_job_id":null,"html_url":"https://github.com/MaxG87/clear-or-close","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/MaxG87/clear-or-close","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaxG87%2Fclear-or-close","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaxG87%2Fclear-or-close/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaxG87%2Fclear-or-close/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaxG87%2Fclear-or-close/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MaxG87","download_url":"https://codeload.github.com/MaxG87/clear-or-close/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaxG87%2Fclear-or-close/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264958135,"owners_count":23689006,"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":[],"created_at":"2024-11-21T00:13:18.560Z","updated_at":"2025-07-12T07:33:13.035Z","avatar_url":"https://github.com/MaxG87.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# clear-or-close\n\nThis project allows you to check whether an referendum was close in a\nstatistical sense. Currently it only supports referendums with exactly two\nchoices.\n\nThe project was born when media coverage claimed that the Brexit referendum was\n\"close\". Since I was preparing a course about statistical testing I took the\nchance to present a Monte Carlo test with recent relevance.\n\n## Statistical Model\n\nThe performed statistical test is based on MonteCarlo testing. Here, $N$\nsamples of a suitable model are drawn and checked wheter they are at least as\nextreme than the referendum in question.\n\nLet $N$ be the number of entitled voters, $0 \u003c M \u003c= N$ be the number of actual\nvoters and blue and red the options to vote for.\n\nThe statistical model is as follows. It assumes that every voter is decided on\nexactly one of the options. Who actually attends the referendum is up to\nchance. However, there is no correlation between the choice of a voter and\nwhether she will attend the referendum.\n\nThus, the outcome of the referendum, according to the statistical model\nsketched above, can be modelled by drawing $M$ balls from an urn with\n$\\frac 12 N$ red and $\\frac 12 N$ blue balls. This is a special case of the\n[Hypergeometric Distribution](https://en.wikipedia.org/wiki/Hypergeometric_distribution).\n\nA sampled result is considered to be _at least as extreme_ than the result that\nis tested for significance if one option got at least as many votes than the\noption with a majority share of votes. Thus, when the actual poll resulted in\n$(13, 37)$ and the sampling resulted in $(37, 13)$, the sampled result is\nconsidered to be at least as extreme.\n\n\n## Sampling from the Statistical Model\n\nThe implementation to sample the Hypergeometric Distribution closely mimicks\ndrawing balls from an urn. It maintains a vector `counts` which tells how many\nexamples for each option remain and samples options with probability\nproportional to these counts. The sampling repeats this process until $M$\nelements were drawn.\n\nThe runtime is prohibitive for large values of $M$.\n\n## Todo:\n\n* Find clever approximations so sampling gets faster. An $O(k)$ way to sample\n  from a k-dimensional Hypergeometric dimension would be awesome.\n  HINT: https://wikis.hu-berlin.de/mmstat/Approximation_von_Verteilungen#Approximation_durch_die_Normalverteilung_2\n\n* Write tests!\n\n* Add command line parser so no recompilation is required for different values.\n\n* Add support for general elections. Needs a better $H_0$ and a better measure\n  of _extremness_, though.\n\n* Generate confidence intervals to indicate how reliable the results are.\n\n\n## Result\n\nUsually election results are significant according to the statistical model\ndescribed above. Even for 2500 eligible voters the Brexit result would be\nsignificant.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxg87%2Fclear-or-close","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaxg87%2Fclear-or-close","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxg87%2Fclear-or-close/lists"}