如何从Dagitty导出以.gml格式的有向无环图(DAG),然后导入到dowhy中?

huangapple go评论66阅读模式
英文:

How to export DAG in .gml format from Dagitty and input into dowhy?

问题

我刚刚开始探索dowhy库进行因果推断。在用户指南部分有一个计算因果效应的基本示例。这里的一个部分说建议以GML图格式输入因果图。可以使用Dagitty生成因果图。

我该如何从Dagitty中以GML格式导出图形并输入到dowhy中?如果有人能向我展示从Dagitty导出GML格式并在dowhy中可视化图形的步骤,那就足够了。

**注意:**我对GML也是新手。我将networkx作为一个标签包括进来,因为dowhy使用networkx,从Dagitty中以GML格式获取图形并在networkx中可视化也会有帮助。

英文:

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.

答案1

得分: 1

根据这个拉取请求(以及问题),你基本上只需传递定义Dagitty dag() 的字符串。

在Dagitty的网站上,右侧有一个名为Model code的框,其中包含了你在R中编写图形定义时将使用的图形定义(而不是交互式构建)。

例如,默认的M-bias图形定义如下:

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
}

如果你将这段文本作为Python中的多行字符串,你可以将它作为CausalModelgraph参数传递给DoWhy,然后DoWhy应该能够处理它。

英文:

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.

huangapple
  • 本文由 发表于 2023年1月9日 15:53:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/75054414.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定