rcluster-analysisigraph

How to delete edges based on cluster_edge_betweenness output


I want to do the same as asked here, using the first approach from the question.

Sadly, the mods variable from the following line is not defined and I'm asking my self how to adjust:

g2 <- delete.edges(out, wc$removed.edges[seq(length = which.max(mods) - 1)])

However, I guess the function edge.betweenness.community is old and the newer version I use is adjusted like:

wc <- cluster_edge_betweenness(out, weights = (E(out)$value, directed = FALSE, bridges = TRUE, membership = TRUE, modularity = TRUE)

However, I struggle to adjust the delete.edge function – the first call deletes too many edges, and the second one too few:

out2 <- delete.edges(out, wc$removed.edges[seq(length = which.max(wc$modularity))])
out2 <- delete.edges(out, wc$removed.edges[which.max(wc$modularity)])

Just for completeness I add the data from the cited question:

from   to  value sourceID targetID
1    74   80 0.2829   255609   262854
2    74   61 0.2880   255609   179585
3    80 1085 0.2997   262854  3055482
4  1045 1046 0.1842  2970629  2971615
5  1046 1085 0.2963  2971615  3055482
6  1046 1154 0.2714  2971615  3087803
7  1085 1154 0.2577  3055482  3087803
8  1085 1187 0.2850  3055482  3101131
9  1085 1209 0.2850  3055482  3110186
10 1154 1243 0.2577  3087803  3130848
11 1154 1187 0.2305  3087803  3101131
12 1154 1209 0.2305  3087803  3110186
13 1154 1244 0.2577  3087803  3131379
14 1243 1187 0.1488  3130848  3101131
15 1243 1209 0.1488  3130848  3110186
16 1243 1244 0.1215  3130848  3131379
17 1243 1281 0.2997  3130848  3255811

Solution

  • Instead of using delete.edges, I think you can use disjoint_union + induced_subgraph like below

    g <- graph_from_data_frame(df)
    ceb <- cluster_edge_betweenness(g)
    out <- do.call(
      disjoint_union,
      lapply(groups(ceb), \(x) induced_subgraph(g, x))
    )
    

    and the plots look like

    par(mfrow = c(2, 1))
    plot(ceb, g, main = "Edge betweenness")
    plot(cluster_edge_betweenness(out), out, main = "Disjoint union")
    

    enter image description here