permute_pam {bamm} | R Documentation |
permute_pam: Function to permute a Presence-Absence-Matrix.
permute_pam(m, niter = NULL, as_sparse = FALSE)
m |
Presence-Absence-Matrix (PAM) or a binary matrix with columns representing species and rows sites. |
niter |
Number of iterations to permute the PAM. |
as_sparse |
If TRUE the PAM will be returned as a sparse matrix |
This function is an implementation of the curve ball algorithm following Strona et al. (2014).
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.
Luis Osorio-Olvera & Jorge SoberĂ³n
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, https://www.r-project.org..
set.seed(111)
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)
# Check if row totals are the same
all(Matrix::rowSums(pam) == Matrix::rowSums(ppam))
# Check if column total are the same
all(Matrix::colSums(pam) == Matrix::colSums(ppam))