In network analysis, many community detection algorithms have been developed. However,their applications leave unaddressed one important question: the statistical validation of the results.
robin (ROBustness in Network) has a double aim: tests the robustness of a community detection algorithm to detect if the community structure found is statistically significant and compares two detection algorithms to choose the one that better fits the network of interest.
Reference in Policastro V., Righelli D., Carissimo A., Cutillo L., De Feis I. (2021) https://journal.r-project.org/archive/2021/RJ-2021-040/index.html.
1) a procedure to examine the robustness of a community detection algorithm against a random graph;
2) a procedure to choose among different community detection algorithms the one that better fits the network of interest;
3) two tests to determine the statistical difference between the curves;
4) a graphical interactive representation.
If there are problems with the installation try:
# if (!requireNamespace("BiocManager", quietly = TRUE)) # install.packages("BiocManager") # BiocManager::install("gprege") # # install.packages("robin")
prepGraph function creates an igraph object from the input file. This step is necessary for robin execution
The unweighted graph can be read from different format: edgelist, pajek, graphml, gml, ncol, lgl, dimacs, graphdb and igraph graphs.
my_network <- system.file("example/football.gml", package="robin") # downloaded from: http://www-personal.umich.edu/~mejn/netdata/ graph <- prepGraph(file=my_network, file.format="gml") graph
plotGraph function offers a graphical representation of the network with the aid of networkD3 package.
methodCommunity function detects communities using all the algorithms implemented in igraph package: "walktrap", "edgeBetweenness", "fastGreedy", "spinglass", "leadingEigen", "labelProp", "infomap", "optimal", "other".
membershipCommunities function detects the community membership.
plotComm function produces an interactive 3D plot of the communites detected by the chosen algorithm.
members <- membershipCommunities(graph=graph, method="fastGreedy") plotComm(graph=graph, members=members)
robin offers two choices for the null model:
1) it can be generated by using the function random
2) it can be built externally and passed directly to the argument graphRandom of the robinRobust function.
The function random creates a random graph with the same degree distribution of the original graph, but with completely random edges. The graph argument must be the same returned by prepGraph function.
graphRandom <- random(graph=graph) graphRandom
robinRobust function implements the validation of the community robustness. In this example we used "vi" distance as stability measure, "independent" type procedure and "louvain" as community detection algorithm.
Users can choose also different measures as: "nmi","split.join", "adjusted.rand".
The graph argument must be the one returned by prepGraph function. The graphRandom must be the one returned by random function or own random graph.
proc <- robinRobust(graph=graph, graphRandom=graphRandom, measure="vi", method="louvain", type="independent")
As output robinRobust will give all the measures at different level of perturbation from 0% to 60% for the real and random graph.
plotRobin function plots the curves. The (x,y)-axes represents the percentage of perturbation and the average of the stability measure, respectively. The arguments of model1 and model2 must be the measures for the real graph and the random graph that are the outputs of the robinRobust function.
We will expect that with a robust algorithm the behavior of the two curves is different. We expect that the curve of the real graph vary less than the curve of the random graph, this visually means that the curve of the real graph is lower than the one of the random graph, so it is more stable than a random graph.
plotRobin(graph=graph, model1=proc$Mean, model2=proc$MeanRandom, legend=c("real data", "null model"))
The procedure implemented depends on the network of interest. In this example, the Louvain algorithm fits good the network of interest,as the curve of the stability measure assumes lower values than the one obtained by the null model.
The differences between the stability measure curves are tested using:
1) Functional Data Analysis (FDA);
2) Gaussian Process (GP).
Moreover to quantify the differences between the curves when they are very close the Area Under the Curves (AUC) are evaluated.
robinFDATest function implements a test giving a p-value for different intervals of the curves. It tests in which interval the two curves are different.
robinFDATest(graph=graph, model1=proc$Mean, model2=proc$MeanRandom, legend=c("real graph", "random graph"))
The first figure represents the stability measure plot using Louvain algorithm for detecting communities. The second one represents the corresponding p-values and adjusted p-values of the Interval Testing procedure. Horizontal red line corresponds to the critical value 0.05.
robinGPTest function implements the GP testing.
It tests the two curves globally. The null hypothesis claims that the two curves come from the same process, the alternative hypothesis that they come from two different processes.
The output is the Bayes Factor.
One of the most common interpretations is the one proposed by Harold Jeffereys (1961) and slightly modified by Lee and Wagenmakers in 2013:
IF B10 IS… THEN YOU HAVE…
° > 100 Extreme evidence for H1
° 30 – 100 Very strong evidence for H1
° 10 – 30 Strong evidence for H1
° 3 – 10 Moderate evidence for H1
° 1 – 3 Anecdotal evidence for H0
° 1 No evidence
° 1/3 – 1 Anecdotal evidence for H0
° 1/3 – 1/10 Moderate evidence for H0
° 1/10 – 1/30 Strong evidence for H0
° 1/30 – 1/100 Very strong evidence for H0
° < 1/100 Extreme evidence for H0
robinAUC function implements the AUC.
robinAUC(graph=graph, model1=proc$Mean, model2=proc$MeanRandom)
The outputs are the area under the two curves.
In this example we want to compare the "Fast Greedy" and the "Louvain" algorithms to see which is the best algorithm.
We firstly plot the communities detected by both algorithms.
membersFast <- membershipCommunities(graph=graph, method="fastGreedy") membersLouv <- membershipCommunities(graph=graph, method="louvain") plotComm(graph=graph, members=membersFast) plotComm(graph=graph, members=membersLouv)
Secondly, we compare them with robinCompare function.
robinCompare function compares two detection algorithms on the same network to choose the one that better fits the network of interest.
comp <- robinCompare(graph=graph, method1="fastGreedy", method2="louvain", measure="vi", type="independent")
A parallelized and faster version of this function is robinCompareFast function. (we recommend to use it mostly with big size networks)
Thirdly, we plot the curves of the compared methods.
plotRobin(graph=graph, model1=comp$Mean1, model2=comp$Mean2, legend=c("fastGreedy", "louvain"), title="FastGreedy vs Louvain")
In this example, the Louvain algorithm fits better the network of interest, as the curve of the stability measure assumes lower values than the one obtained by the Fast greedy method.
Fourthly we test the statistical differences between these two curves that now are created on two different community detection algorithm. The tests are already explained with more detail above.
robinFDATest(graph=graph, model1=comp$Mean1, model2=comp$Mean2)
robinAUC(graph=graph, model1=comp$Mean1, model2=comp$Mean2)
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.