curveball: Randomize an incidence matrix or bipartite graph using the...

View source: R/curveball.R

curveballR Documentation

Randomize an incidence matrix or bipartite graph using the curveball algorithm

Description

curveball randomizes an incidence matrix or bipartite graph, preserving the row and column sums

Usage

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.

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().

Value

An incidence matrix of class matrix or Matrix, or a bipartite graph of class igraph.

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. doi: 10.1038/ncomms5114

Godard, Karl and Neal, Zachary P. 2022. fastball: A fast algorithm to sample bipartite graphs with fixed degree sequences. arXiv:2112.04017

Neal, Z. P. 2022. incidentally: An R package to generate incidence matrices and bipartite graphs. OSF Preprints doi: 10.31219/osf.io/ectms

Examples

M <- incidence.from.probability(5,5,.5)  #A matrix
Mrand <- curveball(M)  #Random matrix with same row/col sums
all.equal(rowSums(M), rowSums(curveball(M)))
all.equal(colSums(M), colSums(curveball(M)))

zpneal/incidentally documentation built on Feb. 23, 2023, 11:54 a.m.