Editing

CausalStructures.add_edges — Function
add_edges(cg::CausalGraph, es::CausalEdge...) -> CausalGraph

Return a new graph of the same class with edges es added. Nodes referenced by any edge are added automatically if not already present.

  • cg::CausalGraph: the graph to add edges to.
  • es::CausalEdge...: the edges to add.

A new CausalGraph of the same class as cg.

julia> dag = DAG("A --> B");

julia> add_edges(dag, directed(:B, :C))
DAG with 3 nodes and 2 edges:
  nodes: A, B, C
  edges:
    A --> B, B --> C

julia> add_edges(dag, directed(:B, :C), directed(:C, :D))
DAG with 4 nodes and 3 edges:
  nodes: A, B, C, D
  edges:
    A --> B, B --> C, C --> D
source
CausalStructures.remove_edges — Function
remove_edges(cg::CausalGraph, es::CausalEdge...) -> CausalGraph

Return a new graph of the same class with edges es removed. Nodes that become isolated are retained. Throws ArgumentError if any edge in es is not present.

  • cg::CausalGraph: the graph to remove edges from.
  • es::CausalEdge...: the edges to remove.

A new CausalGraph of the same class as cg.

  • ArgumentError: if any edge in es is not present in cg.
julia> dag = DAG("A --> B --> C");

julia> remove_edges(dag, directed(:A, :B), directed(:B, :C))
DAG with 3 nodes and 0 edges:
  nodes: A, B, C
  edges:
    (none)
source
CausalStructures.add_nodes — Function
add_nodes(cg::CausalGraph, ns::Symbol...) -> CausalGraph

Return a new graph of the same class with isolated nodes ns added. Nodes already present are ignored.

  • cg::CausalGraph: the graph to add nodes to.
  • ns::Symbol...: the nodes to add.

A new CausalGraph of the same class as cg, or cg itself if every node in ns is already present.

julia> g = DAG("A --> B");

julia> add_nodes(g, :C, :D)
DAG with 4 nodes and 1 edge:
  nodes: A, B, C, D
  edges:
    A --> B

julia> add_nodes(g, :A) === g
true
source
CausalStructures.remove_nodes — Function
remove_nodes(cg::CausalGraph, ns::Symbol...) -> CausalGraph

Return a new graph of the same class with nodes ns and all their incident edges removed. Throws ArgumentError if any node in ns is not present.

  • cg::CausalGraph: the graph to remove nodes from.
  • ns::Symbol...: the nodes to remove.

A new CausalGraph of the same class as cg.

  • ArgumentError: if any node in ns is not present in cg.
julia> g = DAG("A --> B --> C");

julia> remove_nodes(g, :B)
DAG with 2 nodes and 0 edges:
  nodes: A, C
  edges:
    (none)

julia> remove_nodes(g, :A, :B)
DAG with 1 node and 0 edges:
  nodes: C
  edges:
    (none)
source
CausalStructures.reclass — Function
reclass(cg::CausalGraph, T::Type{<:CausalGraph}) -> T

Reinterpret cg's nodes and edges as a graph of class T. Throws an error if the edges violate the structural constraints of T.

  • cg::CausalGraph: the graph to reclass.

A new graph of class T with the same nodes and edges as cg.

julia> dag = DAG("A --> B --> C");

julia> pdag = reclass(dag, PDAG)
PDAG with 3 nodes and 2 edges:
  nodes: A, B, C
  edges:
    A --> B, B --> C
source