R: igraph, community detection, edge.betweenness method, count/list members of each community?

后端 未结 2 1897
悲&欢浪女
悲&欢浪女 2021-02-02 02:41

I\'ve a relatively large graph with Vertices: 524 Edges: 1125, of real world transactions. The edges are directed and have a weight (inclusion is optional). I\'m trying investig

2条回答
  •  被撕碎了的回忆
    2021-02-02 03:19

    A couple of these questions can be discovered by closely looking at the documentation of the functions you're using. For instance, the documentation of clusters, in the "Values" section, describes what will be returned from the function, a couple of which answer your questions. Documentation aside, you can always use the str function to analyze the make-up of any particular object.

    That being said, to get the members or numbers of members in a particular community, you can look at the membership object returned by the clusters function (which you're already using to assign color). So something like:

    summary(clusters(all2)$membership)
    

    would describe the IDs of the clusters that are being used. In the case of your sample data, it looks like you have clusters with the IDs ranging from 0 to 585, for 586 clusters in total. (Note that you won't be able to display those very accurately using the coloring scheme you're currently using.)

    To determine the number of vertices in each cluster, you can look at the csize component also returned by clusters. In this case, it's a vector of length 586, storing one size for each cluster calculated. So you can use

    clusters(all2)$csize
    

    to get the list of sizes of your clusters. Be warned that your clusterIDs, as previously mentioned, start from 0 ("zero-indexed") whereas R vectors start from 1 ("one-indexed"), so you'll need to shift these indices by one. For instance, clusters(all2)$csize[5] returns the size of the cluster with the ID of 4.

    To list the vertices in any cluster, you just want to find which IDs in the membership component previously mentioned match up to the cluster in question. So if I want to find the vertices in cluster #128 (there are 21 of these, according to clusters(all2)$csize[129]), I could use:

    which(clusters(all2)$membership == 128)
    length(which(clusters(all2)$membership == 128)) #21
    

    and to retrieve the vertices in that cluster, I can use the V function and pass in the indices which I just computed which are a member of that cluster:

    > V(all2)[clusters(all2)$membership == 128]
    Vertex sequence:
     [1] "625591221 - Clare Clancy"           
     [2] "100000283016052 - Podge Mooney"     
     [3] "100000036003966 - Jennifer Cleary"  
     [4] "100000248002190 - Sarah Dowd"       
     [5] "100001269231766 - LirChild Surfwear"
     [6] "100000112732723 - Stephen Howard"   
     [7] "100000136545396 - Ciaran O Hanlon"  
     [8] "1666181940 - Evion Grizewald"       
     [9] "100000079324233 - Johanna Delaney"  
    [10] "100000097126561 - Órlaith Murphy"   
    [11] "100000130390840 - Julieann Evans"   
    [12] "100000216769732 - Steffan Ashe"     
    [13] "100000245018012 - Tom Feehan"       
    [14] "100000004970313 - Rob Sheahan"      
    [15] "1841747558 - Laura Comber"          
    [16] "1846686377 - Karen Ni Fhailliun"    
    [17] "100000312579635 - Anne Rutherford"  
    [18] "100000572764945 - Lit Đ Jsociety"   
    [19] "100003033618584 - Fall Ball"        
    [20] "100000293776067 - James O'Sullivan" 
    [21] "100000104657411 - David Conway"
    

    That would cover the basic igraph questions you had. The other questions are more graph-theory related. I don't know of a way to supervise the number of clusters to be created using iGraph, but someone may be able to point you to a package which is able to do that. You may have more success posting that as a separate question, either here or in another venue.

    Regarding your first points of wanting to iterate through all possible communities, I think you'll find that to be unfeasible for a graph of significant size. The number of possible arrangements of the membership vector for 5 different clusters would be 5^n, where n is the size of the graph. If you want to find "all possible communities", that number will actually be O(n^n), if my mental math is correct. Essentially, it would be impossible to calculate that exhaustively over any reasonably size network, even given massive computational resources. So I think you'll be better off using some sort of intelligence/optimization for determining the number of communities represented in your graph, as the clusters function does.

提交回复
热议问题