Skip to main content

Ministats

image Documentation Status

ministats is lightweight Python for learning statistics that includes helper functions for data analysis, probability visualizations, and statistical analysis procedures. The goal is to show code implementations of the standard stats procedures used in STATS 101 courses that are easy to understand for Python beginners.

  • Docs: ministats.readthedocs.io
  • Features:
    • Code implementations from scratch that closely match the math calculations.
    • Leverages probability distributions defined in scipy.stats.
    • Includes both classical analytical approximation methods like t-tests and modern methods like simulations, bootstrap estimation, and permutation tests.
  • Free software: MIT license

Installation

To install the ministats library, run the following command in a terminal:

$ python -m pip install ministats

To use ministats inside a Jupyter notebook or Colab notebook, run the following %-magic command in a code cell:

%pip install ministats

Quickstart

Plotting discrte probability distirbutoins

Here is a simple example that shows how to plot the probability mass function (PMF) of poission distibution $P \sim \text{Pois}(\lambda=10)$.

from scipy.stats import poisson
lam = 10
rvP = poisson(lam)

from ministats import plot_pmf
plot_pmf(rvP, xlims=[0,25], rv_name="P");
Plot output

Plotting continuous probability distirbutoins

Here is a simple example that shows how to plot the probability density function (PDF) of normal distibution $N \sim \mathcal{N}(\mu=100,\sigma=10)$.

from scipy.stats import norm
rvN = norm(100,10)

from ministats import plot_pdf
plot_pdf(rvN, xlims=[40,160], rv_name="N");
Plot output

Computing sample statistics

We'll start by crearing a random sample of size $n=30$ from the normal distribution $N \sim \mathcal{N}(\mu=100,\sigma=10)$.

from scipy.stats import norm
rvN = norm(100,10)

n = 30

np.random.seed(43)
sample = rvN.rvs(n)
sample
# array([102.57399925,  90.91518567,  96.21496894,  94.65084401,
#        108.58073346,  95.86990018, 104.98188584, 120.10199248,
#        112.62861545,  95.60785143,  96.53562107, 104.5531966 ,
#         83.31337293,  91.37914505, 104.92910848,  98.75686604,
#        119.35136287,  93.81557345,  89.53161014,  91.10382411,
#        100.14040537,  98.39170314, 122.30359649,  96.00884281,
#        100.54444563, 108.84181815,  98.92019439, 105.55606984,
#        103.94906636, 108.37205023])
from ministats import mean
mean(sample)
# 101.28079499555454
from ministats import var
var(sample)
# 86.42161227701393
from ministats import std
std(sample)
# 9.296322513607945

Visualizing sampling distributions

from ministats import gen_sampling_dist

nbars = gen_sampling_dist(rvN, estfunc=np.mean, n=30)
ax = sns.histplot(nbars)
ax.set_xlabel(r"$\overline{\mathbf{n}}$")
ax.set_ylabel(r"$f_{\overline{\mathbf{N}}}$");
Plot output

Confidence interval for the mean

from ministats import ci_mean
ci_mean(sample, method="a")
# [98.39692019182347, 104.16466979928568]
from ministats import ci_mean
ci_mean(sample, method="b")
# [98.67104310712713, 104.1143762353487]

One-sample hypothesis test using simulation

from ministats import simulation_test_mean
simulation_test_mean(sample, mu0=100, sigma0=10)
# 0.4744

One-sample $t$-test

from ministats import ttest_mean
ttest_mean(sample, mu0=100)
# 0.4565609669172723

Textbook

The ministats library was developed as the support code for the No Bullshit Guide to Statistics, which is an intro-to-stats textbook that uses a computational approach to teaching probability and statistics concepts. The book explains concepts using words, math formulas, visualizations, and code examples. The ministats library contains implementations of all the statistical procedures discussed in the book written as concise, easy-to-read Python code.

To learn more about the book, consult the links below:

Computational notebooks

To see examples of the ministats library in action, you can check out the computational notebooks that accompany the book.

Roadmap

Here are some tasks I need to take care of before the v1.0 release, which will be the version that accompanies the first edition of the No Bullshit Guide to Statistics:

  • add text
  • finish adding docs/
  • move plots/figures.py plotting functions to plots/book/figures.py
  • remove plots/figures plotting functions from ministats namespace
  • add more statistical tests:
    • chi-square tests for categorical data
    • one-sample equivalence test
    • two-sample equivalence test
  • add more tests

Testing

The statistical procedures implemented in the ministats library are tested against the functions from scipy.stats and statsmodels to make sure they give the same answers.

History

0.5.20 (2026-10)

  • Latest version including lots of updates based on Reading Group feedback.

0.2.0 (2023-03-28)

  • Imported plotting functions from plot_helpers.py (in main namespace for now)

0.1.0 (2023-06-29)

  • First release on PyPI.

Metadata

Release files for ministats 0.5.23

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ministats 0.5.23
File Size Uploaded Provenance Actions
ministats-0.5.23.tar.gz 174.9 kB Without provenance Details for ministats-0.5.23.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ministats 0.5.23
File Interpreter ABI Platform Actions
ministats-0.5.23-py2.py3-none-any.whl Python 2, Python 3 none any Details for ministats-0.5.23-py2.py3-none-any.whl

Total release size: 275.0 kB

Release files / ministats-0.5.23.tar.gz

Download URL ministats-0.5.23.tar.gz
Size 174.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ec28a1a655605b1559b0acfc20df3fc98b5e1fd8dbd4fb3e522619461124eb96
BLAKE2b-256 checksum
How to use checksums
b5b7294134c0f26cd4e11e15ab43a0b77815bab3d4a3bf21bb62fe8ff767fc68
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Release files / ministats-0.5.23-py2.py3-none-any.whl

Download URL ministats-0.5.23-py2.py3-none-any.whl
Size 100.1 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
cc5621ad9cf5da07b34f576c3a3fa90c6375376224b11002aa112c1b007331d5
BLAKE2b-256 checksum
How to use checksums
e215dd56a59b8c6933bd62994034726b5518afa2d3a2e933d349476628664908
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Security for ministats 0.5.23

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.

Release history Release notifications | RSS feed

This release

0.5.23 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page