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.

Home Page:https://www.pywhy.org/dowhy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Сausal effect for non-linear relationship

sinya2 opened this issue · comments

Few years ago it was an assumption that in the later versions would be possibility to evaluate causal effect depends on value of the treatment.
For example, E( outcome=1|t=k)-E(outcome|t=k-1)) for any k.

Is it implemented now? Where I could find the examples?

Thank you!

Yes, the functionality to specify control and treatment values for a continuous treatment variable is implemented now.
For an example, check out cell 7 this notebook: https://www.pywhy.org/dowhy/v0.10.1/example_notebooks/dowhy-conditional-treatment-effects.html

tval1, tval2 = 10, 20
linear_estimate = model.estimate_effect(identified_estimand,
                                        method_name="backdoor.linear_regression",
                                       control_value=tval1,
                                       treatment_value=tval2)

For a non-linear relationship, the same API is used, just the estimator is changed.

dml_estimate = model.estimate_effect(identified_estimand, method_name="backdoor.econml.dml.DML",
                                     control_value = 0,
                                     treatment_value = 1,
                                 target_units = lambda df: df["X0"]>1,  # condition used for CATE
                                 confidence_intervals=False,
                                method_params={"init_params":{'model_y':GradientBoostingRegressor(),
                                                              'model_t': GradientBoostingRegressor(),
                                                              "model_final":LassoCV(fit_intercept=False),
                                                              'featurizer':PolynomialFeatures(degree=1, include_bias=False)},
                                               "fit_params":{}})