简体   繁体   中英

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. The third column “PercentOfImports” records the percent of the focal country's exports to that country

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.

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. However, the results (in the following picture) show that all 0 are at the back of this vector. 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.

enter image description here

Hope you can help! Thanks!

I use this loop to reorder deg.ex.poe. 211 is the number of nodes.

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

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