且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在igraph(R)中进行社区检测后,如何找到对策?

更新时间:2023-01-28 11:30:45

好吧,我们可以修改您的代码以遍历不同的子组

Well, we can just adapt your code to loop over the different subgroups

karate <- graph.famous("Zachary")
wckarate <- walktrap.community(karate) #any algorithm
sapply(unique(membership(wckarate)), function(g) {
    subg1<-induced.subgraph(karate, which(membership(wckarate)==g)) #membership id differs for each cluster
    ecount(subg1)/ecount(karate)
})

只要在社区之间取得优势,就可以做到

and as far as getting the edges between the communities, you could do

#get all combinations of communities
cs <- data.frame(combn(unique(membership(wckarate)),2))
cx <- sapply(cs, function(x) {
    es<-E(karate)[V(karate)[membership(wckarate)==x[1]] %--% 
              V(karate)[membership(wckarate)==x[2]]]    
    length(es)
})
cbind(t(cs),cx)

此外,您可以绘制社区以确保外观合理

Also you can plot the communities to make sure that looks reasonable

plot.communities(wckarate, karate)