Compute sparsity (proportion of zero values) in a matrix or graph.
graph_sparsity(x, fun = igraph::as_adjacency_matrix, ...)
A numeric value representing the proportion of zero values in the graph/matrix.
## Using example KGX file packaged with monarchr
filename <- system.file("extdata", "eds_marfan_kg.tar.gz", package = "monarchr")
g <- file_engine(filename) |>
fetch_nodes(query_ids = "MONDO:0007525") |>
expand(predicates = "biolink:has_phenotype",
categories = "biolink:PhenotypicFeature")
graph_sparsity(g)
#> [1] 0.9800083