bayesplain 0.0.0__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.
Files changed (70) hide show
  1. bayesplain-0.0.0/.github/workflows/build_docs.yml +106 -0
  2. bayesplain-0.0.0/.github/workflows/unittests.yml +80 -0
  3. bayesplain-0.0.0/.github/workflows/upload_package.yml +52 -0
  4. bayesplain-0.0.0/.gitignore +127 -0
  5. bayesplain-0.0.0/LICENSE.txt +29 -0
  6. bayesplain-0.0.0/PKG-INFO +310 -0
  7. bayesplain-0.0.0/README.md +266 -0
  8. bayesplain-0.0.0/bayesplain/__init__.py +97 -0
  9. bayesplain-0.0.0/bayesplain/_config.py +105 -0
  10. bayesplain-0.0.0/bayesplain/_contingency.py +286 -0
  11. bayesplain-0.0.0/bayesplain/_correlation.py +191 -0
  12. bayesplain-0.0.0/bayesplain/_groups.py +483 -0
  13. bayesplain-0.0.0/bayesplain/_means.py +282 -0
  14. bayesplain-0.0.0/bayesplain/_proportions.py +334 -0
  15. bayesplain-0.0.0/bayesplain/core/__init__.py +49 -0
  16. bayesplain-0.0.0/bayesplain/core/beta_binomial.py +264 -0
  17. bayesplain-0.0.0/bayesplain/core/correlation.py +303 -0
  18. bayesplain-0.0.0/bayesplain/core/dirichlet_multinomial.py +532 -0
  19. bayesplain-0.0.0/bayesplain/core/grid.py +159 -0
  20. bayesplain-0.0.0/bayesplain/core/hierarchical.py +123 -0
  21. bayesplain-0.0.0/bayesplain/core/intervals.py +220 -0
  22. bayesplain-0.0.0/bayesplain/core/normal_t.py +317 -0
  23. bayesplain-0.0.0/bayesplain/data/collisions.csv.gz +0 -0
  24. bayesplain-0.0.0/bayesplain/data/la_blockgroups.csv.gz +0 -0
  25. bayesplain-0.0.0/bayesplain/data/la_tracts.csv.gz +0 -0
  26. bayesplain-0.0.0/bayesplain/data/parcels.csv.gz +0 -0
  27. bayesplain-0.0.0/bayesplain/datasets.py +342 -0
  28. bayesplain-0.0.0/bayesplain/frequentist.py +510 -0
  29. bayesplain-0.0.0/bayesplain/priors.py +669 -0
  30. bayesplain-0.0.0/bayesplain/result.py +1243 -0
  31. bayesplain-0.0.0/bayesplain/teach.py +1100 -0
  32. bayesplain-0.0.0/bayesplain/tests/__init__.py +1 -0
  33. bayesplain-0.0.0/bayesplain/tests/test_beta_binomial.py +140 -0
  34. bayesplain-0.0.0/bayesplain/tests/test_contingency.py +185 -0
  35. bayesplain-0.0.0/bayesplain/tests/test_correlation.py +210 -0
  36. bayesplain-0.0.0/bayesplain/tests/test_dirichlet_multinomial.py +363 -0
  37. bayesplain-0.0.0/bayesplain/tests/test_groups.py +240 -0
  38. bayesplain-0.0.0/bayesplain/tests/test_means.py +249 -0
  39. bayesplain-0.0.0/bayesplain/tests/test_proportions.py +200 -0
  40. bayesplain-0.0.0/bayesplain/tests/test_result.py +293 -0
  41. bayesplain-0.0.0/bayesplain/tests/test_teach.py +355 -0
  42. bayesplain-0.0.0/bayesplain.egg-info/PKG-INFO +310 -0
  43. bayesplain-0.0.0/bayesplain.egg-info/SOURCES.txt +68 -0
  44. bayesplain-0.0.0/bayesplain.egg-info/dependency_links.txt +1 -0
  45. bayesplain-0.0.0/bayesplain.egg-info/requires.txt +30 -0
  46. bayesplain-0.0.0/bayesplain.egg-info/scm_file_list.json +65 -0
  47. bayesplain-0.0.0/bayesplain.egg-info/scm_version.json +8 -0
  48. bayesplain-0.0.0/bayesplain.egg-info/top_level.txt +1 -0
  49. bayesplain-0.0.0/ci/312.yml +23 -0
  50. bayesplain-0.0.0/ci/313.yml +23 -0
  51. bayesplain-0.0.0/ci/314.yml +23 -0
  52. bayesplain-0.0.0/docs/Makefile +24 -0
  53. bayesplain-0.0.0/docs/docs_env.yml +27 -0
  54. bayesplain-0.0.0/docs/source/_static/custom.css +16 -0
  55. bayesplain-0.0.0/docs/source/_static/references.bib +115 -0
  56. bayesplain-0.0.0/docs/source/_templates/autosummary/class.rst +20 -0
  57. bayesplain-0.0.0/docs/source/api.rst +248 -0
  58. bayesplain-0.0.0/docs/source/conf.py +167 -0
  59. bayesplain-0.0.0/docs/source/index.md +91 -0
  60. bayesplain-0.0.0/docs/source/installation.md +58 -0
  61. bayesplain-0.0.0/docs/source/references.md +8 -0
  62. bayesplain-0.0.0/docs/source/scope.md +74 -0
  63. bayesplain-0.0.0/docs/source/user-guide/datasets.md +149 -0
  64. bayesplain-0.0.0/docs/source/user-guide/frequentist-twins.md +130 -0
  65. bayesplain-0.0.0/docs/source/user-guide/priors.md +127 -0
  66. bayesplain-0.0.0/docs/source/user-guide/quickstart.md +164 -0
  67. bayesplain-0.0.0/docs/source/validation.md +107 -0
  68. bayesplain-0.0.0/environment.yml +23 -0
  69. bayesplain-0.0.0/pyproject.toml +97 -0
  70. bayesplain-0.0.0/setup.cfg +4 -0
@@ -0,0 +1,106 @@
1
+ ---
2
+ name: Build Docs
3
+ permissions:
4
+ contents: write
5
+
6
+ on:
7
+ push:
8
+ branches: [main]
9
+ tags:
10
+ - "v*"
11
+ pull_request:
12
+ branches:
13
+ - "*"
14
+ workflow_dispatch:
15
+ inputs:
16
+ version:
17
+ description: Manual Doc Build
18
+ default: run-doc-build
19
+ required: false
20
+
21
+ concurrency:
22
+ group: ${{ github.workflow }}-${{ github.ref }}
23
+ cancel-in-progress: true
24
+
25
+ jobs:
26
+ docs:
27
+ name: Build & push docs
28
+ runs-on: ${{ matrix.os }}
29
+ timeout-minutes: 90
30
+ strategy:
31
+ matrix:
32
+ os: ["ubuntu-latest"]
33
+ environment-file: [ci/314.yml]
34
+ experimental: [false]
35
+ defaults:
36
+ run:
37
+ shell: bash -l {0}
38
+
39
+ steps:
40
+ - name: Checkout repo
41
+ uses: actions/checkout@v6
42
+ with:
43
+ fetch-depth: 0
44
+
45
+ - name: Setup micromamba
46
+ uses: mamba-org/setup-micromamba@v3
47
+ with:
48
+ environment-file: ${{ matrix.environment-file }}
49
+ micromamba-version: "latest"
50
+
51
+ - name: Install package
52
+ run: pip install . --no-deps
53
+
54
+ - name: Make docs
55
+ run: cd docs; make html
56
+
57
+ - name: Zip documentation
58
+ if: ${{ github.event_name == 'pull_request' }}
59
+ run: zip docs_artifact.zip docs/build/html -r
60
+
61
+ - name: Upload artifact
62
+ if: ${{ github.event_name == 'pull_request' }}
63
+ uses: actions/upload-artifact@v7
64
+ with:
65
+ name: docs_artifact
66
+ path: docs_artifact.zip
67
+
68
+ - name: Publish to Github Pages on main (dev)
69
+ if: ${{ github.ref == 'refs/heads/main' }}
70
+ uses: peaceiris/actions-gh-pages@v4
71
+ with:
72
+ github_token: ${{ secrets.GITHUB_TOKEN }}
73
+ publish_dir: docs/build/html/
74
+ destination_dir: dev
75
+ keep_files: false
76
+
77
+ - name: Publish to Github Pages on release (versioned)
78
+ if: ${{ github.ref_type == 'tag' }}
79
+ uses: peaceiris/actions-gh-pages@v4
80
+ with:
81
+ github_token: ${{ secrets.GITHUB_TOKEN }}
82
+ publish_dir: docs/build/html/
83
+ destination_dir: ${{ github.ref_name }}
84
+
85
+ - name: Publish to Github Pages on release (stable)
86
+ if: ${{ github.ref_type == 'tag' }}
87
+ uses: peaceiris/actions-gh-pages@v4
88
+ with:
89
+ github_token: ${{ secrets.GITHUB_TOKEN }}
90
+ publish_dir: docs/build/html/
91
+ destination_dir: stable
92
+ keep_files: false
93
+
94
+ - name: Update the versions switcher
95
+ if: ${{ github.ref_type == 'tag' }}
96
+ run: |
97
+ git checkout gh-pages
98
+ git fetch
99
+ git pull
100
+ git config --global user.name 'github-actions[bot]'
101
+ git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com'
102
+ python update_version_json.py --version ${{ github.ref_name }}
103
+ git add versions.json
104
+ git commit -m "Update versions switcher"
105
+ git push
106
+ git checkout main
@@ -0,0 +1,80 @@
1
+ ---
2
+ name: Continuous Integration
3
+
4
+ on:
5
+ push:
6
+ branches: [main]
7
+ pull_request:
8
+ branches:
9
+ - "*"
10
+ schedule:
11
+ - cron: "59 23 * * *"
12
+ workflow_dispatch:
13
+ inputs:
14
+ version:
15
+ description: Manual CI Run
16
+ default: test
17
+ required: false
18
+
19
+ jobs:
20
+ tests:
21
+ name: ${{ matrix.os }}, ${{ matrix.environment-file }}
22
+ runs-on: ${{ matrix.os }}
23
+ timeout-minutes: 30
24
+ strategy:
25
+ matrix:
26
+ os: [ubuntu-latest]
27
+ environment-file: [
28
+ ci/312.yml,
29
+ ci/313.yml,
30
+ ci/314.yml,
31
+ ]
32
+ include:
33
+ - environment-file: ci/314.yml
34
+ os: macos-15-intel # Intel
35
+ - environment-file: ci/314.yml
36
+ os: macos-latest # Apple Silicon
37
+ - environment-file: ci/314.yml
38
+ os: windows-latest
39
+ fail-fast: false
40
+
41
+ defaults:
42
+ run:
43
+ shell: bash -l {0}
44
+
45
+ steps:
46
+ - name: checkout repo
47
+ uses: actions/checkout@v6
48
+ with:
49
+ fetch-depth: 0
50
+
51
+ - name: setup micromamba
52
+ uses: mamba-org/setup-micromamba@v3
53
+ with:
54
+ environment-file: ${{ matrix.environment-file }}
55
+ micromamba-version: "latest"
56
+
57
+ - name: environment info
58
+ run: |
59
+ micromamba info
60
+ micromamba list
61
+
62
+ - name: install package
63
+ run: "pip install -e . --no-deps"
64
+
65
+ - name: run tests
66
+ run: |
67
+ pytest bayesplain/tests \
68
+ -v \
69
+ -r a \
70
+ -n auto \
71
+ --color yes \
72
+ --cov bayesplain \
73
+ --cov-append \
74
+ --cov-report term-missing \
75
+ --cov-report xml .
76
+
77
+ - name: codecov
78
+ uses: codecov/codecov-action@v6
79
+ with:
80
+ token: ${{ secrets.CODECOV_TOKEN }}
@@ -0,0 +1,52 @@
1
+ ---
2
+ name: Release & Publish
3
+
4
+ on:
5
+ push:
6
+ # Sequence of patterns matched against refs/tags
7
+ tags:
8
+ - "v*"
9
+ workflow_dispatch:
10
+ inputs:
11
+ version:
12
+ description: Manual Release
13
+ default: test
14
+ required: false
15
+
16
+
17
+ jobs:
18
+ build:
19
+ name: Create release & publish to PyPI
20
+ runs-on: ubuntu-latest
21
+ permissions:
22
+ id-token: write # MANDATORY for trusted publishing to PyPI
23
+ contents: write # MANDATORY for the Github release action
24
+
25
+ steps:
26
+ - name: Checkout repo
27
+ uses: actions/checkout@v6
28
+
29
+ - name: Set up python
30
+ uses: actions/setup-python@v6
31
+ with:
32
+ python-version: "3.x"
33
+
34
+ - name: Install Dependencies
35
+ run: |
36
+ python -m pip install --upgrade pip
37
+ python -m pip install --upgrade build twine
38
+ python -m build
39
+ twine check --strict dist/*
40
+
41
+ - name: Create Release Notes
42
+ uses: actions/github-script@v8
43
+ with:
44
+ github-token: ${{secrets.GITHUB_TOKEN}}
45
+ script: |
46
+ await github.request(`POST /repos/${{ github.repository }}/releases`, {
47
+ tag_name: "${{ github.ref }}",
48
+ generate_release_notes: true
49
+ });
50
+
51
+ - name: Publish distribution 📦 to PyPI
52
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,127 @@
1
+ scripts/
2
+
3
+ # Byte-compiled / optimized / DLL files
4
+ __pycache__/
5
+ *.py[cod]
6
+ *$py.class
7
+
8
+ # C extensions
9
+ *.so
10
+
11
+ # Distribution / packaging
12
+ .Python
13
+ env/
14
+ build/
15
+ develop-eggs/
16
+ dist/
17
+ downloads/
18
+ eggs/
19
+ .eggs/
20
+ lib/
21
+ lib64/
22
+ parts/
23
+ sdist/
24
+ var/
25
+ wheels/
26
+ *.egg-info/
27
+ .installed.cfg
28
+ *.egg
29
+ *.egg/info/
30
+
31
+ # PyInstaller
32
+ # Usually these files are written by a python script from a template
33
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
34
+ *.manifest
35
+ *.spec
36
+
37
+ # Installer logs
38
+ pip-log.txt
39
+ pip-delete-this-directory.txt
40
+
41
+ # Unit test / coverage reports
42
+ htmlcov/
43
+ .tox/
44
+ .coverage
45
+ .coverage.*
46
+ .cache
47
+ nosetests.xml
48
+ coverage.xml
49
+ *,cover
50
+ .hypothesis/
51
+
52
+ # Translations
53
+ *.mo
54
+ *.pot
55
+
56
+ # Django stuff:
57
+ *.log
58
+ local_settings.py
59
+
60
+ # Flask stuff:
61
+ instance/
62
+ .webassets-cache
63
+
64
+ # Scrapy stuff:
65
+ .scrapy
66
+
67
+ # Sphinx documentation
68
+ docs/_build/
69
+
70
+ # PyBuilder
71
+ target/
72
+
73
+ # Jupyter Notebook
74
+ .ipynb_checkpoints
75
+
76
+ # pyenv
77
+ .python-version
78
+
79
+ # celery beat schedule file
80
+ celerybeat-schedule
81
+
82
+ # dotenv
83
+ .env
84
+
85
+ # virtualenv
86
+ .venv
87
+ venv/
88
+ ENV/
89
+ .serena
90
+
91
+ # Spyder project settings
92
+ .spyderproject
93
+
94
+ # Rope project settings
95
+ .ropeproject
96
+
97
+ # Pycharm
98
+ .idea
99
+ .vscode
100
+
101
+ nlcd_2011.tif
102
+
103
+ docs/generated/
104
+ docs/apidocs/
105
+ docs/source/generated/
106
+ docs/source/user-guide/cache
107
+
108
+ # macOS
109
+ *.DS_Store
110
+
111
+ .pytest_cache/
112
+
113
+ reference
114
+ scratch/
115
+ .claude/*
116
+ # Added by code-review-graph
117
+ .code-review-graph/
118
+ .github/code-review-graph.instruction.md
119
+ agents.md
120
+ claude.md
121
+ .mcp.json
122
+
123
+ /.quarto/
124
+ **/*.quarto_ipynb
125
+
126
+ **.pytest_cache
127
+ **.ruff_cache
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2026, Eli Knaap
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its contributors
17
+ may be used to endorse or promote products derived from this software
18
+ without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,310 @@
1
+ Metadata-Version: 2.4
2
+ Name: bayesplain
3
+ Version: 0.0.0
4
+ Summary: Bayesian answers to the questions frequentist tests are usually asked
5
+ Author-email: Eli Knaap <ek@knaaptime.com>
6
+ License-Expression: BSD-3-Clause
7
+ Project-URL: Home, https://github.com/knaaptime/bayesplain
8
+ Project-URL: Repository, https://github.com/knaaptime/bayesplain
9
+ Keywords: bayesian statistics,statistics education,urban planning,public policy,conjugate priors
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Intended Audience :: Education
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
15
+ Requires-Python: >=3.10
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE.txt
18
+ Requires-Dist: numpy
19
+ Requires-Dist: scipy
20
+ Provides-Extra: plot
21
+ Requires-Dist: matplotlib; extra == "plot"
22
+ Provides-Extra: data
23
+ Requires-Dist: pandas; extra == "data"
24
+ Provides-Extra: tests
25
+ Requires-Dist: pytest; extra == "tests"
26
+ Requires-Dist: pytest-cov; extra == "tests"
27
+ Requires-Dist: hypothesis; extra == "tests"
28
+ Requires-Dist: matplotlib; extra == "tests"
29
+ Requires-Dist: pandas; extra == "tests"
30
+ Provides-Extra: validate
31
+ Requires-Dist: pingouin; extra == "validate"
32
+ Provides-Extra: docs
33
+ Requires-Dist: sphinx; extra == "docs"
34
+ Requires-Dist: myst-nb; extra == "docs"
35
+ Requires-Dist: sphinxcontrib-bibtex; extra == "docs"
36
+ Requires-Dist: sphinx-copybutton; extra == "docs"
37
+ Requires-Dist: sphinx-immaterial; extra == "docs"
38
+ Requires-Dist: numpydoc; extra == "docs"
39
+ Requires-Dist: ipykernel; extra == "docs"
40
+ Requires-Dist: matplotlib; extra == "docs"
41
+ Requires-Dist: pandas; extra == "docs"
42
+ Requires-Dist: packaging; extra == "docs"
43
+ Dynamic: license-file
44
+
45
+ # bayesplain
46
+
47
+
48
+ [![Continuous Integration](https://github.com/knaaptime/bayesplain/actions/workflows/unittests.yml/badge.svg)](https://github.com/knaaptime/bayesplain/actions/workflows/unittests.yml)
49
+ [![codecov](https://codecov.io/gh/knaaptime/bayesplain/branch/main/graph/badge.svg?token=XO4SilfBEb)](https://codecov.io/gh/knaaptime/bayesplain)
50
+
51
+ **Bayesian answers to the questions frequentist tests are usually asked.**
52
+
53
+ `bayesplain` gives you the Bayesian version of the handful of tests an
54
+ introductory statistics course is built around — proportions, means,
55
+ contingency tables, correlation, group comparisons — and prints the
56
+ conventional test alongside it every time.
57
+
58
+ It exists because there is a real hole in the Python ecosystem. `pingouin`
59
+ gives you Bayes factors for t-tests and correlations; `PyMC` and `Bambi` own the
60
+ modeling end. Nothing covers the middle: contingency tables, proportions, and
61
+ group comparisons with one consistent interface and output written to be
62
+ *explained* rather than pasted into a methods section. This fills that middle,
63
+ and it is not a port of R's `BayesFactor` — the positioning difference is the
64
+ product.
65
+
66
+ ## Three design commitments
67
+
68
+ **1. Estimation first, Bayes factors second.** The headline output is a
69
+ posterior, a credible interval, and the probability of clearing a threshold you
70
+ name. `BF = 4.2` is not a sentence anyone puts in a memo, so the Bayes factor is
71
+ a method call (`.bayes_factor()`) rather than a printed default.
72
+
73
+ **2. Every result carries its frequentist twin.** The chi-square statistic, the
74
+ t, the p-value, the confidence interval — computed and printed next to the
75
+ posterior, with a plain-English note on what each does and does not claim. You
76
+ cannot use this package without seeing both numbers for every analysis you run.
77
+
78
+ **3. No sampler in the dependency chain.** numpy and scipy, full stop, with
79
+ matplotlib optional. Everything is a conjugate posterior, a closed-form Bayes
80
+ factor, or a one-dimensional integral. It installs in a Colab cell in seconds,
81
+ with no compiler and no convergence warnings, ever. This constraint is also the
82
+ scope police: anything that would need MCMC is out of scope by construction, and
83
+ the docs hand you off to `Bambi` at that boundary.
84
+
85
+ ## Install
86
+
87
+ ```bash
88
+ pip install bayesplain # numpy + scipy only
89
+ pip install bayesplain[plot] # adds matplotlib
90
+ ```
91
+
92
+ ## The example the whole thing is built around
93
+
94
+ Two districts' eviction filing rates. The Bayesian answer is actionable; the
95
+ frequentist answer is "not significant"; both come from the same four numbers.
96
+
97
+ ```python
98
+ import bayesplain as bp
99
+
100
+ res = bp.compare_proportions(
101
+ successes=[34, 51],
102
+ n=[220, 240],
103
+ labels=["District A", "District B"],
104
+ )
105
+ print(res.summary())
106
+ ```
107
+
108
+ ```
109
+ ==========================================================================
110
+ difference in rate (District B − District A)
111
+ ==========================================================================
112
+
113
+ BAYESIAN — what the data say about the quantity itself
114
+
115
+ most likely value 5.7 percentage points
116
+ 95% credible interval −1.2 to 12.9 percentage points (HDI)
117
+ P(District B higher) 0.945
118
+
119
+ Read: District B is higher than District A with 94% probability; the
120
+ gap is most likely 5.7 percentage points, and the data are
121
+ consistent with anything from −1.2 to 12.9 percentage points
122
+ (95% credible interval).
123
+
124
+ FREQUENTIST — two-proportion z-test (equivalently chi-square, 1 df)
125
+
126
+ chi-square (1 df) 2.559
127
+ p-value 0.1096 (not significant at 0.05)
128
+ 95% confidence interval −1.2 to 12.8 percentage points (Wald)
129
+
130
+ Read: If the two rates were identical, data at least this extreme would
131
+ turn up 11.0% of the time.
132
+
133
+ --------------------------------------------------------------------
134
+
135
+ Why they look like they disagree
136
+ They are answering different questions. The test asks how surprising
137
+ this data would be in a world where the two rates were identical,
138
+ and 11.0% is not surprising enough to clear the conventional bar.
139
+ The posterior asks how plausible each possible difference is given
140
+ the data you have, and puts 94% of that plausibility on one side.
141
+ Neither is wrong. Only the second one is an input to a decision.
142
+
143
+ --------------------------------------------------------------------------
144
+ assumption prior: uninformed — Beta(1, 1)
145
+ precision 100,000 independent draws; Monte Carlo error on the mean
146
+ is ±0.00011. These are exact samples, not a Markov chain.
147
+ next .probability('>', x) .decide(rope=(lo, hi)) .sensitivity()
148
+ ==========================================================================
149
+ ```
150
+
151
+ Note the two intervals nearly coincide. The numbers agree; only the sentences
152
+ differ. That is the lesson, not a coincidence to explain away.
153
+
154
+ ## What you do with a Result
155
+
156
+ Every analysis returns the same object with the same methods, so what you learn
157
+ in week 2 still works in week 9.
158
+
159
+ ```python
160
+ res.probability(">", 0.05) # P(the gap exceeds 5 points)
161
+ res.interval(0.95, kind="hdi") # or kind="eti" to line up with a CI
162
+ res.decide(rope=(-0.02, 0.02)) # HDI + ROPE, in place of "reject the null"
163
+ res.sentence() # one memo-ready line
164
+ res.translate() # what the p-value claims vs the posterior
165
+ res.sensitivity() # how the conclusion moves as the prior widens
166
+ res.plot(kind="components") # where the difference came from
167
+ res.plot_kinds() # what this particular result can draw
168
+ res.to_dict() # autograding hook
169
+ res.draws # ndarray, so you can compute anything
170
+ res.bayes_factor() # available, documented, never the headline
171
+ ```
172
+
173
+ `.sensitivity()` is a first-class method, not an advanced footnote. Prior
174
+ sensitivity is the strongest legitimate objection to canned Bayesian analysis,
175
+ and reporting it by default converts that objection into a scheduled lecture. On
176
+ the example above it also surfaces something worth teaching: the credible
177
+ interval barely moves across every prior in the ladder, while the Bayes factor
178
+ moves by a factor of 19. That asymmetry is the reason this package leads with
179
+ the estimate.
180
+
181
+ ## Priors have names
182
+
183
+ Nobody should have to type a shape parameter to get started, and nobody should
184
+ be able to hide which assumption they used.
185
+
186
+ ```python
187
+ bp.priors.describe() # what each preset assumes
188
+ bp.proportion(34, 220, prior="skeptical") # named preset
189
+ bp.proportion(34, 220, prior=(2, 5)) # explicit (a, b)
190
+ bp.priors.from_previous_study(successes=12, n=80) # an earlier study as a prior
191
+ ```
192
+
193
+ The resolved prior and its parameters print in every summary.
194
+
195
+ ## Reproducibility
196
+
197
+ The default seed is fixed (`bp.get_seed()` → `12345`). That is unusual for a
198
+ research package and correct for a teaching one: if every student gets different
199
+ digits in the last decimal place, office hours fill with questions about Monte
200
+ Carlo noise instead of questions about statistics. Having hidden that noise, the
201
+ package then surfaces it — every sampled quantity prints its Monte Carlo
202
+ standard error. Use `bp.set_seed(None)` to demonstrate that the wobble is real.
203
+
204
+ ## The seven analyses
205
+
206
+ All built, tested, and documented.
207
+
208
+ | Function | Frequentist counterpart printed alongside | Method |
209
+ | --- | --- | --- |
210
+ | `proportion` | exact binomial test, Wilson interval | Beta-Binomial, exact |
211
+ | `compare_proportions` | two-proportion z / chi-square, Wald interval | two Betas, exact draws |
212
+ | `contingency` | Pearson chi-square test of independence | Gunel-Dickey, all four sampling schemes; posterior over Cramér's V or the log odds ratio |
213
+ | `mean` | one-sample t-test | closed-form Student-t posterior |
214
+ | `compare_means` | Welch's t-test (or pooled) | Student-t per group; Behrens-Fisher by draws |
215
+ | `correlation` | Pearson r, Fisher-z interval | exact sampling density, grid + inverse CDF |
216
+ | `compare_groups` | one-way ANOVA | pairwise-first, optional closed-form partial pooling |
217
+
218
+ Explicitly out of scope: multi-factor ANOVA, interactions, regression with more
219
+ than one predictor, mixed models, anything needing importance sampling over
220
+ multiple hyperparameters. For those, go to `Bambi` — the docs include a worked
221
+ handoff. There is also deliberately no *omnibus* Bayes factor for
222
+ `compare_groups`; `.pairwise()` reports a validated one per pair instead, and
223
+ the method explains why when you ask for the omnibus version.
224
+
225
+ ## Bundled datasets
226
+
227
+ Four small, real, pre-cleaned planning datasets ship inside the package, so no
228
+ problem set dies because a city reorganised its open-data portal.
229
+
230
+ ```python
231
+ bp.datasets.describe() # one line each
232
+ bp.datasets.load_collisions() # LA and San Diego collisions, 2019-2023
233
+ bp.datasets.load_tracts() # LA County ACS tracts
234
+ bp.datasets.load_blockgroups() # the same variables, finer geography
235
+ bp.datasets.load_parcels() # Baltimore residential parcels
236
+ ```
237
+
238
+ The tract/block-group pair exists for one purpose: identical variables,
239
+ identical county, two aggregations, and non-overlapping credible intervals for
240
+ the same correlation (0.781 vs 0.695). The modifiable areal unit problem, with
241
+ the arithmetic to show it is not sampling noise.
242
+
243
+ ## Validation
244
+
245
+ Nothing is asserted on the strength of having been transcribed carefully.
246
+
247
+ **Published reference values.** The contingency Bayes factors reproduce the
248
+ worked examples in Jamil et al. (2017) under all four Gunel-Dickey schemes:
249
+ log BF₁₀ = 23.0337 against a published 23.03 for the doll-preference study,
250
+ BF₁₀ = 9.194 against 9.19 (Poisson), 3.043 against 3.04 (hypergeometric), and
251
+ the posterior log odds ratio at 2.47 with a 95% interval of (1.73, 3.26) against
252
+ a published (1.73, 3.26).
253
+
254
+ **Independent implementations.** The JZS t-test Bayes factor matches
255
+ `pingouin.bayesfactor_ttest` to six significant figures across one-sample,
256
+ two-sample, and every prior width; the correlation Bayes factor matches
257
+ `pingouin.bayesfactor_pearson` to seven. `pingouin` is a validation-only
258
+ dependency, never required at runtime.
259
+
260
+ **Self-validation.** Marginal likelihoods are checked against brute-force
261
+ quadrature of the same integral and against summing to 1 over all outcomes. The
262
+ exact correlation sampling density is checked against its own normalisation over
263
+ (−1, 1), which pins the hypergeometric transcription without reference to
264
+ anyone's code.
265
+
266
+ **Behavioural properties.** Posterior means fall between the prior mean and the
267
+ MLE; interval widths shrink as 1/√n; wider priors weaken the Bayes factor for a
268
+ small effect; swapping group order flips the sign and nothing else; results are
269
+ invariant to relabelling categories.
270
+
271
+ **Pedagogical regression tests** (marked `pedagogy`). The numbers a lecture
272
+ depends on are pinned as assertions. If a refactor breaks a lecture, CI says so
273
+ rather than a student.
274
+
275
+ Two notes on the contingency Bayes factor, since the earlier version of this
276
+ README flagged it as unverified. It is now validated against the published
277
+ values above. It is computed in a form that differs algebraically from Jamil et
278
+ al.'s Equation 10 — each row drawing its own column distribution rather than
279
+ their successive conditioning — and the two agree exactly once expanded in gamma
280
+ functions; the advantage of this form is that it accepts a per-column
281
+ concentration vector, so a `Beta(a, b)` prior on a rate carries into the Bayes
282
+ factor unchanged. Separately, `bayesplain` evaluates the correlation marginal
283
+ likelihood in log space, which means it returns a finite answer where `pingouin`
284
+ returns `inf` for strongly correlated large samples — including the ~2,400-tract
285
+ case in the bundled data.
286
+
287
+ ## Documentation
288
+
289
+ ```bash
290
+ pip install -e ".[docs]"
291
+ cd docs && make html
292
+ ```
293
+
294
+ Sphinx with `sphinx-immaterial` and executed notebooks, in the same shape as
295
+ `bayesplain`. Builds clean with no warnings.
296
+
297
+ ## Development
298
+
299
+ ```bash
300
+ pip install -e ".[tests,plot,data,validate]"
301
+ pytest # fast suite, including doctests
302
+ pytest -m '' # add the slow Monte Carlo validation runs
303
+ pytest -m validation # only the cross-implementation checks
304
+ pytest -m pedagogy # only the numbers a lecture depends on
305
+ ruff check . && ruff format --check .
306
+ ```
307
+
308
+ ## License
309
+
310
+ BSD 3-Clause.