graph2amat: Convert graphNEL object to adjacency matrix

View source: R/misc.R

graph2amatR Documentation

Convert graphNEL object to adjacency matrix

Description

Convert graphNEL object to adjacency matrix

Usage

graph2amat(graph, toFrom = TRUE, type = "pdag")

Arguments

graph

A graphNEL object.

toFrom

Logical indicating whether the resulting adjancency matrix is "to-from" (default), or "from-to", see details.

type

The type of adjancency matrix, must be one of "pdag" or "ag". "pdag" should be used for directed graphs, namely DAG, CPDAG, MPDAG, TPDAG and PDAG adjacency matrices, i.e. adjacency matrices where A(i,j) = A(j,i) = 1 is interpreted as an undirected edge. "ag" may be used for ADMGs, MAGs, PAGs and TPAGs, where further possible arrowhead options are available (see amat)

Details

A "to-from" pdag adjacency matrix is encoded as follows: A(i,j) = 1 and A(j,i) = 0 means there is an edge i -> j. A(j,i) = 1 and A(i,j) = 0 means there is an edge j -> i. A(i,j) = 1 and A(j,i) = 1 means there is an undirected edge between i and j, i - j. A(i,j) = 0 and A(j,i) = 0 means there is no edge between i and j.

A "from-to" adjacency matrix is the transpose of a "to-from" adjacency matrix. A "from-to" pdag adjacency matrix is hence encoded as follows: A(i,j) = 1 and A(j,i) = 0 means there is an edge j -> i. A(j,i) = 1 and A(i,j) = 0 means there is an edge i -> j. A(i,j) = 1 and A(j,i) = 1 means there is an undirected edge between i and j, i - j. A(i,j) = 0 and A(j,i) = 0 means there is no edge between i and j.

See amat for details about how an ag adjacency matrix is encoded.


causalDisco documentation built on Jan. 20, 2026, 5:09 p.m.