要在计算特征向量中心性时应用边权重,只需使用以下weights
选项引用权重eigen_centrality
:
rm(list=ls())
library(igraph)
# Some sample data, source: http://www.shizukalab.com/toolkits/sna/weighted-edgelists
el <- structure(list(V1 = c(23732L, 23732L, 23778L, 23778L, 23871L,
23871L, 23871L, 58009L, 58098L, 58256L), V2 = c(23871L, 58098L,
23732L, 23824L, 23778L, 58009L, 58098L, 58098L, 23778L, 58098L
), weight = c(1L, 10L, 8L, 1L, 15L, 1L, 5L, 7L, 1L, 1L)), .Names = c("V1",
"V2", "weight"), class = "data.frame", row.names = c(NA, -10L
))
g <- graph.data.frame(el)
# Only showing the centrality scores, hence the $vector
eigen_centrality(g, directed=TRUE, weights=E(g)$weight)$vector
# 23732 23778 23871 58009 58098 58256 23824
# 0.53685043 0.39782138 0.09055835 0.01527579 1.00000000 0.00000000 0.06710630
要获得权重的邻接矩阵:
get.adjacency(g, attr='weight')