This example demonstrates how to implement a simple Rubin Causal Model (RCM) scenario using the DeepCausality library. It showcases the Effect Propagation Process (EPP)'s capability for Contextual Alternation to directly compute potential outcomes and determine an individual treatment effect.
From the root of the deep_causality project, run:
cargo run -p classical_causality_examples --example rcm_exampleThe RCM defines a causal effect by comparing two "potential outcomes" for a single unit: the outcome if the unit receives a treatment (Y(1)) versus the outcome if it does not (Y(0)). The fundamental challenge is that only one of these outcomes can be observed in reality.
DeepCausality, as an implementation of the EPP, addresses this challenge by separating the causal model (the "science" or physiological response) from its context (the patient's state). This allows for the computational simulation of both potential outcomes:
- Factual Context: Represents the real-world state of a unit.
- Counterfactual Contexts: Cloned from the factual context and modified to represent hypothetical scenarios (e.g., drug administered vs. not administered).
By evaluating the same causal model against these different contexts, DeepCausality can compute both Y(1) and Y(0), thereby enabling the calculation of the Individual Treatment Effect (ITE).
Goal: For a specific patient, determine the causal effect of a new drug on their blood pressure.
drug_effect_causaloid: ACausaloidwhosecausal_fndetermines the drug's effect (e.g., -10.0 BP reduction if administered, 0.0 otherwise). This causaloid expects aPropagatingEffect::Mapas input, containing a flag fordrug_administeredand theinitial_blood_pressure.final_bp_causaloid: ACausaloidwhosecausal_fncalculates the final blood pressure by adding thedrug_effectto theinitial_blood_pressure. It also expects aPropagatingEffect::Mapas input.CausaloidGraph: A simple linear graph (drug_effect_causaloid->final_bp_causaloid) representing the flow of calculation.
- A
BaseContextis created to represent the patient's initial state, containing aDatoidfor theirinitial_blood_pressure(e.g., 145.0).
treatment_context: A clone of thepatient_baseline_contextwith aDatoidindicatingdrug_administered = 1.0(representingtrue).control_context: A clone of thepatient_baseline_contextwith aDatoidindicatingdrug_administered = 0.0(representingfalse).
- The
CausaloidGraphis evaluated twice, once with thetreatment_context(to get Y(1)) and once with thecontrol_context(to get Y(0)). - The
PropagatingEffect::Mapis used to pass all necessary contextual data (initial BP, drug administered status) through the causal graph during evaluation.
- The Individual Treatment Effect (ITE) is calculated as
Y(1) - Y(0). - The result is printed, demonstrating the drug's predicted effect on the patient's blood pressure.
For more information on the EPP, please see chapter 5 in the EPP document: https://github.com/deepcausality-rs/papers/blob/main/effect_propagation_process/epp.pdf