Skip to main content

Stratified random assignment using pandas

Project description

Stochatreat

stochatreat logo

typing-and-tests Coverage Status pypi PyPI Downloads Conda conda-downloads Hatch project linting - Ruff ty License - MIT


Stratified random treatment assignment using pandas. Designed for randomized controlled trials (RCTs) — assign treatments across any number of strata, with equal or unequal probabilities, and let stochatreat handle the misfits.

Installation

pip install stochatreat
# or
conda install -c conda-forge stochatreat

Quick start

from stochatreat import stochatreat
import numpy as np
import pandas as pd

df = pd.DataFrame({"id": range(1000), "nhood": np.random.randint(1, 6, 1000)})

treats = stochatreat(data=df, stratum_cols="nhood", treats=2, idx_col="id", random_state=42)
df = df.merge(treats, how="left", on="id")

For full documentation and examples visit manmartgarc.github.io/stochatreat.

Contributing

Read the contributing guide.

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

stochatreat-0.2.5.tar.gz (6.4 MB view details)

Uploaded Source

Built Distribution

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

stochatreat-0.2.5-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file stochatreat-0.2.5.tar.gz.

File metadata

  • Download URL: stochatreat-0.2.5.tar.gz
  • Upload date:
  • Size: 6.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for stochatreat-0.2.5.tar.gz
Algorithm Hash digest
SHA256 000b95f6997b7fdc67c3cf52461e44f77123d3f1546065d9d1855957c91e1fb2
MD5 88c10236f09b6996a06c8eed31b74016
BLAKE2b-256 5d8a266545d9d3d58c0ccc295baadd254bf09c5963c58173af64e281c1ce5ee7

See more details on using hashes here.

Provenance

The following attestation bundles were made for stochatreat-0.2.5.tar.gz:

Publisher: release-and-publish.yml on manmartgarc/stochatreat

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file stochatreat-0.2.5-py3-none-any.whl.

File metadata

  • Download URL: stochatreat-0.2.5-py3-none-any.whl
  • Upload date:
  • Size: 10.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for stochatreat-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 28e8fbc71d977cb58a6f23c1c72a1c478ae8a410971d9bab6fc5ec83cc757ab0
MD5 213603fea74479ec5bc23ae9cd9449e5
BLAKE2b-256 b7854a2bd99f15892edb98d971ca7ab73588892779f7c41f511490564f835d36

See more details on using hashes here.

Provenance

The following attestation bundles were made for stochatreat-0.2.5-py3-none-any.whl:

Publisher: release-and-publish.yml on manmartgarc/stochatreat

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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