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.1.6.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.1.6-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: stochatreat-0.1.6.tar.gz
  • Upload date:
  • Size: 6.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.3 cpython/3.13.6 HTTPX/0.28.1

File hashes

Hashes for stochatreat-0.1.6.tar.gz
Algorithm Hash digest
SHA256 84ec788a4e753947dd00d7c4525080026375b082bb8ce23a9b82e5288539630d
MD5 a2aa2dacb29ea1f8ad8de57f8d3fd700
BLAKE2b-256 c130565a5aeb94431108abdc69ce355b61bb4f4e79a40c12257070f631f008e5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: stochatreat-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.3 cpython/3.13.6 HTTPX/0.28.1

File hashes

Hashes for stochatreat-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 960d2786bba71c81b243d81c5630bea20fe60432dc69ab7547c0b850ea72d6db
MD5 65e5c86ba2803533811f6fcb9ca5573a
BLAKE2b-256 9a832866146f1652589201e8a7df46caf5a82f510035d23bfa942d1fdf5d4948

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