在 R 中设置检测到的社区的大小

Setting Size of Detected Communities in R

我正在使用 igraph 社区检测,社区规模不是太小就是太大。有没有办法指定检测到的社区的大小?如果没有,我有什么办法可以手动拆分或合并从 igraph 检测到的社区?谢谢!

虽然我认为 set/specify igraph 检测到的社区的 大小 是不可能的,但一些社区检测算法允许您指定您想要多少个社区(splitting/merging的替代方法)。

您可以使用 cluster_spinglass() 函数并将 spins 设置为所需的社区数量。 使用其中一种分层方法,然后使用cut_at()获得所需的社区数量,使用no参数指定您想要的社区数量。

示例代码:

# Set up your graph object
g <-[an igraph object] # set up your graph

# Use spinglass to create a set number of communities
sg <- g %>% cluster_spinglass(spins = 10) # produces 10 communities using spinglass algorithm

# Use hierarchical methods and cut_at to create a set number of communities 
walk <- g %>% cluster_walktrap() %>% cut_at(no = 10) 
eb <- g %>% cluster_edge_betweenness() %>% cut_at(no = 10)

请注意,spinglass 方法将返回一个 communities 对象,而 cut_at 方法只是返回图中所有节点的社区索引(即简单的数值向量)。

您可以在 communities help page.

上找到更多详细信息