Editing
CausalStructures.add_edges — Function
add_edges(cg::CausalGraph, es::CausalEdge...) -> CausalGraphReturn a new graph of the same class with edges es added. Nodes referenced by any edge are added automatically if not already present.
Examples
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 --> DCausalStructures.remove_edges — Function
remove_edges(cg::CausalGraph, es::CausalEdge...) -> CausalGraphReturn 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.
Examples
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)CausalStructures.add_nodes — Function
add_nodes(cg::CausalGraph, ns::Symbol...) -> CausalGraphReturn a new graph of the same class with isolated nodes ns added. Nodes already present are ignored.
Examples
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
trueCausalStructures.remove_nodes — Function
remove_nodes(cg::CausalGraph, ns::Symbol...) -> CausalGraphReturn 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.
Examples
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)CausalStructures.reclass — Function
reclass(cg::CausalGraph, T::Type{<:CausalGraph}) -> TReturn a new graph of class T with the same nodes and edges as cg. Throws an error if the edges violate the structural constraints of T.
Examples
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