statsinference
Fit univariate distributions to data by maximum likelihood, pick the best one by AIC or BIC, check the fit with fitdistrplus-style plots, and simulate from it.
Install
From GitHub
pip install git+https
From PyPI
pip install . # from this folder
pip install ".[all]" # with progress bar (tqdm) and DataFrame tables (pandas)
Quick start
import numpy as np
from statsinference import StatsInference
x = np.random.default_rng(1).gamma(2, 1.5, size=300)
# Let it choose among every distribution whose support fits the data
si = StatsInference(x).select(criterion="aic", verbose=1, progress=True)
si.best_dist # 'gamma'
si.estimate, si.sd # estimates and standard errors
si.table # ranking: loglik, AIC, BIC, delta, weight, KS
si.summary() # estimates, loglik, AIC/BIC, KS / CvM / AD
si.plot() # density, CDF, Q-Q and P-P panels
si.plot_compare(top=3) # the three best overlaid
sims = si.simulate(1000, seed=123) # draws from the best fit
alt = si.simulate(1000, seed=123, dist="weibull") # or from another candidate
# Or fit one distribution directly
StatsInference(x).fit("weibull").summary()
Supported distributions
Named (case-insensitive, parameter names as in R): beta, cauchy,
chi-squared, exponential, f, gamma (shape, rate), geometric,
logistic, lognormal / log-normal, negative binomial (size, mu),
normal (closed form), poisson, t (location-scale: m, s, df), weibull.
Also accepted by fit() and select():
- any SciPy distribution, e.g.
scipy.stats.genextreme; - your own density
f(x, **params), optionally with alogargument (passstart=).
Main options
| Method | Arguments |
|---|---|
fit(densfun, start, fixed, lower, upper, method) |
fixed holds parameters not estimated, e.g. fixed={"df": 5} |
select(distributions, criterion, verbose, progress, options) |
verbose: 0 silent, 1 ranking, 2 each fit; options={"t": {"fixed": {"df": 5}}} |
simulate(size, seed, dist) |
dist picks another stored fit |
compare(), gof(), plot(), denscomp(), cdfcomp(), qqcomp(), ppcomp() |
Notes:
- With non-negative whole numbers,
select()compares only count distributions (Poisson, geometric, negative binomial); count and continuous likelihoods cannot be compared by AIC. Passdistributions=to override. - KS p-values treat the parameters as known, so they are optimistic when the parameters were estimated from the same data.
Development
make help # list every target
make install # editable install with extras (uses uv if present, needs an active venv)
make test # run the tests
make run-tests # install, then tests with coverage
make lint # flake8
make format # black + autopep8, line length 80
make run-examples # run everything in examples/
make docs # API docs with pdoc, in statsinference-docs/
make check-dist # build sdist + wheel and check them with twine
make release # upload to PyPI
License
BSD 3-Clause Clear License; see LICENSE.
Metadata
Release files for statsinference 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| statsinference-0.1.4.tar.gz | 22.0 kB | Without provenance | Details for statsinference-0.1.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| statsinference-0.1.4-py3-none-any.whl | Python 3 | none | any | Details for statsinference-0.1.4-py3-none-any.whl |
Total release size: 41.1 kB
Release files / statsinference-0.1.4.tar.gz
| Download URL | statsinference-0.1.4.tar.gz |
|---|---|
| Size | 22.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ae4de66e61cc775570899a0a34125e27b57d43d9932a2270d766850aac28e871
|
|
BLAKE2b-256 checksum How to use checksums |
957c7dedb0dd7153b8ac41703c03cb0bf0f96e5133f0aff14bdb88b8ad4ce88a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.9
|
Release files / statsinference-0.1.4-py3-none-any.whl
| Download URL | statsinference-0.1.4-py3-none-any.whl |
|---|---|
| Size | 19.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1793634b56ccc2cefd61e3301eb367b01b0ecee37fa4f0aff83a94ec1122c8aa
|
|
BLAKE2b-256 checksum How to use checksums |
39a78ef70bd590c4fc9dd5bbc64acabda765856ef2030f31d3d4b2dd526bc828
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.9
|
Security for statsinference 0.1.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.