6.3.2. pywhy_graphs.export.pcalg_to_graph#
- pywhy_graphs.export.pcalg_to_graph(arr, arr_idx: List[int | float | str | Any], amat_type: str)[source]#
Convert an array from R’s pcalg into causal graph.
- Parameters:
- arrarray-like of shape (n_nodes, n_nodes)
The array representing the causal graph with enumerations following that of
PCAlgPAGEndpoint
. Rows represent the starting node and the columns represent the ending node.- arr_idxList[Node] of length (n_nodes,)
The names of the nodes that are assigned to the graph in order of the rows/columns of
arr
.- amat_typestr
The type of graph in pcalg. One of
{"pag", "cpdag"}
.
- Returns:
- graphcausal graph
The causal graph
Notes
See pcalg documentation for
amatType
https://cran.r-project.org/web/packages/pcalg/pcalg.pdf. Copied here for convenience.Coding for type amat.cpdag:
0: No edge or tail 1: Arrowhead
Note that the edgemark-code refers to the row index (as opposed adjacency matrices of type mag or pag). E.g.:
amat[a,b] = 0 and amat[b,a] = 1 implies a –> b. amat[a,b] = 1 and amat[b,a] = 0 implies a <– b. amat[a,b] = 0 and amat[b,a] = 0 implies a b. amat[a,b] = 1 and amat[b,a] = 1 implies a — b.
Coding for type amat.pag:
0: No edge 1: Circle 2: Arrowhead 3: Tail
Note that the edgemark-code refers to the column index (as opposed adjacency matrices of type dag or cpdag). E.g.:
amat[a,b] = 2 and amat[b,a] = 3 implies a –> b. amat[a,b] = 3 and amat[b,a] = 2 implies a <– b. amat[a,b] = 2 and amat[b,a] = 2 implies a <-> b. amat[a,b] = 1 and amat[b,a] = 3 implies a –o b. amat[a,b] = 0 and amat[b,a] = 0 implies a b.