Utilities

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

CausalDynamics.stable_hash64 — Function
stable_hash64(value) -> UInt64

Return a deterministic 64-bit digest of a canonical textual value. Unlike Base.hash, this value is intended for persisted certificates and cross-version reproducibility.

source
CausalDynamics.stable_seed — Function
stable_seed(parts...) -> UInt

Derive a deterministic seed from declared primitive or otherwise canonically represented components. Length prefixes prevent delimiter collisions.

source
CausalDynamics.stable_rng_seed — Function
stable_rng_seed(rng) -> UInt

Derive a seed from a copy of rng without advancing the supplied generator. Cross-version stability depends on the RNG implementation; use an RNG with an explicit stability guarantee, such as StableRNG, when persisted results must reproduce across Julia releases.

source
CausalDynamics.plot_causal_graph — Function
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_paths — Function
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

Temporal unrollings are plotted with DAGMakie.dagplot_temporal (CausalDynamics extension method on TemporalUnrolling).

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),
    fit_node_size_to_labels = false,
    node_size = 28,
)
fig
Example block output

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