I have an undirected network that I am working with in Igraph
with weighted edges.
For a particular graph out
, I can calculate communities in Igraph
using the function edge.betweenness.community
and the betweenness of each edge by using edge.betweenness
.
I can tell igraph
to include the weights of each edge by writing the following:
largest <- which.max(sapply(modules, vcount))
out <- modules[largest][[1]]
bt <- edge.betweenness(out, weights = E(out)$value, directed = FALSE)
Returning:
bt
[1] 20.0 11.0 27.0 11.0 8.0 12.0 8.0 8.5 7.5 6.0 3.0 3.0 7.0 8.5 7.5 4.0 11.0
Where the weights are:
E(out)$value
[1] 0.2829 0.2880 0.2997 0.1842 0.2963 0.2714 0.2577 0.2850 0.2850 0.2577 0.2305 0.2305 0.2577 0.1488 0.1488 0.1215 0.2997
The weights in this case have limits 0 - 1
, where 1 = highest cost to traverse an edge, 0 = lowest cost. However, these limits do not get passed to igraph
in any of the betweenness calculations.
My question: How does igraph
evaluate the lower and upper limits of the listed weights in terms of normalisation?
Does it automatically scale the weights based on the min and max values of the specified weights? (in this case min = 0.1215, max = 0.2997
)
What I want: How do I tell it to take the true limits of the full data set (min=0 - max=1
) into account?
Additional Information:
If I multiply the weights E(out)$value
by some constant and recalculate the betweenness, I get a similar answer (I assume there is some floating error and they are in fact the same):
new_weights <- as.numeric(E(out)$value*2.5)
new_weights
[1] 0.70725 0.72000 0.74925 0.46050 0.74075 0.67850 0.64425 0.71250 0.71250 0.64425 0.57625 0.57625 0.64425 0.37200 0.37200 0.30375 0.74925
bt <- edge.betweenness(out, weights = new_weights, directed = FALSE)
Giving:
bt
[1] 20 11 27 11 8 12 8 8 8 6 3 3 7 8 8 4 11
This implies there is some auto scaling going on:
With this in mind, how do I manually scale the betweenness calculation to my required limits of 0 and 1?
Research:
Edit 4 Jun2 2016 -
I have tried to review the source code for edge.betweenness on the igraph R Github page https://github.com/igraph/rigraph/tree/dev/R
The closest function I could find was cluster_edge_betweenness
at https://github.com/igraph/rigraph/blob/dev/R/community.R
This function make a call to the C function C_R_igraph_community_edge_betweenness
. The closest reference to this I could find in the igraph C documentation is igraph_community_edge_betweenness
at https://github.com/igraph/igraph/blob/master/include/igraph_community.h
Neither of these links however makes any reference to how the limits of the weights are calculated.
Original Research:
I have looked through the igraph
documentation on betweenness algorithms, and explored other questions related to normalisation, but have found nothing that deals specifically with the normalisation of the weights themselves.
Modularity calculation for weighted graphs in igraph
Calculation of betweenness in iGraph
http://igraph.org/r/doc/betweenness.html
The network data and visualisation are as follows:
plot(out)
get.data.frame(out)
from to value sourceID targetID
1 74 80 0.2829 255609 262854
2 74 61 0.2880 255609 179585
3 80 1085 0.2997 262854 3055482
4 1045 1046 0.1842 2970629 2971615
5 1046 1085 0.2963 2971615 3055482
6 1046 1154 0.2714 2971615 3087803
7 1085 1154 0.2577 3055482 3087803
8 1085 1187 0.2850 3055482 3101131
9 1085 1209 0.2850 3055482 3110186
10 1154 1243 0.2577 3087803 3130848
11 1154 1187 0.2305 3087803 3101131
12 1154 1209 0.2305 3087803 3110186
13 1154 1244 0.2577 3087803 3131379
14 1243 1187 0.1488 3130848 3101131
15 1243 1209 0.1488 3130848 3110186
16 1243 1244 0.1215 3130848 3131379
17 1243 1281 0.2997 3130848 3255811
(The weights in this case are in the frame$value
column with limits 0 - 1
, where 1 = highest cost to traverse an edge, 0 = lowest cost)