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
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