Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Output of igraph clustering functions

I constructed a graph from a data-frame using the igraph graph_from_data_frame function. My two first column represent the edge list, and i have another column named "weight". There is several other attributes columns.

I then tried to find a community structure within my graph using cluster_fast_greedy.

data <- data %>%  rename(weight = TH_LIEN_2)
graph <- graph_from_data_frame(data,directed=FALSE)
is_weighted(graph)


cluster_1 <- cluster_fast_greedy(graph, weights = NULL)

The output is a list of three (merges, modularity, membership), each containing some of my vertices.
However, the following returns "NULL":

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel


cluster_1[["merges"]]
cluster_1[["modularity"]]
cluster_1[["membership"]]

(I believe cluster_1[["membership"]] is supposed to be a list of integer indicating the cluster the vertices belong to?)

I have tried different method of clustering (cluster_fast_greedy, cluster_label_prop, cluster_leading_eigen, cluster_spinglass, cluster_walktrap) and with a weighted and non weighted graph and the output looks the same every time. (The number of element on the list varying from 1 to 4)

Does anyone have an idea of why it does that?

Thank you and have a nice day!

Cassandra

>Solution :

You should use the dollar sign $ to access the cluster object. For example

g <- make_full_graph(5) %du% make_full_graph(5) %du% make_full_graph(5)
g <- add_edges(g, c(1, 6, 1, 11, 6, 11))
fc <- cluster_fast_greedy(g)

and you will see

> str(fc)
Class 'communities'  hidden list of 5
 $ merges    : num [1:14, 1:2] 3 4 5 1 12 13 15 11 7 8 ...
 $ modularity: num [1:15] -6.89e-02 -4.59e-02 6.94e-18 6.89e-02 1.46e-01 ...
 $ membership: num [1:15] 3 3 3 3 3 1 1 1 1 1 ...
 $ algorithm : chr "fast greedy"
 $ vcount    : int 15

> fc$merges
      [,1] [,2]
 [1,]    3    2
 [2,]    4   16
 [3,]    5   17
 [4,]    1   18
 [5,]   12   14
 [6,]   13   20
 [7,]   15   21
 [8,]   11   22
 [9,]    7    9
[10,]    8   24
[11,]   10   25
[12,]    6   26
[13,]   27   19
[14,]   23   28

> fc$modularity
 [1] -6.887052e-02 -4.591368e-02  6.938894e-18  6.887052e-02  1.460055e-01
 [6]  1.689624e-01  2.148760e-01  2.837466e-01  3.608815e-01  3.838384e-01
[11]  4.297521e-01  4.986226e-01  5.757576e-01  3.838384e-01 -1.110223e-16

> fc$membership
 [1] 3 3 3 3 3 1 1 1 1 1 2 2 2 2 2

> fc$algorithm
[1] "fast greedy"

> fc$vcount
[1] 15
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading