Compute sparsity (proportion of zero values) in a matrix or graph.

graph_sparsity(x, fun = igraph::as_adjacency_matrix, ...)

Arguments

x

An igraph object or a (sparse) matrix.

fun

Function to convert graph to matrix.

...

Arguments passed to fun.

Value

A numeric value representing the proportion of zero values in the graph/matrix.

Examples

## Using example KGX file packaged with monarchr
data(eds_marfan_kg)
g <- eds_marfan_kg |>
     fetch_nodes(query_ids = "MONDO:0007525") |>
     expand(predicates = "biolink:has_phenotype",
            categories = "biolink:PhenotypicFeature")

graph_sparsity(g)
#> [1] 0.9800083