【发布时间】:2019-06-12 07:18:49
【问题描述】:
我试图在 Actor-Actor 网络中找到中心节点。当我说中心节点时,我的意思是与网络中所有其他节点的路径最短的节点。
例如:
df <- structure(list(Movie.Name = structure(c(1L, 1L, 1L, 1L, 2L, 2L,
2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L), .Label = c("A", "B", "C",
"D"), class = "factor"), Actor.Name = structure(c(1L, 5L, 6L,
7L, 8L, 5L, 9L, 1L, 10L, 11L, 8L, 12L, 2L, 3L, 4L), .Label = c("Actor1",
"Actor10", "Actor11", "Actor12", "Actor2", "Actor3", "Actor4",
"Actor5", "Actor6", "Actor7", "Actor8", "Actor9"), class = "factor")), .Names = c("Movie.Name",
"Actor.Name"), class = "data.frame", row.names = c(NA, -15L))
从这个二分网络中,我投影了参与者-参与者网络,并使用以下代码找到所有节点的最短路径:
library(igraph)
g_graph <- graph.data.frame(df,directed=FALSE)
V(g_graph)$type <- bipartite_mapping(g_graph)$type
# project only actor&actor network
projected_g <- bipartite_projection(g_graph, multiplicity = TRUE, which = TRUE)
# Get connected nodes in largest component
# get largest component
getmax = function(g) {
V(g)$comp = clusters(g)$membership
delete.vertices(g, V(g)[V(g)$comp!=which(clusters(g)$csize==max(clusters(g)$csize))])
}
lc_projected_g <- getmax(projected_g)
# Turn weights into sample value!!
E(lc_projected_g)$weight <- 1
# Find shortes path from one to all nodes
p_short <- shortest.paths(lc_projected_g)
p_df <-as.data.frame(rownames(p_short))
p_df$Total_path_length <- rowSums(p_short)
# Find eigenvector centrality!!!
projected_eig <- eigen_centrality(lc_projected_g)$vector
我的问题是:
在 igraph 中,权重被视为成本或密切关系,因此将权重转换为相同的值是否正确?即使 Actor01 和 Actor02 之间有很多边,路径的长度也会是一条!
计算所有节点的最短路径后,有3个节点的值相同。在这种情况下,特征向量中心性是找到中心节点的正确方法吗?
当我投影二分网络时,我丢失了 Actor-Actor 网络中的边名称。我怎样才能重新分配它们?
我希望我的问题清晰合理。 提前致谢。
【问题讨论】:
标签: r graph igraph social-networking eigenvector