Skip to content

Judea Pearl’s Causal Ladder, featuring Association, Intervention, and Counterfactual models.

Notifications You must be signed in to change notification settings

SunilGolden/causal-ladder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Causal Ladder

Usage Guide

1. Create a virtual environment

python -m venv env

2. Activate the virtual environment

For macOS / Linux

source env/bin/activate

For Windows

env\Scripts\Activate.ps1

3. Install pip-tools

pip install pip-tools

4. Install project dependencies

pip-sync

A. Generate Synthetic Data

i. Vision Dataset

python -m scripts.generate_synthetic_vision_data --n_samples 10000 --output_filename vision_data.csv --data_dir data

ii. Kidney Stone Dataset

python -m scripts.generate_synthetic_kidney_stone_data --output_filename kidney_data.csv --data_dir data

B. Run Rung 1 (Association)

python -m scripts.run_rung1 [FLAGS]

Flags

  • --data_path: Path to CSV data file. Default: ./data/kidney_data.csv
  • --treatment_col: Column name for treatment. Default: Treatment
  • --condition_col: Column name for condition. Default: Stone_Size
  • --outcome_col: Column name for outcome. Default: Success
  • --stratify: If provided, results are stratified by the condition variable.

Example

python -m scripts.run_rung1 --data_path ./data/kidney_data.csv --stratify

C. Run Rung 2 (Intervention)

python -m scripts.run_rung2 [FLAGS]

Flags

  • --data_path: Path to CSV data file. Default: ./data/kidney_data.csv
  • --random_seed: Seed for reproducibility. Default: 42
  • --treatment_col: Column name for treatment. Default: Treatment
  • --condition_col: Column name for condition. Default: Stone_Size
  • --outcome_col: Column name for outcome. Default: Success

Example

python -m scripts.run_rung2 --data_path ./data/kidney_data.csv --treatment_col Treatment --outcome_col Success

D. Run Rung 3 (Counterfactual)

python -m scripts.run_rung3 [FLAGS]

Flags

  • --data_path: Path to CSV data file. Default: ./data/vision_data.csv
  • --sample_condition: The specific condition value of the patient. Default: 1
  • --sample_treatment: The actual treatment the patient received. Default: 2
  • --sample_outcome: The actual outcome the patient experienced. Default: 0.883874
  • --new_treatments: Space-separated list of alternative treatments to simulate. Default: 0 1
  • --treatment_col: Column name for treatment. Default: Treatment
  • --condition_col: Column name for condition. Default: Condition
  • --outcome_col: Column name for outcome. Default: Vision

Example

python -m scripts.run_rung3 --data_path ./data/vision_data.csv --sample_condition 1 --sample_treatment 2 --sample_outcome 0.88 --new_treatments 0 1

References

About

Judea Pearl’s Causal Ladder, featuring Association, Intervention, and Counterfactual models.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages