Igraph 根据中心度分数识别节点

Igraph Identifying nodes based on centrality scores

我是 运行 igraph 包,用于对此示例数据集进行一些网络分析

structure(list(ï..Column1 = c(NA, NA, NA, NA), Column2 = c(NA, 
NA, NA, NA), Column3 = c(NA, NA, NA, NA), Column4 = c(NA, NA, 
NA, NA), Column5 = structure(c(2L, 1L, 4L, 3L), .Label = c("Eric ", 
"Jim", "Matt", "Tim"), class = "factor"), Column6 = c(NA, NA, 
NA, NA), Column7 = structure(c(1L, 3L, 2L, 3L), .Label = c("Eric", 
"Erica", "Mary "), class = "factor"), Column8 = structure(c(3L, 
2L, 1L, 3L), .Label = c("Beth", "Loranda", "Matt"), class = "factor"), 
    Column9 = structure(c(2L, 3L, 1L, 3L), .Label = c("Courtney ", 
    "Heather ", "Patrick"), class = "factor"), Column10 = structure(4:1, .Label = c("Beth", 
    "Heather", "John", "Loranda "), class = "factor"), Column11 = c(NA, 
    NA, NA, NA), Column12 = c(NA, NA, NA, NA), Column13 = c(NA, 
    NA, NA, NA), Column14 = c(NA, NA, NA, NA), Column15 = c(NA, 
    NA, NA, NA)), class = "data.frame", row.names = c(NA, -4L
))

这里是任何想要跳过找到

的步骤的人的边缘列表
structure(c("Jim", "Eric ", "Tim", "Matt", "Jim", "Eric ", "Tim", 
"Matt", "Jim", "Eric ", "Tim", "Matt", "Jim", "Eric ", "Tim", 
"Matt", "Eric", "Mary ", "Erica", "Mary ", "Matt", "Loranda", 
"Beth", "Matt", "Heather ", "Patrick", "Courtney ", "Patrick", 
"Loranda ", "John", "Heather", "Beth"), .Dim = c(16L, 2L), .Dimnames = list(
    NULL, c("Column5", "value")))

我正在尝试使用此代码计算网络中每个节点的中心性(mat 是我的边列表矩阵)

g1=graph_from_edgelist(mat)
degree.cent <- centr_degree(g1, mode = "all")
degree.cent

我的输出是这样的

> degree.cent
$`res`
 [1] 4 1 4 2 4 1 6 1 2 1 2 1 1 1 1

$centralization
[1] 0.1479592

$theoretical_max
[1] 392

我知道“degree$res”是我的中心性得分衡量标准,但我不清楚哪些节点实际获得了该得分。我查了一个教程here,但它只说第一个分数是"node 1"。没有迹象表明节点 1 是什么,也没有简单的方法来识别

首先,您得到的结果不正确,因为某些名称包含空格(Eric、Marry、Heather 等)。所以,让

mat <- gsub(" ", "", mat)
g1 <- graph_from_edgelist(mat)
degree.cent <- centr_degree(g1, mode = "all")

现在我们可以提取相应的顶点名称并将它们与您的结果结合起来:

setNames(degree.cent$res, V(g1)$name)
#      Jim     Eric     Mary      Tim    Erica     Matt  Loranda     Beth  Heather 
#        4        5        2        4        1        6        2        2        2 
#  Patrick Courtney     John 
#        2        1        1