Learn R Programming

bamm (version 0.5.0)

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

Description

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

Usage

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

Value

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.

Arguments

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

randal

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

Author

Luis Osorio-Olvera & Jorge Soberón

Details

This function can use the "curveball" (Strona et al., 2014), the fastball (Godard and Neal, 2022), and the independent swap algorithms. The implementation of the "fastball" in C++ is provided in https://github.com/zpneal/fastball/blob/main/fastball.cpp. Please when using the "fastball" algorithm for publications cite Godard and Neal (2022). When using the "curveball" cite Strona et al. (2014). When using independent swap ("indep_swap") cite Kembel et al. (2010)

References

Strona2014bamm

Gordard2022bamm

Kembel2010bamm

Examples

Run this code
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))

Run the code above in your browser using DataLab