dagitty()
DAGitty model text for a networkx graph.
::
import networkx as nx
Usage
dagitty(
graph: Any,
*,
pos: Mapping[Any, Any] | None = None,
y: str | None = None,
) -> str
Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| graph required | Any |
A |
|
| pos | Mapping[Any, Any] | None | None |
Positions by node, such as |
| y | str | None | None |
Which way y points in the positions: |
Value
The DAGitty model text.
Details
g = nx.DiGraph() g.add_node("smoking", role="exposure", label="Smoking status") g.add_node("cancer", role="outcome") g.add_edges_from([("age", "smoking"), ("age", "cancer"), ("smoking", "cancer")]) print(fw.dagitty(g))
The text opens with dag {, lists every node with its roles and position, then
every edge. R's dagitty and ggdag and dagitty.net read it. A name that isn't a plain
identifier, such as parental SES, is double-quoted.
The graph's node and edge attributes say what DAGitty needs:
role:"exposure","outcome","latent","adjusted", or"selected", or a list of them. A pgmpyDAG'slatentsare latent too.pos: an(x, y)position, asnx.draw(G, pos)takes it: y points up. DAGitty's y points down, so y is negated in the text, and the drawing on Framework Cloud matchesnx.draw().y="down"writes positions as they are.label: the name to show.dagitty()leaves labels out;publish_dag()sends them.bidirected=Trueon an edge:a <-> b, a latent common cause. The edge's direction doesn't matter, and it isn't part of the cycle check.
Raises
FrameworkError: The graph is undirected or has a directed cycle, a node points to itself, or a role or position isn't valid.