Run the edge swapping algorithm from Milo et al. (2003) on a bipartite graph while maintaining the separation of the nodes in two groups.
bipartite_edge_swap(gr, Q = 20, N = Q * igraph::ecount(gr))
gr | a tidygraph object with a node attribute called |
---|---|
Q | number of permutations you are conducting; default is 20 |
N | the number of edge swaps; default is \(Q \times |E(G)|\) |
the graph with \(N\) random edge swaps with constrained marginals
set.seed(0) bgr <- tidygraph::create_ring(6, directed = FALSE) bgr <- tidygraph::mutate(bgr, type = rep(c(TRUE, FALSE), 3)) print(bgr)#> # A tbl_graph: 6 nodes and 6 edges #> # #> # A bipartite simple graph with 1 component #> # #> # Node Data: 6 x 1 (active) #> type #> <lgl> #> 1 TRUE #> 2 FALSE #> 3 TRUE #> 4 FALSE #> 5 TRUE #> 6 FALSE #> # #> # Edge Data: 6 x 2 #> from to #> <int> <int> #> 1 1 2 #> 2 2 3 #> 3 3 4 #> # … with 3 more rows#> # A tbl_graph: 6 nodes and 6 edges #> # #> # A bipartite simple graph with 1 component #> # #> # Edge Data: 6 x 2 (active) #> from to #> <int> <int> #> 1 1 6 #> 2 4 5 #> 3 1 2 #> 4 3 4 #> 5 5 6 #> 6 2 3 #> # #> # Node Data: 6 x 2 #> type .idx #> <lgl> <int> #> 1 TRUE 1 #> 2 FALSE 2 #> 3 TRUE 3 #> # … with 3 more rows