4
$\begingroup$

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))$?

$\endgroup$
1
  • $\begingroup$ 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. $\endgroup$ Sep 23, 2020 at 22:15

1 Answer 1

2
$\begingroup$

I believe you are confusing a "sample from a distribution", and the "analytical equation of the distribution?" No software (well, very few) will actually give you an analytical equation, but they will provide samples, which you then plot using "histogram" to observe the equation P(Y | do(X)) empirically. Hence why it returns the samples as a "dataframe object".

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.