I have a list of graphs (igraph format) and I would like to obtain a merge graph, which would be the intersection of those nodes and vertices that are shared a certain percentage trough all the graphs.
I know that igraph library has the function graph.intersection()
but this function intersect all the vertices and nodes present in all the graphs.
Any help would be much appreciated
Here is a brief example
g1 <- graph.data.frame(df1, directed=F)
df2 <- data.frame(V1=c(1,2,2,3,4), V2=c(3,3,5,5,5))
g2 <- graph.data.frame(df2, directed=F)
df3 <- data.frame(V1=c(1,2,3,4), V2=c(3,3,5,5))
g3 <- graph.data.frame(df3, directed=F)
df4 <- data.frame(V1=c(1,1,2,3), V2=c(2,3,4,5))
g4 <- graph.data.frame(df4, directed=F)
get.edgelist(g1)
[,1] [,2]
[1,] "1" "3"
[2,] "2" "3"
[3,] "2" "4"
[4,] "3" "5"
[5,] "4" "5"
get.edgelist(g2)
[,1] [,2]
[1,] "1" "3"
[2,] "2" "3"
[3,] "2" "5"
[4,] "3" "5"
[5,] "4" "5"
get.edgelist(g3)
[,1] [,2]
[1,] "1" "3"
[2,] "2" "3"
[3,] "3" "5"
[4,] "4" "5"
get.edgelist(g4)
[,1] [,2]
[1,] "1" "2"
[2,] "1" "3"
[3,] "2" "4"
[4,] "3" "5"
If I put all the graphs in a list:
mylist <- list(g1,g2,g3,g4)
And then apply the graph.intersection()
function:
g.int <- graph.intersection(mylist, keep.all.vertices=FALSE)
The result is a graph with the following nodes and edges:
V(g.int)
[1] "1" "2" "3" "4" "5"
get.edgelist(g.int)
[,1] [,2]
[1,] "3" "5"
[2,] "1" "3"
What I want is to include those vertices and edges that appears in a certain percentage, in this example I would like to include edges present in 75% of the graphs. Thus, the optimal result would be:
V(g.int)
[1] "1" "2" "3" "4" "5"
get.edgelist(g.int)
[,1] [,2]
[1,] "3" "5"
[2,] "1" "3"
[3,] "4" "5"
Hope now it is more clear