简体   繁体   English

如何计算R中的组间中心度

[英]How to calculate group betweenness centrality in R

I'm trying to implement a calculation of group centrality measures in a social network analysis. 我正在尝试在社交网络分析中实施小组集中度度量的计算。

Everett, MG, and SP Borgatti. Everett,MG和SP Borgatti。 “The Centrality of Groups and Classes.” The Journal of Mathematical Sociology 23, no. “群体和阶级的中心性”。《数学社会学杂志》 23号,第1期。 3 (January 1999): 181–201. 3(1999年1月):181-201。 doi:10.1080/0022250X.1999.9990219. doi:10.1080 / 0022250X.1999.9990219。

I've managed to calculate the group closeness centrality, but I'm still having problems with the group betweenness centrality. 我已经设法计算了组之间的接近度中心度,但是我仍然对组之间的接近度中心度有疑问。

Having a igraph object net and a group, g , within this, I need to calculate two things 1) the number of shortest paths connecting every vertex that is NOT within the group (g), but which go through at least one of the vertices in group 2) the total number of shortest paths between all vertices not in the group. 在其中有一个igraph对象网络和一个组g ,我需要计算两件事:1)连接不在组(g)中但通过至少一个顶点的每个顶点的最短路径数在第2组中)不在该组中的所有顶点之间的最短路径总数。

Can anyone help me with some further code to do this. 谁能帮我一些进一步的代码来做到这一点。

I found something on the following link, but only a statement saying it should be possible: https://lists.nongnu.org/archive/html/igraph-help/2008-03/msg00043.html 我在以下链接上找到了一些东西,但是只有一条声明说应该有可能: https : //lists.nongnu.org/archive/html/igraph-help/2008-03/msg00043.html

UPDATE::: 更新:::

I've now by trial and error managed to write following function to get all the shortest paths within a the non -group-part of a set of vertices that pass through another particular group in that set... 我现在通过反复试验设法编写以下函数来获取一组顶点的组部分内的所有最短路径,这些顶点通过该组中的另一个特定组...

get.shortest.paths.throug.group<-function(graph, grp) {
num <- 1:vcount(graph)
y <- cbind(num, V(graph)$name)

no.group <- as.numeric(y[(y[,2] %in% grp)==FALSE, 1])
group <- as.numeric(y[(y[,2] %in% grp)==TRUE, 1])
group.chr <- as.character(y[(y[,2] %in% grp)==TRUE, 1])   
count <- vector(mode="numeric", length(group))    

paths <- lapply(1:(length(no.group)-1), function(i) {
get.all.shortest.paths(
  graph, 
  from = no.group[i],
  to = no.group[(i+1):length(no.group)]
)$res
})

list <- unsplit(paths, rep.int(seq_along(paths), sapply(paths, length)))

for (j in 1:length(group)) {
count[j] <-  sum(grepl(group.chr[j], list)*1)
}

gbc <- (2*sum(count)/length(list))/((vcount(graph)-length(group))*(vcount(graph)-length(group)-1))

return(gbc)
}

But... Since my network contains 7500 vetices; 但是...由于我的网络包含7500个顶点; 118 in the group and 7382 non-group, this is a very time consuming function. 组118和非组7382,这是非常耗时的功能。 Creating the list of all shortest.paths between the 7382 non-group vertices is not that time consuming, but the part of the function finding out which of the 31.000.000+ shortest.paths pass throug the group is very slow 创建在7382个非组顶点之间的所有shortest.path的列表并不是很费时,但是该函数找出通过组的31.000.000+ shortest.paths中的哪一个通过的过程非常缓慢。

for (j in 1:length(group)) { count[j] <- sum(grepl(group.chr[j], list)*1) }

Can this be done in a more effective way? 能以更有效的方式做到吗?

Someone wrote a java code http://sourceforge.net/p/jung/patches/12/ that does the calculations (apparently in a faster way). 有人写了一个Java代码http://sourceforge.net/p/jung/patches/12/来执行计算(显然以更快的方式)。 But I have no experience with java. 但是我没有使用Java的经验。 Would it be possible to adapt the jung-patch to a R script?? 是否有可能使jung-patch适应R脚本?

Puzis et al give non-language-specific semicode for a fast scaleable algorithm here: http://journals.aps.org/pre/abstract/10.1103/PhysRevE.76.056709 Puzis等人在此处提供了非语言特定的半码,用于快速可缩放的算法: http ://journals.aps.org/pre/abstract/10.1103/PhysRevE.76.056709

And a Python implementation here: http://ftp.aip.org/epaps/phys_rev_e/E-PLEEE8-76-064711/ 这里还有一个Python实现: http : //ftp.aip.org/epaps/phys_rev_e/E-PLEEE8-76-064711/

My R is not good enough to implement it directly right now so unfortunately I don't have a final answer, but as a new user I also can't leave this in a comment. 我的R尚不足以立即直接实现它,因此很遗憾,我没有最终的答案,但是作为新用户,我也无法在评​​论中留下这个问题。 Good luck! 祝好运! And post if you do manage to implement it in R. 并发布(如果您确实设法在R中实现它)。

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

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