简体   繁体   中英

R Igraph Error: “Weight vector must be positive, Invalid value”

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 (eg calling the betweenness function, or using betweenness-based community detection, they need to be changed into distances - ie inverted:

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

The problem is that this results in vectors which contain several 0's (ie 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

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

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)))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM