extract_direct_edges: Extract Direct Edges (Transitive Reduction)

View source: R/transitive_reduction.R

extract_direct_edgesR Documentation

Extract Direct Edges (Transitive Reduction)

Description

Performs transitive reduction on a reachability matrix to extract only the direct (essential) edges, removing edges that can be inferred through transitive paths.

Usage

extract_direct_edges(reach_matrix, adj_matrix = NULL)

Arguments

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.

Details

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.

Value

A matrix of the same dimension containing only direct edges (1s where there is a direct relationship that cannot be inferred from other paths).

See Also

identify_transitive_edges for identifying (not removing) transitive edges, plot_ism which uses this function internally.

Examples

# 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

ISMtools documentation built on March 13, 2026, 1:06 a.m.