Create a new DAG instance with updated node roles.
Parameters:
| Name |
Type |
Description |
Default |
nodes_role
|
dict[str, Sequence[str]]
|
Keys should be node role names (e.g., 'Exposure', 'Outcome',
'Latent') and values a string or list with the node names.
Lowercase role keys for 'Exposure', 'Outcome', and
'Latent' are automatically promoted to their capitalized equivalents.
|
required
|
Returns:
| Type |
Description |
DAG
|
A fresh DAG object reflecting the new role assignments.
|
Examples:
>>> dag = DAG(graph="X -> Y")
>>> updated = dag.set_nodes_role({"Exposure": ["X"], "Outcome": ["Y"]})
>>> updated
Graph:
X -> Y
Observed:
Exposure: X
Outcome: Y
>>> updated.exposure
['X']
Source code in causalinf/gcm.py
| def set_nodes_role(self, nodes_role):
"""
Create a new DAG instance with updated node roles.
Parameters
----------
nodes_role : dict[str, Sequence[str]]
Keys should be node role names (e.g., ``'Exposure'``, ``'Outcome'``,
``'Latent'``) and values a string or list with the node names.
Lowercase role keys for ``'Exposure'``, ``'Outcome'``, and
``'Latent'`` are automatically promoted to their capitalized equivalents.
Returns
-------
DAG
A fresh `DAG` object reflecting the new role assignments.
Examples
--------
>>> dag = DAG(graph="X -> Y")
>>> updated = dag.set_nodes_role({"Exposure": ["X"], "Outcome": ["Y"]})
>>> updated
Graph:
X -> Y
Observed:
Exposure: X
Outcome: Y
>>> updated.exposure
['X']
"""
res = DAG(graph=self.__graph_str_parsed__,
nodes_role=nodes_role,
nodes_label=self.nodes_label,
nodes_position=self.nodes_position,
edge_label=self.edge_label,
data=self.data)
return res
|