statsinference 0.1.4__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.
@@ -0,0 +1 @@
1
+ github: Techtonique
@@ -0,0 +1,15 @@
1
+ * nnetsauce version:
2
+ * Python version:
3
+ * Operating System:
4
+
5
+ ### Description
6
+
7
+ Describe what you were trying to get done.
8
+ Tell us what happened, what went wrong, and what you expected to happen.
9
+
10
+ ### What I Did
11
+
12
+ ```
13
+ Paste the command(s) you ran and the output.
14
+ If there was a crash, please include the traceback here.
15
+ ```
@@ -0,0 +1,83 @@
1
+ name: Publish Python 🐍 distribution 📦 to PyPI
2
+
3
+ on:
4
+ push:
5
+ branches: [main] # test every push to main
6
+ tags: ["v*"] # publish when a version tag is pushed, e.g. v0.1.0
7
+ pull_request:
8
+ workflow_dispatch: # manual run: test, build and publish
9
+
10
+ jobs:
11
+ test:
12
+ runs-on: ubuntu-latest
13
+ strategy:
14
+ fail-fast: false
15
+ matrix:
16
+ python-version: ["3.10", "3.12", "3.13"]
17
+ env:
18
+ MPLBACKEND: Agg # no display on the runner
19
+ steps:
20
+ - uses: actions/checkout@v7
21
+
22
+ - uses: actions/setup-python@v7
23
+ with:
24
+ python-version: ${{ matrix.python-version }}
25
+
26
+ - name: Install package with test extras
27
+ run: |
28
+ python -m pip install --upgrade pip
29
+ pip install ".[all,test]"
30
+
31
+ - name: Run tests
32
+ run: python -m pytest -q tests
33
+
34
+ - name: Run examples
35
+ run: find examples -maxdepth 2 -name "*.py" -print -exec python {} \;
36
+
37
+ build:
38
+ needs: test
39
+ runs-on: ubuntu-latest
40
+ steps:
41
+ - uses: actions/checkout@v7
42
+
43
+ - uses: actions/setup-python@v7
44
+ with:
45
+ python-version: "3.12"
46
+
47
+ - name: Build sdist and wheel
48
+ run: |
49
+ python -m pip install --upgrade pip build twine
50
+ python -m build
51
+ python -m twine check dist/*
52
+
53
+ - name: Check the tag matches the package version
54
+ if: startsWith(github.ref, 'refs/tags/v')
55
+ run: |
56
+ PKG_VERSION=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")
57
+ if [ "v${PKG_VERSION}" != "${GITHUB_REF_NAME}" ]; then
58
+ echo "Tag ${GITHUB_REF_NAME} does not match pyproject version ${PKG_VERSION}"
59
+ exit 1
60
+ fi
61
+
62
+ - uses: actions/upload-artifact@v7
63
+ with:
64
+ name: dist
65
+ path: dist/
66
+
67
+ publish:
68
+ needs: build
69
+ # Only for version tags or a manual run, never for ordinary pushes or PRs
70
+ if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch'
71
+ runs-on: ubuntu-latest
72
+ environment: pypi
73
+ steps:
74
+ - uses: actions/download-artifact@v8
75
+ with:
76
+ name: dist
77
+ path: dist/
78
+
79
+ - name: Publish to PyPI
80
+ uses: pypa/gh-action-pypi-publish@release/v1
81
+ with:
82
+ password: ${{ secrets.PYPI_GLOBAL }}
83
+ skip-existing: true # a manual re-run won't fail on an existing version
@@ -0,0 +1,225 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ *.lcov
51
+ .hypothesis/
52
+ .pytest_cache/
53
+ cover/
54
+
55
+ # Translations
56
+ *.mo
57
+ *.pot
58
+
59
+ # Django stuff:
60
+ *.log
61
+ local_settings.py
62
+ db.sqlite3
63
+ db.sqlite3-journal
64
+ db.sqlite3-wal
65
+ db.sqlite3-shm
66
+
67
+ # Flask stuff:
68
+ instance/
69
+ .webassets-cache
70
+
71
+ # Scrapy stuff:
72
+ .scrapy
73
+
74
+ # Sphinx documentation
75
+ docs/_build/
76
+
77
+ # PyBuilder
78
+ .pybuilder/
79
+ target/
80
+
81
+ # Jupyter Notebook
82
+ .ipynb_checkpoints
83
+
84
+ # IPython
85
+ profile_default/
86
+ ipython_config.py
87
+
88
+ # pyenv
89
+ # For a library or package, you might want to ignore these files since the code is
90
+ # intended to run in multiple environments; otherwise, check them in:
91
+ # .python-version
92
+
93
+ # pipenv
94
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
95
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
96
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
97
+ # install all needed dependencies.
98
+ # Pipfile.lock
99
+
100
+ # uv
101
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
102
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
103
+ # commonly ignored for libraries.
104
+ # uv.lock
105
+
106
+ # poetry
107
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
108
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
109
+ # commonly ignored for libraries.
110
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
111
+ # poetry.lock
112
+ # poetry.toml
113
+
114
+ # pdm
115
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
116
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
117
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
118
+ # pdm.lock
119
+ # pdm.toml
120
+ .pdm-python
121
+ .pdm-build/
122
+
123
+ # pixi
124
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
125
+ # pixi.lock
126
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
127
+ # in the .venv directory. It is recommended not to include this directory in version control.
128
+ .pixi/*
129
+ !.pixi/config.toml
130
+
131
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
132
+ __pypackages__/
133
+
134
+ # Celery stuff
135
+ celerybeat-schedule*
136
+ celerybeat.pid
137
+
138
+ # Redis
139
+ *.rdb
140
+ *.aof
141
+ *.pid
142
+
143
+ # RabbitMQ
144
+ mnesia/
145
+ rabbitmq/
146
+ rabbitmq-data/
147
+
148
+ # ActiveMQ
149
+ activemq-data/
150
+
151
+ # SageMath parsed files
152
+ *.sage.py
153
+
154
+ # Environments
155
+ .env
156
+ .envrc
157
+ .venv
158
+ env/
159
+ venv/
160
+ ENV/
161
+ env.bak/
162
+ venv.bak/
163
+
164
+ # Conda environments
165
+ conda-meta/
166
+
167
+ # Spyder project settings
168
+ .spyderproject
169
+ .spyproject
170
+
171
+ # Rope project settings
172
+ .ropeproject
173
+
174
+ # mkdocs/Zensical documentation
175
+ /site
176
+
177
+ # mypy
178
+ .mypy_cache/
179
+ .dmypy.json
180
+ dmypy.json
181
+
182
+ # Pyre type checker
183
+ .pyre/
184
+
185
+ # pytype static type analyzer
186
+ .pytype/
187
+
188
+ # Cython debug symbols
189
+ cython_debug/
190
+
191
+ # PyCharm
192
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
193
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
194
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
195
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
196
+ # .idea/
197
+
198
+ # Abstra
199
+ # Abstra is an AI-powered process automation framework.
200
+ # Ignore directories containing user credentials, local state, and settings.
201
+ # Learn more at https://abstra.io/docs
202
+ .abstra/
203
+
204
+ # Visual Studio Code
205
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore that
206
+ # can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
207
+ # and can be added to the global gitignore or merged into this file. However, if you prefer, you
208
+ # could uncomment the following to ignore the entire vscode folder
209
+ # .vscode/
210
+ # Temporary file for partial code execution
211
+ tempCodeRunnerFile.py
212
+
213
+ # Ruff stuff:
214
+ .ruff_cache/
215
+
216
+ # PyPI configuration file
217
+ .pypirc
218
+
219
+ # Marimo
220
+ marimo/_static/
221
+ marimo/_lsp/
222
+ __marimo__/
223
+
224
+ # Streamlit
225
+ .streamlit/secrets.toml
@@ -0,0 +1,32 @@
1
+ The Clear BSD License
2
+
3
+ Copyright (c) 2026, [Thierry Moudiki]
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted (subject to the limitations in the disclaimer
8
+ below) provided that the following conditions are met:
9
+
10
+ * Redistributions of source code must retain the above copyright notice,
11
+ this list of conditions and the following disclaimer.
12
+
13
+ * Redistributions in binary form must reproduce the above copyright
14
+ notice, this list of conditions and the following disclaimer in the
15
+ documentation and/or other materials provided with the distribution.
16
+
17
+ * Neither the name of the copyright holder nor the names of its
18
+ contributors may be used to endorse or promote products derived from this
19
+ software without specific prior written permission.
20
+
21
+ NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
22
+ THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
23
+ CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
25
+ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
26
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
29
+ BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
30
+ IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
+ POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,105 @@
1
+ .PHONY: clean clean-test clean-pyc clean-build docs help lint format coverage \
2
+ test run-tests run-examples install dist release servedocs check-dist
3
+ .DEFAULT_GOAL := help
4
+
5
+ PACKAGE := statsinference
6
+ SRC := src/$(PACKAGE)
7
+ DOCS_OUT := $(PACKAGE)-docs
8
+ # Where `make build-site` copies the docs (override: make build-site SITE_DIR=...)
9
+ SITE_DIR ?= ../../Pro_Website/Techtonique.github.io/$(PACKAGE)
10
+ # Use uv when available, plain pip otherwise
11
+ PIP := $(shell command -v uv >/dev/null 2>&1 && echo "uv pip" || echo "python3 -m pip")
12
+
13
+ define BROWSER_PYSCRIPT
14
+ import os, webbrowser, sys
15
+
16
+ from urllib.request import pathname2url
17
+
18
+ webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1])))
19
+ endef
20
+ export BROWSER_PYSCRIPT
21
+
22
+ define PRINT_HELP_PYSCRIPT
23
+ import re, sys
24
+
25
+ for line in sys.stdin:
26
+ match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line)
27
+ if match:
28
+ target, help = match.groups()
29
+ print("%-20s %s" % (target, help))
30
+ endef
31
+ export PRINT_HELP_PYSCRIPT
32
+
33
+ BROWSER := python3 -c "$$BROWSER_PYSCRIPT"
34
+
35
+ help:
36
+ @python3 -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)
37
+
38
+ clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and Python artifacts
39
+
40
+ clean-build: ## remove build artifacts
41
+ rm -fr build/
42
+ rm -fr dist/
43
+ rm -fr .eggs/
44
+ find . -name '*.egg-info' -exec rm -fr {} +
45
+ find . -name '*.egg' -exec rm -fr {} +
46
+
47
+ clean-pyc: ## remove Python file artifacts
48
+ find . -name '*.pyc' -exec rm -f {} +
49
+ find . -name '*.pyo' -exec rm -f {} +
50
+ find . -name '*~' -exec rm -f {} +
51
+ find . -name '__pycache__' -exec rm -fr {} +
52
+
53
+ clean-test: ## remove test and coverage artifacts
54
+ rm -fr htmlcov .coverage .pytest_cache
55
+
56
+ lint: ## check style with flake8
57
+ python3 -m flake8 $(SRC) tests examples --max-line-length=80 \
58
+ --extend-ignore=E203,W503,E731
59
+
60
+ format: ## format code with black and autopep8 (line length 80)
61
+ python3 -m black $(SRC) tests examples --line-length=80
62
+ find $(SRC) -name "*.py" -exec python3 -m autopep8 --max-line-length=80 --in-place {} +
63
+
64
+ install: clean ## install the package (editable) with all extras
65
+ $(PIP) install -e ".[all,test]"
66
+
67
+ test: ## run the tests (without reinstalling)
68
+ python3 -m pytest -q tests
69
+
70
+ run-tests: install ## install, then run all the tests with coverage
71
+ python3 -m coverage run --source=$(SRC) -m pytest -q tests
72
+ python3 -m coverage report --show-missing
73
+
74
+ coverage: ## show the coverage report (after run-tests) and build htmlcov/
75
+ python3 -m coverage report --show-missing
76
+ python3 -m coverage html
77
+ $(BROWSER) htmlcov/index.html
78
+
79
+ docs: install ## generate API docs with pdoc
80
+ $(PIP) install pdoc
81
+ python3 -m pdoc $(SRC) --output-dir $(DOCS_OUT)
82
+ find . -name '__pycache__' -exec rm -fr {} +
83
+
84
+ servedocs: install ## serve the docs locally, reloading on change
85
+ $(PIP) install pdoc
86
+ python3 -m pdoc $(SRC)
87
+
88
+ build-site: docs ## copy the docs to the website folder (SITE_DIR)
89
+ mkdir -p $(SITE_DIR)
90
+ cp -rf $(DOCS_OUT)/* $(SITE_DIR)
91
+
92
+ run-examples: ## run all examples with one command
93
+ find examples -maxdepth 2 -name "*.py" -exec python3 {} \;
94
+
95
+ dist: clean ## build source and wheel packages
96
+ $(PIP) install build
97
+ python3 -m build
98
+ ls -l dist
99
+
100
+ check-dist: dist ## check the built packages render correctly on PyPI
101
+ $(PIP) install twine
102
+ python3 -m twine check dist/*
103
+
104
+ release: check-dist ## package and upload a release to PyPI
105
+ python3 -m twine upload --repository pypi dist/* --verbose
@@ -0,0 +1,129 @@
1
+ Metadata-Version: 2.5
2
+ Name: statsinference
3
+ Version: 0.1.4
4
+ Summary: Maximum-likelihood fitting of univariate distributions, AIC/BIC model selection, diagnostic plots and simulation.
5
+ Author: Your Name
6
+ License-Expression: BSD-3-Clause-Clear
7
+ License-File: LICENSE
8
+ Keywords: AIC,BIC,distribution fitting,maximum likelihood,statistics
9
+ Classifier: Intended Audience :: Science/Research
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
12
+ Requires-Python: >=3.9
13
+ Requires-Dist: matplotlib>=3.5
14
+ Requires-Dist: numpy>=1.22
15
+ Requires-Dist: scipy>=1.9
16
+ Provides-Extra: all
17
+ Requires-Dist: pandas; extra == 'all'
18
+ Requires-Dist: tqdm; extra == 'all'
19
+ Provides-Extra: dev
20
+ Requires-Dist: autopep8; extra == 'dev'
21
+ Requires-Dist: black; extra == 'dev'
22
+ Requires-Dist: build; extra == 'dev'
23
+ Requires-Dist: coverage; extra == 'dev'
24
+ Requires-Dist: flake8; extra == 'dev'
25
+ Requires-Dist: pdoc; extra == 'dev'
26
+ Requires-Dist: pytest; extra == 'dev'
27
+ Requires-Dist: twine; extra == 'dev'
28
+ Provides-Extra: pandas
29
+ Requires-Dist: pandas; extra == 'pandas'
30
+ Provides-Extra: progress
31
+ Requires-Dist: tqdm; extra == 'progress'
32
+ Provides-Extra: test
33
+ Requires-Dist: coverage; extra == 'test'
34
+ Requires-Dist: pytest; extra == 'test'
35
+ Description-Content-Type: text/markdown
36
+
37
+ # statsinference
38
+
39
+ Fit univariate distributions to data by maximum likelihood, pick the best one
40
+ by AIC or BIC, check the fit with fitdistrplus-style plots, and simulate from it.
41
+
42
+ ## Install
43
+
44
+ ### From GitHub
45
+
46
+ ```bash
47
+ pip install git+https
48
+ ```
49
+
50
+ ### From PyPI
51
+
52
+ ```bash
53
+ pip install . # from this folder
54
+ pip install ".[all]" # with progress bar (tqdm) and DataFrame tables (pandas)
55
+ ```
56
+
57
+ ## Quick start
58
+
59
+ ```python
60
+ import numpy as np
61
+ from statsinference import StatsInference
62
+
63
+ x = np.random.default_rng(1).gamma(2, 1.5, size=300)
64
+
65
+ # Let it choose among every distribution whose support fits the data
66
+ si = StatsInference(x).select(criterion="aic", verbose=1, progress=True)
67
+ si.best_dist # 'gamma'
68
+ si.estimate, si.sd # estimates and standard errors
69
+ si.table # ranking: loglik, AIC, BIC, delta, weight, KS
70
+ si.summary() # estimates, loglik, AIC/BIC, KS / CvM / AD
71
+ si.plot() # density, CDF, Q-Q and P-P panels
72
+ si.plot_compare(top=3) # the three best overlaid
73
+
74
+ sims = si.simulate(1000, seed=123) # draws from the best fit
75
+ alt = si.simulate(1000, seed=123, dist="weibull") # or from another candidate
76
+
77
+ # Or fit one distribution directly
78
+ StatsInference(x).fit("weibull").summary()
79
+ ```
80
+
81
+ ## Supported distributions
82
+
83
+ Named (case-insensitive, parameter names as in R): `beta`, `cauchy`,
84
+ `chi-squared`, `exponential`, `f`, `gamma` (shape, rate), `geometric`,
85
+ `logistic`, `lognormal` / `log-normal`, `negative binomial` (size, mu),
86
+ `normal` (closed form), `poisson`, `t` (location-scale: m, s, df), `weibull`.
87
+
88
+ Also accepted by `fit()` and `select()`:
89
+
90
+ - any SciPy distribution, e.g. `scipy.stats.genextreme`;
91
+ - your own density `f(x, **params)`, optionally with a `log` argument
92
+ (pass `start=`).
93
+
94
+ ## Main options
95
+
96
+ | Method | Arguments |
97
+ |---|---|
98
+ | `fit(densfun, start, fixed, lower, upper, method)` | `fixed` holds parameters not estimated, e.g. `fixed={"df": 5}` |
99
+ | `select(distributions, criterion, verbose, progress, options)` | `verbose`: 0 silent, 1 ranking, 2 each fit; `options={"t": {"fixed": {"df": 5}}}` |
100
+ | `simulate(size, seed, dist)` | `dist` picks another stored fit |
101
+ | `compare()`, `gof()`, `plot()`, `denscomp()`, `cdfcomp()`, `qqcomp()`, `ppcomp()` | |
102
+
103
+ Notes:
104
+
105
+ - With non-negative whole numbers, `select()` compares only count
106
+ distributions (Poisson, geometric, negative binomial); count and
107
+ continuous likelihoods cannot be compared by AIC. Pass `distributions=`
108
+ to override.
109
+ - KS p-values treat the parameters as known, so they are optimistic when the
110
+ parameters were estimated from the same data.
111
+
112
+ ## Development
113
+
114
+ ```bash
115
+ make help # list every target
116
+ make install # editable install with extras (uses uv if present, needs an active venv)
117
+ make test # run the tests
118
+ make run-tests # install, then tests with coverage
119
+ make lint # flake8
120
+ make format # black + autopep8, line length 80
121
+ make run-examples # run everything in examples/
122
+ make docs # API docs with pdoc, in statsinference-docs/
123
+ make check-dist # build sdist + wheel and check them with twine
124
+ make release # upload to PyPI
125
+ ```
126
+
127
+ ## License
128
+
129
+ BSD 3-Clause Clear License; see [LICENSE](LICENSE).
@@ -0,0 +1,93 @@
1
+ # statsinference
2
+
3
+ Fit univariate distributions to data by maximum likelihood, pick the best one
4
+ by AIC or BIC, check the fit with fitdistrplus-style plots, and simulate from it.
5
+
6
+ ## Install
7
+
8
+ ### From GitHub
9
+
10
+ ```bash
11
+ pip install git+https
12
+ ```
13
+
14
+ ### From PyPI
15
+
16
+ ```bash
17
+ pip install . # from this folder
18
+ pip install ".[all]" # with progress bar (tqdm) and DataFrame tables (pandas)
19
+ ```
20
+
21
+ ## Quick start
22
+
23
+ ```python
24
+ import numpy as np
25
+ from statsinference import StatsInference
26
+
27
+ x = np.random.default_rng(1).gamma(2, 1.5, size=300)
28
+
29
+ # Let it choose among every distribution whose support fits the data
30
+ si = StatsInference(x).select(criterion="aic", verbose=1, progress=True)
31
+ si.best_dist # 'gamma'
32
+ si.estimate, si.sd # estimates and standard errors
33
+ si.table # ranking: loglik, AIC, BIC, delta, weight, KS
34
+ si.summary() # estimates, loglik, AIC/BIC, KS / CvM / AD
35
+ si.plot() # density, CDF, Q-Q and P-P panels
36
+ si.plot_compare(top=3) # the three best overlaid
37
+
38
+ sims = si.simulate(1000, seed=123) # draws from the best fit
39
+ alt = si.simulate(1000, seed=123, dist="weibull") # or from another candidate
40
+
41
+ # Or fit one distribution directly
42
+ StatsInference(x).fit("weibull").summary()
43
+ ```
44
+
45
+ ## Supported distributions
46
+
47
+ Named (case-insensitive, parameter names as in R): `beta`, `cauchy`,
48
+ `chi-squared`, `exponential`, `f`, `gamma` (shape, rate), `geometric`,
49
+ `logistic`, `lognormal` / `log-normal`, `negative binomial` (size, mu),
50
+ `normal` (closed form), `poisson`, `t` (location-scale: m, s, df), `weibull`.
51
+
52
+ Also accepted by `fit()` and `select()`:
53
+
54
+ - any SciPy distribution, e.g. `scipy.stats.genextreme`;
55
+ - your own density `f(x, **params)`, optionally with a `log` argument
56
+ (pass `start=`).
57
+
58
+ ## Main options
59
+
60
+ | Method | Arguments |
61
+ |---|---|
62
+ | `fit(densfun, start, fixed, lower, upper, method)` | `fixed` holds parameters not estimated, e.g. `fixed={"df": 5}` |
63
+ | `select(distributions, criterion, verbose, progress, options)` | `verbose`: 0 silent, 1 ranking, 2 each fit; `options={"t": {"fixed": {"df": 5}}}` |
64
+ | `simulate(size, seed, dist)` | `dist` picks another stored fit |
65
+ | `compare()`, `gof()`, `plot()`, `denscomp()`, `cdfcomp()`, `qqcomp()`, `ppcomp()` | |
66
+
67
+ Notes:
68
+
69
+ - With non-negative whole numbers, `select()` compares only count
70
+ distributions (Poisson, geometric, negative binomial); count and
71
+ continuous likelihoods cannot be compared by AIC. Pass `distributions=`
72
+ to override.
73
+ - KS p-values treat the parameters as known, so they are optimistic when the
74
+ parameters were estimated from the same data.
75
+
76
+ ## Development
77
+
78
+ ```bash
79
+ make help # list every target
80
+ make install # editable install with extras (uses uv if present, needs an active venv)
81
+ make test # run the tests
82
+ make run-tests # install, then tests with coverage
83
+ make lint # flake8
84
+ make format # black + autopep8, line length 80
85
+ make run-examples # run everything in examples/
86
+ make docs # API docs with pdoc, in statsinference-docs/
87
+ make check-dist # build sdist + wheel and check them with twine
88
+ make release # upload to PyPI
89
+ ```
90
+
91
+ ## License
92
+
93
+ BSD 3-Clause Clear License; see [LICENSE](LICENSE).
@@ -0,0 +1,18 @@
1
+ """Fit a user-supplied density (with a `log` argument) and a fixed parameter."""
2
+
3
+ import numpy as np
4
+ from scipy import stats
5
+
6
+ from statsinference import StatsInference
7
+
8
+
9
+ def dgamma(x, shape, rate, log=False):
10
+ f = stats.gamma.logpdf if log else stats.gamma.pdf
11
+ return f(x, shape, scale=1 / rate)
12
+
13
+
14
+ x = np.random.default_rng(3).gamma(2, 1.5, size=300)
15
+ StatsInference(x).fit(dgamma, start={"shape": 1, "rate": 1}).summary()
16
+
17
+ t = np.random.default_rng(4).standard_t(5, size=400) * 2 + 1
18
+ StatsInference(t).fit("t", fixed={"df": 5}).summary()