{"id":22115302,"url":"https://github.com/nolanbconaway/binoculars","last_synced_at":"2025-08-25T00:31:48.908Z","repository":{"id":48950621,"uuid":"323719257","full_name":"nolanbconaway/binoculars","owner":"nolanbconaway","description":"Confidence intervals for binomial proportions.","archived":false,"fork":false,"pushed_at":"2021-10-08T00:16:55.000Z","size":84,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-12-15T03:24:04.051Z","etag":null,"topics":["binomial-distribution","confidence-intervals","python","statistics"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nolanbconaway.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}},"created_at":"2020-12-22T19:50:01.000Z","updated_at":"2024-05-27T08:35:49.000Z","dependencies_parsed_at":"2022-08-30T10:30:20.740Z","dependency_job_id":null,"html_url":"https://github.com/nolanbconaway/binoculars","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nolanbconaway%2Fbinoculars","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nolanbconaway%2Fbinoculars/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nolanbconaway%2Fbinoculars/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nolanbconaway%2Fbinoculars/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nolanbconaway","download_url":"https://codeload.github.com/nolanbconaway/binoculars/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230852591,"owners_count":18290081,"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":["binomial-distribution","confidence-intervals","python","statistics"],"created_at":"2024-12-01T12:15:20.174Z","updated_at":"2024-12-22T15:48:51.334Z","avatar_url":"https://github.com/nolanbconaway.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Binoculars: Binomial Confidence Intervals\n\n![https://deepnote.com/project/e17fa473-51c6-45aa-8de0-980be7d2dc5f](demo.png)\n\n![Unit Tests](https://github.com/nolanbconaway/binoculars/workflows/Unit%20Tests/badge.svg)\n[![codecov](https://codecov.io/gh/nolanbconaway/binoculars/branch/main/graph/badge.svg?token=EOH4M3PIYL)](https://codecov.io/gh/nolanbconaway/binoculars)\n[![PyPI](https://img.shields.io/pypi/v/binoculars)](https://pypi.org/project/binoculars/)\n\n\nThis is a small package that provides functions to compute the confidence interval for a binomial proportion. I made it because I spend altogether too much time staring at the Binomial proportion confidence interval [wiki page](https://en.wikipedia.org/wiki/Binomial_proportion_confidence_interval).\n\nPresently, the package implements:\n\n- [The Normal Approximation](https://en.wikipedia.org/wiki/Binomial_proportion_confidence_interval#Normal_approximation_interval)\n- [The Wilson Interval](https://en.wikipedia.org/wiki/Binomial_proportion_confidence_interval#Wilson_score_interval) (no continuity correction)\n- [Jeffrey's interval](https://en.wikipedia.org/wiki/Binomial_proportion_confidence_interval#Jeffreys_interval) (via scipy.stats.beta)\n- [Clopper-Pearson interval](https://en.wikipedia.org/wiki/Binomial_proportion_confidence_interval#Clopper%E2%80%93Pearson_interval) (also via scipy.stats.beta)\n\nIf you haven't spent a lot of time thinking about which interval _you_ should use (and why would you want to?), I suggest using the Wilson interval or Jeffrey's interval. Jeffrey's interval is returned by default by the `binomial_confidence` function in this package. \n\n\u003e You _oughtn't_ use the normal approximation if you don't have to. It produces patently inaccurate values with low/high probabilities at low Ns. The plot at the top of this readme shows the normal approximation producing lower lower bounds of _less than 0_ in these cases.\n\n## Install\n\n```sh\npip install binoculars\n```\n\n## Usage\n\n```py\nfrom binoculars import binomial_confidence\n\nN, p = 100, 0.2\n\nbinomial_confidence(p, N)  # default to jeffrey's interval\n# (0.1307892803998113, 0.28628125447599173)\n\nbinomial_confidence(p, N, tail='lower') # grab one tail\n# 0.1307892803998113\n\n# set Z value\nbinomial_confidence(p, N, tail='lower', z=2.58)\n# 0.11212431621448567\n\n# choose your method\n\nbinomial_confidence(p, N, method='normal')\n# (0.12160000000000001, 0.2784)\n\nbinomial_confidence(p, N, method='wilson')\n# (0.1333659225590988, 0.28883096192650237)\n\nbinomial_confidence(p, N, method='clopper-pearson')\n# (0.1266544343411484, 0.291844378634278\n```\n\n## Development\n\nI honestly do not imagine touching this a lot. But maybe you want to add one of the other interval methods?\n\n1. Make a python 3.6+ venv\n3. `pip install -e .[test]`\n4. `black lib --check`\n5. `pytest`\n\n## Later (?)\n\n - [ ] Add confidence intervals for odds ratios, differences\n - [ ] Add the unimplemented intervals\n - [x] Add plots comparing the intervals to readme.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnolanbconaway%2Fbinoculars","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnolanbconaway%2Fbinoculars","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnolanbconaway%2Fbinoculars/lists"}