简体   繁体   English

如何通过igraph计算加权度中心性?

[英]How to calculate weighted degree centrality by igraph?

I have a network for international export and the data frame is the following:我有一个国际出口网络,数据框如下:

The first column is the focal “Ego” country, and the second column is the “Alter” country, to which the focal country export goods.第一列是焦点“Ego”国家,第二列是焦点国家出口货物的“Alter”国家。 The third column “PercentOfImports” records the percent of the focal country's exports to that country第三列“PercentOfImports”记录了重点国家对该国出口的百分比

enter image description here ...在此处输入图像描述...

I want to calculate weighted degree centrality to decide which country is the most influential (totally export the highest percentage of goods).我想计算加权度中心性来决定哪个国家是最有影响力的(出口商品的百分比最高)。

export.gra<-graph_from_edgelist(cbind(export$Ego, export$Alter))
E(export.gra)$weight.poe<-export$PercentOfImports

And I use strength()to create the weighted centrality.我使用 strength() 来创建加权中心性。

deg.ex.poe<-strength(export.gra, mode="in", weights = E(export.gra)$weight.poe)

However, I found the result is problematic.但是,我发现结果是有问题的。 Some nodes in my case do not have a degree centrality, to which no focal country export goods.在我的例子中,一些节点没有中心度,没有焦点国家出口商品。 So I expected some 0 would occur in the vector of deg.ex.poe.所以我预计deg.ex.poe的向量中会出现一些0。 However, the results (in the following picture) show that all 0 are at the back of this vector.但是,结果(下图中)显示所有 0 都在这个向量的后面。 I checked my data and found the elements which should be 0 are filled in by later elements which are not 0. For example, the 2nd element in export$Alter is the degree centrality of the 5th country in export$Alter, since the degree centrality of the 2nd, 3rd and 4th element in export$Alter are all 0.我检查了我的数据,发现应该为0的元素被后面的非0元素填充。例如,export$Alter中的第二个元素是export$Alter中第5个国家的度中心性,因为度数中心性export$Alter 中的第 2 个、第 3 个和第 4 个元素都为 0。

enter image description here在此处输入图像描述

Hope you can help!希望你能帮忙! Thanks!谢谢!

I use this loop to reorder deg.ex.poe.我使用这个循环来重新排序 deg.ex.poe。 211 is the number of nodes. 211 是节点数。

for (i in 2:211){
    ifelse(TF[i]=="TRUE",
           deg.ex.poe[i]<-deg.ex.poe[i],
           deg.ex.poe<-c(deg.ex.poe[1:i-1],0,deg.ex.poe[i:211]))
      }  

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

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