Skip to content

manmartgarc/stochatreat

Repository files navigation

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.

About

This is a Python tool to employ stratified sampling or treatment randomization with uneven numbers in some strata using pandas. Mainly thought with RCTs in mind, it also works for any other scenario in where you would like to randomly allocate treatment within blocks or strata. The tool also supports having multiple treatments with different pro…

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages