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_swap3(gr, Q = 20, N = igraph::ecount(gr) * Q,
  quiet = TRUE)

Arguments

gr

a tidygraph object with a node attribute called type that holds boolean values (i.e. either TRUE or FALSE)

Q

number of permutations you are conducting; default is 20

N

the number of edge swaps; default is \(Q \times |E(G)|\)

quiet

boolean for if you want the number of successful edge swaps printed; default TRUE

Value

the graph with \(N\) random edge swaps with constrained marginals

Examples

set.seed(0) bgr <- tidygraph::create_ring(6, directed = FALSE) bgr <- tidygraph::mutate( bgr, type = rep(c(TRUE, FALSE), 3), name = LETTERS[1:6]) print(bgr)
#> # A tbl_graph: 6 nodes and 6 edges #> # #> # A bipartite simple graph with 1 component #> # #> # Node Data: 6 x 2 (active) #> type name #> <lgl> <chr> #> 1 TRUE A #> 2 FALSE B #> 3 TRUE C #> 4 FALSE D #> 5 TRUE E #> 6 FALSE F #> # #> # Edge Data: 6 x 2 #> from to #> <int> <int> #> 1 1 2 #> 2 2 3 #> 3 3 4 #> # … with 3 more rows
print(bipartite_edge_swap3(bgr, 10))
#> # A tbl_graph: 6 nodes and 6 edges #> # #> # A bipartite simple graph with 1 component #> # #> # Node Data: 6 x 2 (active) #> name type #> <chr> <lgl> #> 1 E TRUE #> 2 C TRUE #> 3 A TRUE #> 4 B FALSE #> 5 D FALSE #> 6 F FALSE #> # #> # Edge Data: 6 x 2 #> from to #> <int> <int> #> 1 1 4 #> 2 2 4 #> 3 1 5 #> # … with 3 more rows