summary.mknn_graphs: Summary Method for mknn_graphs Objects

View source: R/mknn_graphs.R

summary.mknn_graphsR Documentation

Summary Method for mknn_graphs Objects

Description

Provides a comprehensive summary of mutual k-nearest neighbor graphs created by create.mknn.graphs, including structural statistics and connectivity information for each k value.

Usage

## S3 method for class 'mknn_graphs'
summary(object, ...)

Arguments

object

An object of class "mknn_graphs", typically output from create.mknn.graphs.

...

Additional arguments (currently unused).

Details

The summary provides insights into how graph structure changes with k:

  • Connected Components: Indicates graph fragmentation. A value of 1 means the graph is fully connected.

  • Degree Statistics: Shows the distribution of vertex connectivity. Large differences between min and max degree may indicate hub vertices.

  • Density/Sparsity: Measures how many of the possible edges are present. MkNN graphs are typically very sparse.

For pruned graphs, the statistics reflect the structure after geometric pruning has been applied.

Value

Invisibly returns a data frame containing graph statistics with columns:

idx

Index of the k value (1 to number of graphs)

k

The k value used for the graph

n_components

Number of connected components

n_edges

Number of edges in the graph

mean_degree

Average vertex degree

min_degree

Minimum vertex degree

max_degree

Maximum vertex degree

density

Graph density (proportion of possible edges present)

sparsity

Graph sparsity (1 - density)

Examples

mknn_result <- list(
  pruned_graphs = list(
    list(adj_list = list(c(2L), c(1L, 3L), c(2L))),
    list(adj_list = list(c(2L, 3L), c(1L, 3L), c(1L, 2L)))
  ),
  k_statistics = data.frame(
    k = 2:3,
    n_edges = c(2L, 3L),
    n_edges_pruned = c(2L, 3L),
    n_removed = c(0L, 0L),
    reduction_ratio = c(0, 0)
  )
)
attr(mknn_result, "kmin") <- 2L
attr(mknn_result, "kmax") <- 3L
attr(mknn_result, "n_vertices") <- 3L
attr(mknn_result, "max.path.edge.ratio.thld") <- 1.2
class(mknn_result) <- "mknn_graphs"

stats <- summary(mknn_result)
plot(stats$k, stats$mean_degree, type = "b",
     xlab = "k", ylab = "Mean Degree")


dgraphs documentation built on Aug. 21, 2026, 1:08 a.m.