1

I've built several graphs in iGraph. In each graph, nodes represent words, and edge weights represent the number of times Word A was given as a response (in a word association task) to Word B. In each graph, I've normalised the edge weights so that they vary between 0 and 1 using the following code:

E(G)$weight <- E(G)$weight / max(E(G)$weight)

These values are appropriate when analysing node/network strength, but when calculating functions pertaining to betweenness (e.g. calling the betweenness function, or using betweenness-based community detection, they need to be changed into distances - i.e. inverted:

G2 = G
E(G2)$weight = 1 - E(G2)$weight

The problem is that this results in vectors which contain several 0's (i.e. for those which had a strength of 1 before being inverted. This results (at least, I think that this is the cause) in error messages such as:

Error in cluster_edge_betweenness(G2.JHJ.strong, weights = E(G2.JHJ.strong)$weight,  : 
  At community.c:455 : weights must be strictly positive, Invalid value

What can be done about this?

Thanks,

Peter

1 Answers1

3

If you want to play it safe, you can try sum instead of max to normalize the weights, e.g.,

E(G)$weight <- E(G)$weight / sum((E(G)$weight)

or

E(G)$weight <- 2**((E(G)$weight - min(E(G)$weight)) / diff(range(E(G)$weight)))
ThomasIsCoding
  • 96,636
  • 9
  • 24
  • 81
  • Thanks. This creates values which are much closer to each other than when using ```max``` - i.e. the total range seems to span 0.995010 to 0.999002, rather than the previous values of 0 to 1. Will this affect the way that the algorithm works? – Peter Thwaites Jan 22 '21 at 11:36
  • @PeterThwaites See my update, which gives weights within range 1 to 2. – ThomasIsCoding Jan 22 '21 at 14:30