%config InlineBackend.figure_format = "svg"
In [1]:
In [2]:
import networkx as nx
import matplotlib.pyplot as plt
In [8]:
= plt.subplots(1, 1, figsize=(3, 1.5))
fig, ax
= nx.DiGraph([
G "$A$", "$Y$"),
(# ("$X_0$", None),
"$X_A$", "$A$"),
("$X_{AY}$", "$A$"), ("$X_{AY}$", "$Y$"),
("$X_Y$", "$Y$"),
(
])"$X_0$")
G.add_node(= {
pos "$A$":[0,0], "$Y$":[5,0],
"$X_0$":[1, 2], "$X_A$":[2,2],
"$X_{AY}$":[3, 2], "$X_Y$":[4, 2],
}
=pos, ax=ax, with_labels=True, node_color="white") nx.draw(G, pos
In [9]:
= plt.subplots(1, 1, figsize=(3, 1.5))
fig, ax
= nx.DiGraph([
G "$A$", "$Y$"),
("$X_A$", "$A$"),
("$X_{AY}$", "$A$"), ("$X_{AY}$", "$Y$"),
("$X_Y$", "$Y$"),
(
])"$X_0$")
G.add_node(= {
pos "$A$":[0,0], "$Y$":[5,0],
"$X_0$":[1, 2], "$X_A$":[2,2],
"$X_{AY}$":[3, 2], "$X_Y$":[4, 2],
}
=pos, ax=ax, with_labels=True, node_color="white")
nx.draw(G, pos
nx.draw_networkx_edges(=pos,
G, pos=[
edgelist"$X_0$", "$A$"), ("$X_0$", "$Y$"),
("$X_A$", "$Y$"), ("$X_Y$", "$A$"),
(
],="--",
style="0.25",
edge_color=ax,
ax; )
In [15]:
= plt.subplots(1, 2, figsize=(10, 2.5))
fig, axes
= nx.DiGraph([
G "$A$", "$Y$"),
("$X_A$", "$A$"),
("$X_{AY}$", "$A$"), ("$X_{AY}$", "$Y$"),
("$X_Y$", "$Y$"),
(
])"$X_0$")
G.add_node(= {
pos "$A$":[0,0], "$Y$":[5,0],
"$X_0$":[1, 2], "$X_A$":[2,2],
"$X_{AY}$":[3, 2], "$X_Y$":[4, 2],
}
=pos, ax=axes[1], with_labels=True, node_color="white", font_size=14)
nx.draw(G, pos=pos, ax=axes[0], with_labels=True, node_color="white", font_size=14)
nx.draw(G, pos
nx.draw_networkx_edges(=pos,
G, pos=[
edgelist"$X_0$", "$A$"), ("$X_0$", "$Y$"),
("$X_A$", "$Y$"), ("$X_Y$", "$A$"),
(
],="--",
style="#9e3434", # "#d12e2e"
edge_color=axes[0],
ax
)0].set_title("Assumed confounding structure", fontsize=14, pad=12)
axes[1].set_title("Actual confounding structure", fontsize=14, pad=12);
axes[=0);
fig.subplots_adjust(wspace# fig.tight_layout();