# Judea Pearl do-calculus using DoWhy package

I have a dataset in which the columns are the variables X,Y,Z,W,A,B. I would like to evaluate $$P(Y|do(X=x))$$. In the package DoWhy for Python, there is the example:

import dowhy.api
import dowhy.datasets

data = dowhy.datasets.linear_dataset(beta=5,
num_common_causes=1,
num_instruments = 0,
num_samples=1000,
treatment_is_binary=True)

# data['df'] is just a regular pandas.DataFrame
data['df'].causal.do(x='v0', # name of treatment variable
variable_types={'v0': 'b', 'y': 'c', 'W0': 'c'},
outcome='y',
common_causes=['W0']).groupby('v0').mean().plot(y='y', kind='bar')


With the following description:

The do method in the causal namespace generates a random sample from $$P(outcome|do(X=x))$$ of the same length as your data set, and returns this outcome as a new DataFrame. You can continue to perform the usual DataFrame operations with this sample, and so you can compute statistics and create plots for causal outcomes!

I was not able to understand however how this performs the do-calculus since what I wanted was a probability distribution, as described by Pearl himself, and not a dataframe as returned by the function; nor was I able to set $$X=x$$ in the model, only insert the variable. So, in my example, how could I use the dowhy package to give me $$P(Y|do(X=x))$$?

• Looks like the dowhy package gives you a sample conforming to the probability distribution. This is about all you could reasonably expect. What do you mean that you want the probability distribution? The theoretical one? In that case, you should try applying the do calculus by hand. Sep 23, 2020 at 22:15

If you want the expression $$P(Y | do(X))$$ via Pearl's rules, then you don't need software for that as it is known to be $$P(Y | do(X)) = \sum_Z P(Y | X,Z) P(Z)$$ - where $$Z$$ are your confounders.