Skip to contents

Sets several hg_communities() fits of the same data side by side, as the paper does for its eight GFCC representations (Coupette et al. 2024, Figure 8): the cluster-size distribution of each AMI medoid, the pairwise AMI, ARI and NMI between medoids, and per-fit summaries (number of communities, singletons, the balance between the two largest clusters).

Usage

hg_compare_communities(..., hg = NULL, edge_source = NULL)

# S3 method for class 'hypernets_community_comparison'
print(x, n = 10L, ...)

# S3 method for class 'hypernets_community_comparison'
hg_get(x, what = c("summary", "similarity", "sizes", "quality"), ...)

# S3 method for class 'hypernets_community_comparison'
plot(x, what = c("sizes", "similarity"), ...)

Arguments

...

For plot, unused.

hg

Optional: the static net_hg the fits were computed on. When given, every medoid is scored with hg_community_quality() on the projection its own fit used, and the scores are available as what = "quality".

edge_source

Hyperedge sources for the citation and self-association projections when scoring, as in hg_project().

x

A hypernets_community_comparison object.

n

Number of rows of the default table to print. Default 10.

what

Which table: "summary" (default), "similarity", "sizes" or "quality".

Value

A hypernets_community_comparison object. hg_get() returns its "summary" (default; one row per fit with model, medoid_seed, n_communities, n_singletons, n_nontrivial, largest_size, second_size and balance = second / largest), "similarity" (one row per pair of fits with model_a, model_b, ami, ari, nmi, on the nodes the two medoids share), "sizes" (one row per community of every medoid with model, rank, n_nodes) or, when hg was given, "quality" (one row per fit with the columns of hg_community_quality()). plot() draws the cluster-size distributions (what = "sizes", the number of communities at least as large as each size, on logarithmic axes) or the similarity matrix (what = "similarity", AMI below and ARI above the diagonal, values printed in the cells).

For plot, a ggplot object.

References

Coupette, C., Hartung, D., & Katz, D. M. (2024). Legal hypergraphs. Philosophical Transactions of the Royal Society A, 382(2270), 20230141. doi:10.1098/rsta.2023.0141

Examples

dat <- data.frame(
  member = c("a", "b", "c", "a", "b", "c", "x", "y", "z", "x", "y", "z"),
  edge = rep(paste0("e", 1:4), each = 3)
)
h <- group_hypergraph(dat, "member", "edge")
if (requireNamespace("igraph", quietly = TRUE)) {
  multi <- hg_communities(h, n_runs = 2, trials = 2, seeds = 1:2)
  binary <- hg_communities(h, n_runs = 2, trials = 2, seeds = 1:2,
                           duplicate_edges = "collapse")
  comparison <- hg_compare_communities(mh = multi, bh = binary)
  hg_get(comparison)
  hg_get(comparison, what = "similarity")
}
#>   model_a model_b n_nodes ami ari nmi
#> 1      mh      bh       6   1   1   1