Skip to contents

permute_pam: Function to permute a Presence-Absence-Matrix.


permute_pam(m, niter = NULL, as_sparse = FALSE, randal = "fastball")



Presence-Absence-Matrix (PAM) or a binary matrix with columns representing species and rows sites.


Number of iterations to permute the PAM.


If TRUE the PAM will be returned as a sparse matrix


Randomization algorithm applied to the PAM. Possible choices "curveball" and "fastball".


Returns a permuted matrix of the same dimensions of m (same number of rows and columns). Note that the sum of each row and column of this permuted matrix is equal to that of m. species.


This function uses the "curveball" (Strona et al., 2014) and the fastball (Godard and Neal, 2022) algorithms. The implementation of the "fastball" in C++ is provided in Please when using the "fastball" algorithm for publications cite Godard and Neal (2022). When using the "curveball" cite Strona et al. (2014).


Strona G, Nappo D, Boccacci F, Fattorini S, San-Miguel-Ayanz J (2014). “A fast and unbiased procedure to randomize ecological binary matrices with fixed row and column totals.” Nature Communications, 5(1), 1--9. ISSN 20411723, doi:10.1038/ncomms5114 , . Godard K, Neal ZP (2022). “fastball: a fast algorithm to randomly sample bipartite graphs with fixed degree sequences.” Journal of Complex Networks, 10(6), cnac049. ISSN 2051-1329, doi:10.1093/comnet/cnac049 ,


Luis Osorio-Olvera & Jorge Soberón


pam <- matrix(rbinom(100,1,0.3),nrow = 10,ncol = 10)
ppam <- bamm::permute_pam(m = pam,niter = NULL,as_sparse = FALSE)
# Check if matrices are different
all(pam == ppam)
#> [1] FALSE
# Check if row totals are the same
all(Matrix::rowSums(pam) == Matrix::rowSums(ppam))
#> [1] TRUE
# Check if column total are the same
all(Matrix::colSums(pam) == Matrix::colSums(ppam))
#> [1] TRUE