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 'hypergraphs_community_comparison'
print(x, n = 10L, ...)

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

# S3 method for class 'hypergraphs_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 the measures of hg_community_quality() on the projection its own fit saved (for type = "irmm", the final reweighted clique reduction), and the scores are available as what = "quality". A fit run on a directed citation graph cannot be scored (the measures are defined on undirected graphs): its quality row is NA and a hypergraphs_undefined_statistic warning is raised.

edge_source

Deprecated and unused: the saved projections already carry the hyperedge sources. Supplying it warns with class hypergraphs_deprecated.

x

A hypergraphs_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 hypergraphs_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, n_nodes, ami, ari, nmi, on the n_nodes nodes the two medoids share; with fewer than two shared nodes the three scores are NA and a hypergraphs_undefined_statistic warning is raised), "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, on a diverging scale from -1 through 0 (white) to 1, since chance-corrected agreement can be negative; undefined cells are grey).

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