Utilities

Optional plotting requires DAGMakie.jl (using DAGMakie). See the DAGMakie docs for layout, themes, and path-highlighting conventions.

CausalDynamics.plot_causal_graphFunction
plot_causal_graph(g; node_labels, highlight_nodes, highlight_edges, kwargs...)

Plot a causal graph with optional node labels and highlighting.

Requires using DAGMakie. Returns a Makie Figure (via DAGMakie).

Arguments

  • g::AbstractGraph: The causal graph to plot
  • node_labels: Optional labels for nodes (default: node indices)
  • highlight_nodes::Set{Int}: Nodes to highlight
  • highlight_edges: Edges to highlight as (src, dst) tuples
  • kwargs...: Forwarded to DAGMakie plotting helpers

Example

using CausalDynamics, Graphs, DAGMakie, CairoMakie

g = DiGraph(3)
add_edge!(g, 1, 2)
add_edge!(g, 1, 3)
add_edge!(g, 2, 3)

fig = plot_causal_graph(g;
    node_labels = ["Z", "X", "Y"],
    highlight_nodes = Set([1]),
)
source
CausalDynamics.plot_backdoor_pathsFunction
plot_backdoor_paths(g, X, Y; node_labels, kwargs...)

Plot a causal graph highlighting backdoor paths from treatment X to outcome Y.

Requires using DAGMakie. Uses DAGMakie's dagplot_backdoor with the CausalDynamics find_backdoor_paths / adjustment helpers where useful.

source

Live example

using CausalDynamics, Graphs, DAGMakie, CairoMakie

g = DiGraph(3)
add_edge!(g, 1, 2)
add_edge!(g, 1, 3)
add_edge!(g, 2, 3)

fig = plot_causal_graph(g;
    node_labels = ["Z", "X", "Y"],
    highlight_nodes = Set([1]),
)
fig
Example block output

Temporal unrolling

using CausalDynamics, DAGMakie, CairoMakie

spec = TemporalDAGSpec([:a, :y], [(:a, :y, 0), (:a, :a, 1), (:y, :y, 1)])
u = unroll_temporal_dag(spec, 4)
fig, ax, p = dagplot_temporal(u; figure_size = (560, 240))
fig
Example block output

For raw Graphs without a TemporalUnrolling, use DAGMakie.dagplot_time_indexed (see the DAGMakie skeletons & time guide).