How to find measures after community detection in igraph (R)?

前端 未结 1 1000
北荒
北荒 2020-12-28 23:39

I am working with Community Detection in graphs. I have been through the different community detection algorithms implemented in igraph and plotting the community structures

1条回答
  •  时光说笑
    2020-12-29 00:18

    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)
    

    enter image description here

    0 讨论(0)
提交回复
热议问题