Package: y0
y0y0(pronounced "why not?") is Python code for causal inference.💪 Getting StartedRepresenting Probability Expressionsy0has a fully featured internal domain specific language for representing
probability expressions:fromy0.dslimportP,A,B# The probability of A given Bexpr_1=P(A|B)# The probability of A given not Bexpr_2=P(A|~B)# The joint probability of A and Bexpr_3=P(A,B)It can also be used to manipulate expressions:fromy0.dslimportP,A,B,SumP(A,B).marginalize(A)==Sum[A](P(A,B))P(A,B).conditional(A)==P(A,B)/Sum[A](P(A,B))DSL objects can be converted into strings withstr()and parsed back
usingy0.parser.parse_y0().A full demo of the DSL can be found in thisJupyter NotebookRepresenting Causalityy0has a notion of acyclic directed mixed graphs built on top ofnetworkxthat can be used to model causality:fromy0.graphimportNxMixedGraphfromy0.dslimportX,Y,Z1,Z2# Example from:#   J. Pearl and D. Mackenzie (2018)#   The Book of Why: The New Science of Cause and Effect.#   Basic Books, p. 240.napkin=NxMixedGraph.from_edges(directed=[(Z2,Z1),(Z1,X),(X,Y),],undirected=[(Z2,X),(Z2,Y),],)y0has many pre-written examples iny0.examplesfrom Pearl, Shpitser,
Bareinboim, and others.do Calculusy0providesactualimplementations of many algorithms that have remained
unimplemented for the last 15 years of publications including:AlgorithmReferenceIDShpitser and Pearl, 2006IDCShpitser and Pearl, 2008ID*Shpitser and Pearl, 2012IDC*Shpitser and Pearl, 2012Surrogate OutcomesTikka and Karvanen, 2018Apply an algorithm to an ADMG and a causal query to generate an estimand
represented in the DSL like:fromy0.dslimportP,X,Yfromy0.examplesimportnapkinfromy0.algorithm.identifyimportIdentification,identify# TODO after ID* and IDC* are done, we'll update this interfacequery=Identification.from_expression(graph=napkin,query=P(Y@X))estimand=identify(query)assertestimand==P(Y@X)🚀 InstallationThe most recent release can be installed fromPyPIwith:$pipinstally0The most recent code and data can be installed directly from GitHub with:$pipinstallgit+https://github.com/y0-causal-inference/y0.git👐 ContributingContributions, whether filing an issue, making a pull request, or forking, are appreciated. SeeCONTRIBUTING.mdfor more information on getting
involved.👋 Attribution⚖️ LicenseThe code in this package is licensed under theBSD-3-Clause
license.📖 CitationBefore we publish an application note ony0, you can cite this software
via our Zenodo record (also see the badge above):@software{y0,author={Charles Tapley Hoyt andJeremy Zucker andMarc-Antoine Parent},title={y0-causal-inference/y0},month=jun,year=2021,publisher={Zenodo},version={v0.1.0},doi={10.5281/zenodo.4950768},url={https://doi.org/10.5281/zenodo.4950768}}🙏 SupportersThis project has been supported by several organizations (in alphabetical order):Harvard Program in Therapeutic Science - Laboratory of Systems PharmacologyPacific Northwest National Laboratory💰 FundingThe development of the Y0 Causal Inference Engine has been funded by the following grants:Funding BodyProgramGrantDARPAAutomating Scientific Knowledge Extraction (ASKE)HR00111990009PNNL Data Model Convergence InitiativeCausal Inference and Machine Learning Methods for Analysis of Security Constrained Unit Commitment (SCY0)90001DARPAAutomating Scientific Knowledge Extraction and Modeling (ASKEM)HR00112220036🍪 CookiecutterThis package was created with@audreyfeldroy'scookiecutterpackage using@cthoyt'scookiecutter-python-packagetemplate.🛠️ DevelopmentSee developer instructionsThe final section of the README is for if you want to get involved by making a code contribution.Developer InstallationTo install in development mode, use the following:$gitclonegit+https://github.com/y0-causal-inference/y0.git
$cdy0
$pipinstall-e.❓ TestingAfter cloning the repository and installingtoxwithpip install tox, the unit tests in thetests/folder can be
run reproducibly with:$toxAdditionally, these tests are automatically re-run with each commit in aGitHub Action.📦 Making a ReleaseAfter installing the package in development mode and installingtoxwithpip install tox, the commands for making a new release are contained within thefinishenvironment
intox.ini. Run the following from the shell:$tox-efinishThis script does the following:Uses BumpVersion to switch the version number in thesetup.cfgandsrc/y0/version.pyto not have the-devsuffixPackages the code in both a tar archive and a wheelUploads to PyPI usingtwine. Be sure to have a.pypircfile configured to avoid the need for manual input at this
stepPush to GitHub. You'll need to make a release going with the commit where the version was bumped.Bump the version to the next patch. If you made big changes and want to bump the version by minor, you can
usetox -e bumpversion minorafter.