简体   繁体   English

Gephi和R的介数分析

[英]Analysis of betweenness in Gephi and R

I'm trying to analyze a network ( les miserables ) from the betweenness point of view.我试图从中介的角度分析网络(悲惨世界)。

A piece of the network is:网络的一部分是:

graph
[
  node
  [
    id 0
    label "Myriel"
    maincharacter 0
  ]
  node
  [
    id 1
    label "Napoleon"
    maincharacter 0
  ]
  node
  [
    id 2
    label "MlleBaptistine"
    maincharacter 0
  ]
  node
  [
    id 3
    label "MmeMagloire"
    maincharacter 0
  ]
  node
  [
    id 4
    label "CountessDeLo"
    maincharacter 0
  ]
  node
  [
    id 5
    label "Geborand"
    maincharacter 0
  ]
  node
  [
    id 6
    label "Champtercier"
    maincharacter 0
  ]
  node
  [
    id 7
    label "Cravatte"
    maincharacter 0
  ]
  node
  [
    id 8
    label "Count"
    maincharacter 0
  ]
  node
  [
    id 9
    label "OldMan"
    maincharacter 0
  ]
  node
  [
    id 10
    label "Labarre"
    maincharacter 0
  ]
  node
  [
    id 11
    label "Valjean"
    maincharacter 1
  ]
  node
  [
    id 12
    label "Marguerite"
    maincharacter 0
  ]
  node
  [
    id 13
    label "MmeDeR"
    maincharacter 0
  ]
  node
  [
    id 14
    label "Isabeau"
    maincharacter 0
  ]
  ...

I open the network in Gephi and I made biggeer nodes using the "centrality Betweenness" attribute.我在 Gephi 中打开网络,并使用“中心性介数”属性制作了更大的节点。 Doing it I get that the node of id 11 is the one with greater betweenness.这样做我得到 id 11 的节点是具有更大介数的节点。

Then I tried to do the same thing in R. So I run these commands:然后我尝试在 R 中做同样的事情。所以我运行这些命令:

> net <- read.graph("./dataset/lesmiserables.gml", format = c("gml"))

> bet <- betweenness(net, normalized = TRUE)
> print(bet)
 [1] 0.1768421053 0.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000
 [9] 0.0000000000 0.0000000000 0.0000000000 0.5699890528 0.0000000000 0.0000000000 0.0000000000 0.0000000000
[17] 0.0406293482 0.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 0.1296445410
[25] 0.0290024187 0.0749012212 0.0237962535 0.0543315597 0.0264912281 0.0080409357 0.0000000000 0.0086402950
[33] 0.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0069254386
[41] 0.0000000000 0.0114875507 0.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0263157895
[49] 0.1651125024 0.0202106216 0.0002172097 0.0475989279 0.0003508772 0.0000000000 0.0000000000 0.1320324886
[57] 0.0000000000 0.0276612364 0.0425533568 0.0012501456 0.0000000000 0.0012501456 0.0052670299 0.0021854883
[65] 0.0307536502 0.0021854883 0.0001503759 0.0000000000 0.0049603840 0.0049603840 0.0048618042 0.0038738299
[73] 0.0000000000 0.0000000000 0.0000000000 0.0004385965 0.0000000000
> max(bet)
[1] 0.5699891

> betValjean <- betweenness(net, v = 11, normalized = TRUE)
> print(betValjean)
[1] 0

Why in Gephi the node with the highest betweenness is the the node of 11 while in R the node with the highest betweenness is the node of id 12?为什么在 Gephi 中具有最高介数的节点是 11 的节点,而在 R 中具有最高介数的节点是 id 12 的节点?

Why in R the node with id 11 has betweenness = 0?为什么在 R 中,id 为 11 的节点的介数 = 0?

I don't understand where I'm wrong..我不明白我错在哪里..

Thank you all谢谢你们

Your problem is that the id's of the vertices when you've read the graph in igraph do not necessarily correspond to the ids in your file.您的问题是,当您在igraph阅读图形时,顶点的 id 不一定与文件中的 id 相对应。 You don't specify how you've read the info in R, but assuming that you've done something like this,你没有指定你如何阅读 R 中的信息,但假设你已经做了这样的事情,

net <- read.graph("lesmiserables.gml", format="gml")

and also assuming that I've found in google the same file as you, indeed when I calculate betweenness of node 11 I don't get the expected result,并假设我在 google 中找到了与您相同的文件,实际上当我计算节点 11 的介数时,我没有得到预期的结果,

> betValjean <- betweenness(net, v = 11, normalized = TRUE)
> betValjean
[1] 0

However node 11 is not Jean Valjean,然而节点11不是冉阿让,

> get.vertex.attribute(net, "label", 11)
[1] "Labarre"

You can get the node you want like this,你可以像这样得到你想要的节点,

> V(net)[label == "Valjean"]
+ 1/77 vertex:
[1] 12

And then the betweenness in any of this 3 ways:然后是这 3 种方式中的任何一种的介数:

> betweenness(net, v =V(net)[label == "Valjean"], normalized = TRUE)
[1] 0.5699891
> betweenness(net, v = V(net)[id == 11], normalized = TRUE)
[1] 0.5699891
> betweenness(net, v = 12, normalized = TRUE)
[1] 0.5699891

Hope it helps.希望能帮助到你。

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

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