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
6.99k stars 923 forks source link

Causal Effect of Common Causes to Outcome #466

Open AradAshrafi opened 2 years ago

AradAshrafi commented 2 years ago

Hello,

Thanks for this amazing library.
I am using dowhy.datasets.linear_dataset to create a linear dataset. Using beta, I can specify the effect of treatment on outcome. Is it possible to get the true causal effect of each of the common causes on the outcome?

For more details about the code, I am using this code to generate data:

dowhy.datasets.linear_dataset(beta=10, num_common_causes=5, num_instruments = 2, num_treatments=1, num_samples=10000, treatment_is_binary=True, outcome_is_binary=True, stddev_treatment_noise=10)

In this case, I know the causal effect of treatment on the outcome is 10. I am interested in knowing the causal effect of those 5 common causes on the outcome.

AradAshrafi commented 2 years ago

Ok. I found this way which requires adding very small changes to the datasets class of the library. I found out that the causal effect I am looking for is denoted by variable c2. In line 155 datasets class the causal effect of common_causes is taken into account:

if num_common_causes > 0: y += W @ c2

I am just returning this value manually.

Please let me know if there is a better way to get those c2 amounts without changing any code.

amit-sharma commented 2 years ago

yes, that is correct. c2 is the causal effect of W. This can be added as a parameter to return all coefficients (return_all_cofficients to the linear_dataset method). I will keep this for the next release.

AradAshrafi commented 2 years ago

Hi Again @amit-sharma ,

I have one more similar question. In an observational dataset, I am interested in finding the causal effect of all nodes based on my assumed causal graph. Can I do that using the library? Since model.estimate_effect returns only the causal effect of treatment on the outcome, in my case, I want to know the true causal effect of confounders on the outcome as well.

amit-sharma commented 2 years ago

Given a causal graph, you can rerun the analysis specifying any of the variables as the treatment node. We do not support outputting the causal effect on confounders, because most methods focus on the effect parameter for treatment. Estimating the effect of each confounder also requires additional assumptions (that the confounder and the outcome do not share any unobserved common cause), so it is best to consider each such question as a separate analysis which you can run in a loop using dowhy.