I am reading the book "Network science" of Barabasi and in particular the chapter on community detection.
If I understand correctly, modularity is a goodness factor of partition calculated by a certain algorithm: the greater the value of modularity and better is the structure of the communities found.
I tried several algorithms in R on the same network:
library(igraph)
library(GGally)
library(ggplot2)
library(ggdendro)
# load dataset
net <- read.graph("./ds.gml", format = c("gml"))
# find degree
deg <- igraph::degree(net, mode = "all")
###### GIRVAN & NEWMANN (divisive) ##################################################
girvNew <- cluster_edge_betweenness(net, modularity = TRUE)
girvNew_sizesComm <- sizes(girvNew)
girvNew_numComm <- length(girvNew_sizesComm)
girvNew_modularity <- modularity(girvNew)
print(girvNew_numComm)
print(girvNew_sizesComm)
print(girvNew_modularity)
girvNew_den <- as.dendrogram(girvNew)
###### GREEDY ################################################################
fastgreedy <- fastgreedy.community(net)
fastgreedy_sizesComm <- sizes(fastgreedy)
fastgreedy_numComm <- length(fastgreedy_sizesComm)
fastgreedy_modularity <- modularity(fastgreedy)
print(fastgreedy_numComm)
print(fastgreedy_sizesComm)
print(fastgreedy_modularity)
fastgreedy_den <- as.dendrogram(fastgreedy)
###### WALKTRAP ################################################################
walktrap <- cluster_walktrap(net)
walktrap_sizesComm <- sizes(walktrap)
walktrap_numComm <- length(walktrap_sizesComm)
walktrap_modularity <- modularity(walktrap)
print(walktrap_numComm)
print(walktrap_sizesComm)
print(walktrap_modularity)
walktrap_den <- as.dendrogram(walktrap)
###### LOUVAIN ################################################################
louvain <- cluster_louvain(graph = net, weights = NULL)
louvain_sizesComm <- sizes(louvain)
louvain_numComm <- length(louvain_sizesComm)
louvain_modularity <- modularity(louvain)
print(louvain_numComm)
print(louvain_sizesComm)
print(louvain_modularity)
The result I get are:
Looking at the table I would say that the algorithm of detection communties more efficient is Louvain, then Girvan-Newmann, Wolktrap and Greedy. Is this statement right?
The book says that the first algorithm (to Girvan-Newmann) calculates all partitions and doesn't choose the best one. To do this you need to select the best cut of the dendrogram based on modularity.
Having said that, what means the value of modularity found (0.5380681)? But above all, how do I find the modularity for each step of algorithm?
What I would like to get is something similar to this chart:
That is, a chart that allows me to see the various modular values obtained and can then choose the best one. This shows Modularity for each cut of the dendrogram.