HierarchicalCausalModel
- class HierarchicalCausalModel[source]
Bases:
objectA class that wraps HCM functionality.
Initialize the HCM.
Methods Summary
add_edge(u, v, **kwargs)Add an edge.
add_observed_node(node)Add an observed node.
add_subunits(subunit_nodes)Annotate the given nodes as the subunit graph.
add_unobserved_node(node)Add an unobserved node.
copy_hcm()Return a copy of the HCM.
delete_edge(u, v)Delete an edge.
delete_node(node)Delete a node.
edges()Get all edges.
from_lists(*[, observed_subunits, ...])Create a hierarchical causal model from the given node and edge lists.
get_direct_unit_descendants(subunit_node)Return the set of direct unit descendants of the given subunit variable in the HCM.
Return the set of observed variables (both unit and subunit) in the HCM.
get_parents(node)Return the set of parent/predecessor variables of the given variable in the HCM.
Return the subunit subgraph of the input HCM.
Return the set of subunit variables in the HCM.
Return the set of unit variables in the HCM.
Return the set of unobserved variables (both unit and subunit) in the HCM.
is_node_observed(node)Check if the node is observed.
nodes()Get all nodes.
predecessors(node)Get predecessors.
successors(node)Get successors.
to_admg(*[, return_hcgm])Return a collapsed hierarchical causal model.
to_hcgm()Convert an HCM to a hierarchical causal graphical model (HCGM) with promoted Q variables.
to_hscm()Convert the input HCM to an explicit hierarchical structural causal model (HSCM).
Get a pygraphviz object.
Methods Documentation
- add_edge(u: str | Variable | QVariable, v: str | Variable | QVariable, **kwargs: Any) None[source]
Add an edge.
- add_subunits(subunit_nodes: Iterable[str | Variable | QVariable]) None[source]
Annotate the given nodes as the subunit graph.
- copy_hcm() HierarchicalCausalModel[source]
Return a copy of the HCM.
- delete_edge(u: str | Variable | QVariable, v: str | Variable | QVariable) None[source]
Delete an edge.
- classmethod from_lists(*, observed_subunits: Sequence[str | Variable | QVariable] | None = None, unobserved_subunits: Sequence[str | Variable | QVariable] | None = None, observed_units: Sequence[str | Variable | QVariable] | None = None, unobserved_units: Sequence[str | Variable | QVariable] | None = None, edges: Sequence[tuple[str | Variable | QVariable, str | Variable | QVariable]] | None = None) HierarchicalCausalModel[source]
Create a hierarchical causal model from the given node and edge lists.
- Parameters:
observed_subunits – a list of names for the observed subunit variables
unobserved_subunits – a list of names for the unobserved subunit variables
observed_units – a list of names for the observed unit variables
unobserved_units – a list of names for the unobserved unit variables
edges – a list of edges
- Returns:
a hierarchical causal model with subunit variables in the
SUBUNITS_KEYsubgraph
- get_direct_unit_descendants(subunit_node: str | Variable | QVariable) set[Variable][source]
Return the set of direct unit descendants of the given subunit variable in the HCM.
- get_observed() set[Variable][source]
Return the set of observed variables (both unit and subunit) in the HCM.
- get_parents(node: str | Variable | QVariable) set[Variable][source]
Return the set of parent/predecessor variables of the given variable in the HCM.
- get_unobserved() set[Variable][source]
Return the set of unobserved variables (both unit and subunit) in the HCM.
- to_admg(*, return_hcgm: bool = False) NxMixedGraph[source]
Return a collapsed hierarchical causal model.
- Parameters:
return_hcgm – if True, returns the intermediate hierarchical causal graphical models (HCGM) with subunits and promoted Q variables
- Returns:
a mixed graph
- Raises:
NotImplementedError – currently cannot handle unobserved subunit variables
- to_hcgm() HierarchicalCausalModel[source]
Convert an HCM to a hierarchical causal graphical model (HCGM) with promoted Q variables.
- to_hscm() HierarchicalStructuralCausalModel[source]
Convert the input HCM to an explicit hierarchical structural causal model (HSCM).