Skip to contents

Filter Sparse Graph to Retain Nodes with Minimum Degree

Usage

filter_network(adj, n_neighbors = 5)

Arguments

adj

A symmetric adjacency matrix (numeric or sparse).

n_neighbors

Integer. The minimum number of neighbors each node must have to remain in the network (default: 5).

Value

A filtered adjacency matrix containing only nodes with at least `n_neighbors` connections.

Details

Iteratively removes nodes from a symmetric adjacency matrix until all remaining nodes have at least `n_neighbors` edges.

Examples

mat <- matrix(sample(0:1, 100, replace = TRUE, prob = c(0.9, 0.1)), nrow = 10)
mat[lower.tri(mat)] <- t(mat)[lower.tri(mat)]
diag(mat) <- 0
filtered <- filter_network(mat, n_neighbors = 2)
#> Error in base::rowSums(x, na.rm = na.rm, dims = dims, ...): 'x' must be an array of at least two dimensions