node_in_community() returns a single community partition of a network, drawing on all the community detection algorithms available for that type of network.

By default it selects a partition. Where feasible (a small enough network), the optimal problem solving technique is used to ensure the maximal modularity partition. For larger networks, it identifies the applicable algorithms, runs each of them, and returns the partition with the largest modularity score.

Where consensus = TRUE it combines the partitions instead. Each applicable algorithm is run, the stochastic ones repeatedly, and the algorithms are then rerun on how often each pair of nodes is placed together until they agree. This costs considerably more time than selection, but does not rest the answer on a single run of a single algorithm.

node_in_community(
  .data,
  k = NULL,
  max_k = 8L,
  consensus = FALSE,
  times = 20,
  Kmax = NULL
)

Arguments

.data

A network object of class stocnet, igraph, tbl_graph, network, or similar. Internally any of these will be coerced to an efficient implementation. For more information on possible coercions, see e.g. manynet::as_stocnet().

k

Integer indicating the target number of communities to return. By default NULL, in which case the algorithm returns the number of communities that it finds itself. Alternatively, a character string naming a selection method: "silhouette" selects the number that maximises the mean silhouette width over geodesic distances, "elbow" selects the number at the elbow of the coverage curve, and "strict" returns the partition in which no tie crosses a group, i.e. the components. Prefer "silhouette"; the elbow method is unreliable where the coverage curve has no clear elbow. If the algorithm cannot return exactly the number of communities requested, a warning is given and the nearest number is returned.

max_k

Integer indicating the maximum number of communities to evaluate for "silhouette" and "elbow". By default 8. Otherwise ignored. Note that for node_in_louvain() and node_in_leiden() each candidate requires its own search over the resolution parameter, so a large max_k is costly on large networks.

consensus

Logical, whether to combine the partitions of all the applicable algorithms instead of selecting the one with the highest modularity. By default FALSE, since combining them costs more time. This argument is ignored on a network small enough for node_in_optimal(), which already returns the maximum modularity partition.

times

Integer scalar, how many times the algorithm repeats its work. Where the algorithm is stochastic, this is how many times it runs, and the best or the most frequent result is kept. Where the algorithm searches, this is how many steps the search takes. More repetitions give a more reliable result and take longer, so each function documents its own default.

Kmax

Deprecated. The former spelling of max_k. Still accepted, but warns; please use max_k instead.

Value

A node_member character vector the length of the nodes in the network, of group memberships "A", "B", etc for each node. If the network is labelled, then the assignments will be labelled with the nodes' names.

Details

times applies only when consensus = TRUE, and is 20 by default. Deterministic algorithms are run once however it is set.

References

On consensus community detection

Lancichinetti, Andrea, and Santo Fortunato. 2012. "Consensus clustering in complex networks". Scientific Reports 2: 336. doi:10.1038/srep00336

Tagarelli, Andrea, Alessia Amelio, and Francesco Gullo. 2017. "Ensemble-based Community Detection in Multilayer Networks". Data Mining and Knowledge Discovery 31: 1506-1543. doi:10.1007/s10618-017-0528-8

Examples

node_in_community(ison_adolescents)
#> 3 groups
#>   Betty Sue   Alice Jane  Dale  Pam   Carol Tina 
#> 1 A     A     B     B     B     C     C     C