简体   繁体   English

R Igraph 错误:“权重向量必须为正,值无效”

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

I've built several graphs in iGraph.我在 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:在每个图中,节点代表单词,边权重代表单词 A 作为对单词 B 的响应(在单词关联任务中)的次数。在每个图中,我已经对边权重进行了归一化,以便它们在0 和 1 使用以下代码:

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:这些值在分析节点/网络强度时是合适的,但在计算与介数有关的函数时(例如调用介数 function,或使用基于介数的社区检测,它们需要更改为距离 - 即倒置:

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:问题是这会导致向量包含几个 0(即对于那些在反转之前强度为 1 的向量。这会导致(至少,我认为这是原因)出现错误消息,例如:

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,如果你想安全起见,你可以尝试sum而不是max来标准化权重,例如,

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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