Skip to main content

Randomization inference in Python.

Project description

ritest

PyPI version Python versions CI License: MIT

Overview

ritest provides fast randomization inference (RI) tools for linear models and arbitrary statistics. It supports weights (WLS) as well as stratified and clustered designs.

📑 Documentation: https://tabarecapitan.com/projects/ritest.

Features

  • Linear-model RI with efficient computation.
  • Generic RI for arbitrary scalar statistics via stat_fn.
  • Stratified, clustered, and stratified-clustered designs.
  • Weighted least squares (WLS) support.
  • Deterministic seeding, reproducible permutations.
  • Configurable p-value and ultra-fast coefficient bounds and bands.

Installation

From PyPI:

pip install ritest-python

Optional extras:

pip install ritest-python[plot]      # plotting support
pip install ritest-python[numba]     # Numba acceleration

Quickstart

Linear model (formula interface)

import pandas as pd
from ritest import ritest

df = pd.DataFrame({
    "y": [1, 2, 3, 4],
    "treat": [0, 1, 0, 1],
    "x": [5, 6, 7, 8],
})

res = ritest(
    df=df,
    permute_var="treat",
    formula="y ~ treat + x",
    stat="treat",
    reps=1000,
)

print(res.summary())

Custom statistic (stat_fn)

def my_stat(df):
    return df["y"].corr(df["treat"])

res = ritest(
    df=df,
    permute_var="treat",
    stat_fn=my_stat,
    reps=1000,
)

print(res.pvalue)

Citation

A software citation entry will be provided once the package reaches its first stable release and the accompanying paper/notes are finalized. For now, cite the GitHub repository:

Tabaré Capitán (2025). ritest: Randomization inference in Python.
https://github.com/tabareCapitan/ritest

Disclaimer

Use this software at your own risk. I make no guarantees of correctness or fitness for any purpose. I use it in my own work, but you should review the code to ensure it meets your needs. If you find an issue, please report it.

Contributing and issues

Bug reports and feature requests can be filed at:

https://github.com/tabareCapitan/ritest/issues

Pull requests should be focused and include tests for new behavior.

License

MIT License. See the LICENSE file for full terms.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ritest_python-0.1.1.tar.gz (54.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ritest_python-0.1.1-py3-none-any.whl (34.1 kB view details)

Uploaded Python 3

File details

Details for the file ritest_python-0.1.1.tar.gz.

File metadata

  • Download URL: ritest_python-0.1.1.tar.gz
  • Upload date:
  • Size: 54.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for ritest_python-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a32695bbc6ce29be75b34f171649241beeba7fb3dd5eecc8e6fbda44936bf43d
MD5 a72d511f3f85a7f0a727c56de6555a54
BLAKE2b-256 4c706b7a703c60c5ac24ff4415684e3a87cf2c6472e257e03ca181910152cb88

See more details on using hashes here.

File details

Details for the file ritest_python-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: ritest_python-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 34.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for ritest_python-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8f4d667bb7099e15a67894f578d40a05ff0e57c33ee799c7fce043f02ec331c1
MD5 b6109a0d1b759ea969c70182c01e4cf6
BLAKE2b-256 870ce9b4ac709b81770d14643db41007dcc138d5d99083bf83bce94bcaa704e8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page