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

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for stochatreat-0.2.1.tar.gz
Algorithm Hash digest
SHA256 8ecd9cd2df3e37e0424d9f3177484d96db99cfc935dd571286a6ed45c5ecd812
MD5 518958a0c4f463f5b110b4faf7e87847
BLAKE2b-256 bda0454cf9dc0edac5fdc481a223d7250e8bf0d05b5899d7c039e1575e8669a5

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for stochatreat-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 62884c664fa3d9141d76a8994233a55fd51a9edb7dccea07fc33cd22446c573a
MD5 21f0be54c8fef2510cd74865a75f33e8
BLAKE2b-256 c860cb06abc03ad49bd2eeb1d90759c39810ac6c2cf72dcab534cf965e46a053

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