I have just started exploring dowhy library for causal inference. In the user guide section there is a basic example to calculate the causal effect. A section here says that it is recommended to input the causal graph in GML graph format. The causal graph can be generated in Dagitty.
How can I export the graph in GML format from Dagitty and input into dowhy? If someone can show me the steps to export the GML format from Dagitty and visualize the graph in dowhy, that would be enough.
Note: I am new to GML as well. Am including networkx as a tag as dowhy uses networkx and getting the graph in GML format from Dagitty and visualizing it in networkx would help as well.
According to this pull request (and issue), you can basically just pass the string defining a Dagitty dag()
.
On Dagitty's website there is a Model code
box on the right, which is the graph definitions you would use if you were coding it in R (and not building it interactively).
For example, the default M-bias graph is defined as
dag {
A [pos="-2.200,-1.520"]
B [pos="1.400,-1.460"]
D [outcome,pos="1.400,1.621"]
E [exposure,pos="-2.200,1.597"]
Z [pos="-0.300,-0.082"]
A -> E
A -> Z [pos="-0.791,-1.045"]
B -> D
B -> Z [pos="0.680,-0.496"]
E -> D
}
If you were to take this text as a multi-line string in Python, you could pass it as a CausalModel
graph
parameter and DoWhy should be able to take it from there.