Package: rct
rctWhat this package doesThis package provides tools to generate robust and balanced random assignments
followingBanerjee, Chassang, Montero, and Snowberg (2019).TheRCT,KRerandomizedRCT, andQuantileTargetingRCTclasses of
therct.designmodule implement RCT, K-rerandomized
RCT, and Quantile Targeting RCT designs described inBanerjee, Chassang, Montero, and Snowberg (2019).For each design,assignment_from_iiddraws designs selected from i.i.d. assignments;assignment_from_shuffleddraws designs selected from exchangeable
assignments guaranteed to exactly match desired sampling weights (up to
integer issues).The package allows for an arbitrary number of treatment arms, specified via
theweightsargument in each design.rctimplements various balance objectives, including:minimizing the Mahalanobis distance between the mean of selected
covariates  across treatment arms;maximizing the minimum p-value for the regression of covariates on
treatment dummies;soft blocking on selected covariates;linear combinations of existing objectives.Customizing balance objectives, besides linear combinations of existing balance functions, is straightforward. First, you can pass different
aggregating functions to theBalanceObjectiveconstructor. For instance, this would allow to maximize the mean p-value rather than the minimum p-value. Second, you can simply define a new class inheriting fromBalanceObjectiveand implementing the abstract method_balance_func.CitationTo citerctin publications, useBanerjee, Abhijit, Sylvain Chassang, Sergio Montero, and Erik Snowberg.   
A theory of experimenters. No. w23867. National Bureau of Economic Research, 2017.The correspondingbibtexentry is:@techreport{banerjee2017theory,   
  title={A theory of experimenters},   
  author={Banerjee, Abhijit and Chassang, Sylvain and Montero, Sergio and Snowberg, Erik},   
  year={2017},   
  institution={National Bureau of Economic Research}   
}InstallationThis package is tested forpython 3.6andpython 3.7under Ubuntu
Linux 16.04.You may download the package viapip:$ pip install rctthis will install all required dependencies.Alternatively, you can clone (git@github.com:sylvaingchassang/rct.git) ordownload a.zipof the repo. If you
do so you must install requirements for the package manually. Withpip, run./rct$ pip install -r requirements.txtRunning testsBefore using the package, you may want to check that unit and
integration tests pass on your machine. To this end, run./rct$ pytest --cov=. --cov-report=term-missingExamplesExample notebooks illustrate the use ofrctmodules:rct/notebooks/examples_rct.ipynbshows how to generate
traditional i.i.d. and shuffled RCT assignments for binary and ternary
treatments. Thepvalue_reportfunction provides a useful summary of
assignment balance by reporting the(#treatments -1, #covariates)matrix of p-values obtained from regressing covariates on different
treatment dummies.rct/notebooks/examples_k_rerandomized_rct.ipynbshows how to
obtain k-rerandomized i.i.d. and shuffled assignments under various balance
objectives.rct/notebooks/examples_quantile_targeting_rct.ipynbperforms a
similar exercise for quantile targeting experiment designs.Integration tests located atrct/tests/test_integration.pyreplicate
the content of these notebooks.ContributeIf you want to improverctplease reach out!Whether you are a programmer who wants to improve our code, or an experiment designer with a
practical comment, or a new design idea, we want to talk to you!On our current todo list (2019/09/20):adding type hints to improve readability;profiling & speed improvement;implementing sequential designs.