py-why / dowhy

DoWhy is a Python library for causal inference that supports explicit modeling and testing of causal assumptions. DoWhy is based on a unified language for causal inference, combining causal graphical models and potential outcomes frameworks.
https://www.pywhy.org/dowhy
MIT License
7.15k stars 935 forks source link

Do operator #1251

Closed lucasmarques2003 closed 1 month ago

lucasmarques2003 commented 2 months ago

I just wanted to estimate a simple do operation, for example $E(Y|do(X))$ and I can't find an easy way on the documentation. I used dowhy.causal_model.do but it just didn't work

emrekiciman commented 2 months ago

Hi Lucas,

This page provides simple examples for estimating treatment (X) effects on an outcome (Y). https://www.pywhy.org/dowhy/v0.11.1/example_notebooks/dowhy_simple_example.html

model=CausalModel(
        data = df,
        treatment=data["treatment_name"],
        outcome=data["outcome_name"],
        graph=data["gml_graph"]
        )
identified_estimand = model.identify_effect(proceed_when_unidentifiable=True)
causal_estimate = model.estimate_effect(identified_estimand,
        method_name="backdoor.propensity_score_stratification")
print(causal_estimate)

Treatment (X) and output variables (Y) are specified when you initialize the CausalModel. If you don't have a graph but just happen to know what your confounders are, there are instructions on that page for how to initialize a canonical causal model.

The identification step figures out how to calculate E(Y|do(X)) for a specific graph; and then estimation actually does the calculation.

github-actions[bot] commented 2 months ago

This issue is stale because it has been open for 14 days with no activity.

github-actions[bot] commented 1 month ago

This issue was closed because it has been inactive for 7 days since being marked as stale.