View source: R/transitive_reduction.R
| extract_direct_edges | R Documentation |
Performs transitive reduction on a reachability matrix to extract only the direct (essential) edges, removing edges that can be inferred through transitive paths.
extract_direct_edges(reach_matrix, adj_matrix = NULL)
reach_matrix |
A square reachability matrix (n x n) with 0/1 entries. |
adj_matrix |
Optional. The original adjacency matrix. If provided, the function will use it to identify direct edges more accurately. |
Transitive reduction removes redundant edges from a directed graph while preserving reachability. An edge (i,j) is considered redundant (transitive) if there exists another path from i to j through intermediate nodes.
For example, if A->B->C and A->C, the edge A->C is transitive and will be removed, leaving only A->B and B->C.
This is essential for creating clean ISM diagrams suitable for publications, as showing all reachability edges would result in cluttered graphs.
A matrix of the same dimension containing only direct edges (1s where there is a direct relationship that cannot be inferred from other paths).
identify_transitive_edges for identifying (not removing) transitive edges,
plot_ism which uses this function internally.
# Create adjacency matrix with a transitive edge
# A -> B -> C, and A -> C (transitive)
adj <- matrix(c(0, 1, 1,
0, 0, 1,
0, 0, 0), nrow = 3, byrow = TRUE)
rownames(adj) <- colnames(adj) <- c("A", "B", "C")
# Compute reachability
reach <- compute_reachability(adj)
print(reach)
# Extract direct edges only
direct <- extract_direct_edges(reach)
print(direct)
# A->C is removed because it's transitive through B
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.