pywhy_graphs.ADMG#

class pywhy_graphs.ADMG(incoming_directed_edges=None, incoming_bidirected_edges=None, incoming_undirected_edges=None, directed_edge_name: str = 'directed', bidirected_edge_name: str = 'bidirected', undirected_edge_name: str = 'undirected', **attr)[source]#

Acyclic directed mixed graph (ADMG).

A causal graph with two different edge types: bidirected and traditional directed edges. Directed edges constitute causal relations as a causal DAG did, while bidirected edges constitute the presence of a latent confounder.

Parameters:
incoming_directed_edgesinput directed edges (optional, default: None)

Data to initialize directed edges. All arguments that are accepted by networkx.DiGraph are accepted.

incoming_bidirected_edgesinput bidirected edges (optional, default: None)

Data to initialize bidirected edges. All arguments that are accepted by networkx.Graph are accepted.

incoming_undirected_edgesinput undirected edges (optional, default: None)

Data to initialize undirected edges. All arguments that are accepted by networkx.Graph are accepted.

directed_edge_namestr

The name for the directed edges. By default ‘directed’.

bidirected_edge_namestr

The name for the bidirected edges. By default ‘bidirected’.

undirected_edge_namestr

The name for the directed edges. By default ‘undirected’.

attrkeyword arguments, optional (default= no attributes)

Attributes to add to graph as key=value pairs.

Notes

Edge Type Subgraphs

The data structure underneath the hood is stored in two networkx graphs: networkx.Graph and networkx.DiGraph to represent the non-directed edges and directed edges. Non-directed edges in an ADMG can be present as bidirected edges standing for latent confounders, or undirected edges standing for selection bias.

  • Directed edges (<-, ->, indicating causal relationship) = networkx.DiGraph

    The subgraph of directed edges may be accessed by the ADMG.sub_directed_graph. Their edges in networkx format can be accessed by ADMG.directed_edges and the corresponding name of the edge type by ADMG.directed_edge_name.

  • Bidirected edges (<->, indicating latent confounder) = networkx.Graph

    The subgraph of bidirected edges may be accessed by the ADMG.sub_bidirected_graph. Their edges in networkx format can be accessed by ADMG.bidirected_edges and the corresponding name of the edge type by ADMG.bidirected_edge_name.

  • Undirected edges (–, indicating selection bias) = networkx.Graph

    The subgraph of undirected edges may be accessed by the ADMG.sub_undirected_graph. Their edges in networkx format can be accessed by ADMG.undirected_edges and the corresponding name of the edge type by ADMG.undirected_edge_name.

By definition, no cycles may exist due to the directed edges. However, beyond that multiple types of edges between the same pairs of nodes are possible.

property bidirected_edge_name: str#

Name of the bidirected edge internal graph.

property bidirected_edges: Mapping#

EdgeView of the bidirected edges.

c_components() Iterator[Set][source]#

Generate confounded components of the graph.

Note the trivial c-component of a node without bidirected edges is the node themself.

Returns:
compiterator of sets

The c-components.

property directed_edge_name: str#

Name of the directed edge internal graph.

property directed_edges: Mapping#

EdgeView of the directed edges.

sub_bidirected_graph() Graph[source]#

Sub-graph of just the bidirected edges.

sub_directed_graph() DiGraph[source]#

Sub-graph of just the directed edges.

sub_undirected_graph() Graph[source]#

Sub-graph of just the undirected edges.

property undirected_edge_name: str#

Name of the undirected edge internal graph.

property undirected_edges: Mapping#

EdgeView of the undirected edges.

Examples using pywhy_graphs.ADMG#

An introduction to Inducing Paths and how to find them

An introduction to Inducing Paths and how to find them

An introduction to causal graphs and how to use them

An introduction to causal graphs and how to use them

On PAGs and their validity

On PAGs and their validity

Drawing graphs and setting their layout for visual comparison

Drawing graphs and setting their layout for visual comparison