I would like to know the best way to identify the nodes(j,k) that influence the betweenness centrality of a focal node i. Since betweenness is based on the geodesics between j and k that pass through i, one way to do this is to get all of the shortest paths in the network, select only those paths that include i, and obtain the ids of nodes on those paths. However
library(igraph)
test <- shortest_paths(sample_gnp(200,.001),from=1)
takes almost nine seconds to run, and that's just for the paths from the first node; as I understand it, shortest_paths
will only calculate paths from one node at a time. This involves a lot of irrelevant information, since I really only want the geodesics that go through i. I assume that the betweenness function itself is doing this in some more efficient way using breadth first search or some other algorithm, but I don't see anything in the documentation for igraph or sna that would allow one to do this. I would like to avoid re-inventing the wheel here.
In short, given a network and a focal node i, what is the best way to find all the geodesics between j and k that include i?
UPDATE: here is a function I wrote that seems to do the trick (I have NOT carefully checked this yet though). It is slow but not unworkably slow on a random graph of 100 nodes with tie probability .2. I am sure there are better ways to do this.
find.shortest.paths <- function(net,focus){
nodes.on.path <- vector(mode="numeric")
n <- length(V(net))
for(i in 1:n){
for(j in 1:n){
if(i != focus & j != focus){
p <- all_shortest_paths(net,i,j)
if(focus %in% (unlist(p$res))==T){
nodes.on.path <- unique(c(nodes.on.path,unlist(p$res)))
}
}
}
}
return(sort(nodes.on.path))
}
ex <- sample_gnp(100,.2)
#try e.g. node 14 as focal node
system.time(test <- find.shortest.paths(ex,focus=14))