Randomize an incidence matrix or bipartite graph using the curveball algorithm
Randomize an incidence matrix or bipartite graph using the curveball algorithm
curveball randomizes an incidence matrix or bipartite graph, preserving the row and column sums
curveball(M, trades =5* nrow(M), class =NULL)
Arguments
M: a binary matrix of class matrix or Matrix, or a bipartite graph of class igraph.
trades: integer: number of trades; the default is 5 * nrow(M) (approx. mixing time)
class: string: Return object as matrix, Matrix, igraph. If NULL, object is returned in the same class as M.
Returns
An incidence matrix of class matrix or Matrix, or a bipartite graph of class igraph.
Details
Strona et al. (2014) provided an initial implementation of the Curveball algorithm in R. curveball() is a modified R implementation that is slightly more efficient. For an even more efficient algorithm, see backbone::fastball().
Examples
M <- incidence.from.probability(5,5,.5)#A matrixMrand <- curveball(M)#Random matrix with same row/col sumsall.equal(rowSums(M), rowSums(curveball(M)))all.equal(colSums(M), colSums(curveball(M)))
References
Strona, Giovanni, Domenico Nappo, Francesco Boccacci, Simone Fattorini, and Jesus San-Miguel-Ayanz. 2014. A Fast and Unbiased Procedure to Randomize Ecological Binary Matrices with Fixed Row and Column Totals. Nature Communications, 5, 4114. tools:::Rd_expr_doi("10.1038/ncomms5114")
Godard, Karl and Neal, Zachary P. 2022. fastball: A fast algorithm to sample bipartite graphs with fixed degree sequences. list("arXiv:2112.04017")
Neal, Z. P. 2022. incidentally: An R package to generate incidence matrices and bipartite graphs. OSF Preprints tools:::Rd_expr_doi("10.31219/osf.io/ectms")