API#
Causal modeling with structural causal models and causal graphs.
This is the application programming interface (API) reference
for classes (CamelCase
names) and functions
(underscore_case
names) of Causal-Networkx, grouped thematically by analysis
stage.
Most-used classes#
These are the causal classes for Structural Causal Models (SCMs), or various causal graphs encountered in the literature.
|
Structural Causal Model (SCM) class. |
|
Causal directed acyclic graph. |
|
Completed partially directed acyclic graphs (CPDAG). |
|
Acyclic directed mixed graph (ADMG). |
|
Partial ancestral graph (PAG). |
To see a breakdown of different inner graph functionalities, see the Graph API page. See
- DAG
- Overview
- causal_networkx.graphs.base.MarkovianGraph
- causal_networkx.graphs.base.SemiMarkovianGraph
- causal_networkx.graphs.base.MarkovEquivalenceClass
- Copying
- Information about nodes and edges
- causal_networkx.graphs.dag.DAG.name
- causal_networkx.graphs.dag.DAG.parents
- causal_networkx.graphs.dag.DAG.children
- causal_networkx.graphs.dag.DAG.successors
- causal_networkx.graphs.dag.DAG.predecessors
- causal_networkx.graphs.dag.DAG.edges
- causal_networkx.graphs.dag.DAG.nodes
- causal_networkx.graphs.dag.DAG.has_adjacency
- causal_networkx.graphs.dag.DAG.has_edge
- causal_networkx.graphs.dag.DAG.has_node
- causal_networkx.graphs.dag.DAG.number_of_edges
- causal_networkx.graphs.dag.DAG.number_of_nodes
- causal_networkx.graphs.dag.DAG.size
- causal_networkx.graphs.dag.DAG.degree
- causal_networkx.graphs.dag.DAG.markov_blanket_of
- Graph modification
- causal_networkx.graphs.dag.DAG.add_node
- causal_networkx.graphs.dag.DAG.add_nodes_from
- causal_networkx.graphs.dag.DAG.remove_node
- causal_networkx.graphs.dag.DAG.remove_nodes_from
- causal_networkx.graphs.dag.DAG.remove_edge
- causal_networkx.graphs.dag.DAG.remove_edges_from
- causal_networkx.graphs.dag.DAG.add_edge
- causal_networkx.graphs.dag.DAG.add_edges_from
- causal_networkx.graphs.dag.DAG.clear
- causal_networkx.graphs.dag.DAG.clear_edges
- Ordering
- Conversion to/from other formats
- Overview
Discovery functions#
These functions compute try to learn the causal graph from data.
All these functions work with a Pandas DataFrame
object,
which is the recommended input to these functions. However, they
also should work on numpy array inputs.
|
Methods |
|
Methods |
|
Methods |
Conditional independence testing functions#
These functions are implementations of common conditional independence (CI) testing functions. These will eventually be ported out of this repository as they are of independent interest.
The general API for CI tests require a data
, x
, y
and sep_set
input, where data
is the DataFrame containing the data to be analyzed,
x
and y
are single columns of the DataFrame corresponding to a single
variable and then sep_set
is the conditioning set of variables.
Abstract class for any conditional independence test. |
|
|
Methods |
|
Methods |
|
Methods |
|
Methods |
|
Oracle conditional independence testing. |
|
Parent and children oracle for conditional independence testing. |
IO for reading/writing causal graphs#
We advocate for using our implemented causal graph classes whenever
utilizing various packages. However, we also support transformations
to and from popular storage classes, such as numpy arrays
,
pandas dataframes
, pgmpy
, DOT
and dagitty
. Note that
not all these are supported for all types of graphs because of
inherent limitations in supporting mixed-edge graphs in other formats.
Load causal graph from networkx. |
|
|
Load causal graph from a numpy array. |
|
Load causal graph from pgmpy. |
|
Convert causal graph to networkx class. |
|
Convert causal graph to a numpy adjacency array. |
Utility Algorithms for Causal Graphs#
|
Check d-separation among 'x' and 'y' given 'z' in graph G. |
|
Find all maximal cliques in causal DAG. |
Check if |
|
Returns a generator of nodes in topologically sorted order. |
|
|
Find the discriminating path for <..., a, u, c>. |
|
Find all PDS sets between node_x and node_y. |
|
Compute uncovered potentially directed path from u to c. |
|
Convert a DAG to a completed partially directed acyclic graph. |
|
Convert an ADMG to a PAG. |
|
Check markov equivalence of two graphs. |
|
Iterate through the graph to compute all v-structures. |