cpr_rand_comm {canaper}R Documentation

Randomize a single community matrix


Note that binary null models return a binary matrix, even if an abundance matrix was used as input.


cpr_rand_comm(comm, null_model, n_iterations = 1, thin = 1, seed = NULL)



Dataframe or matrix; input community data with sites (communities) as rows and species as columns. Values of each cell are the presence/absence (0 or 1) or number of individuals (abundance) of each species in each site.


Character vector of length 1 or object of class commsim; either the name of the model to use for generating random communities (null model), or a custom null model. For full list of available predefined null models, see the help file of vegan::commsim(), or run vegan::make.commsim(). An object of class commsim can be generated with vegan::commsim() (see Examples).


Numeric vector of length 1; number of iterations for sequential null models. Ignored by non-sequential null models.


Numeric vector of length 1; thinning parameter used by some null models in vegan (e.g., quasiswap); ignored for other models.


Integer vector of length 1 or NULL; random seed that will be used in a call to set.seed() before randomizing the matrix. Default (NULL) will not change the random generator state.





# Check list of available pre-defined null models in vegan

# Binary null model produces binary output
cpr_rand_comm(phylocom$comm, "swap", 100)

# Quantitative null model produces quantitative output
cpr_rand_comm(phylocom$comm, "swap_count", 100)

# How to use a custom null model
# 1. Define a randomizing function, e.g. re-sample the matrix while
# preserving total number of presences (same as the "r00" model)
randomizer <- function(x, n, ...) {
  array(replicate(n, sample(x)), c(dim(x), n))

# 2. Generate a commsim object
cs_object <- vegan::commsim(
  fun = randomizer, binary = TRUE,
  isSeq = FALSE, mode = "integer"

# 3. Generate the null community
cpr_rand_comm(phylocom$comm, cs_object, 100)

[Package canaper version 1.0.0 Index]