API Reference
CausalEffectGraph
The central class. Represents a directed causal effect graph and provides methods for graph manipulation, querying, and causal effect estimation.
cegraph.CausalEffectGraph(adjacency_matrix=None, nodes=None) Parameters:
adjacency_matrix— Optional 2D NumPy array. If provided, initializes the graph from this matrix.nodes— Optional list of node names. Required ifadjacency_matrixis provided.
Graph Construction
add_edge(u, v, weight=1.0)
Add a directed edge from node
u to node v with optional weight.
remove_edge(u, v)
Remove the directed edge from
u to v.
add_node(name)
Add a node with the given
name to the graph.
Graph Querying
has_edge(u, v) -> bool
Returns
True if a directed edge exists from u to v.
parents(node) -> list
Return a list of parent nodes (nodes with edges directed into
node).
children(node) -> list
Return a list of child nodes (nodes with edges directed out of
node).
ancestors(node) -> set
Return the set of all ancestor nodes reachable via directed paths to
node.
descendants(node) -> set
Return the set of all descendant nodes reachable via directed paths from
node.
Causal Methods
average_causal_effect(data, treatment, outcome, covariates=None) -> float Estimate the average causal effect of treatment on outcome using regression adjustment.
Parameters:
data— 2D NumPy array of shape(n_samples, n_features).treatment— Name or index of the treatment variable.outcome— Name or index of the outcome variable.covariates— Optional list of covariate names/indices to adjust for.
backdoor_adjustment_set(target, cause) -> list
Find a valid backdoor adjustment set for estimating the causal effect of
cause on target.
Utility Methods
to_adjacency_matrix() -> np.ndarray
Return the adjacency matrix representation of the graph.
copy() -> CausalEffectGraph
Return a deep copy of the graph.
__len__() -> int
Return the number of edges in the graph.