Description Usage Arguments Details Value Author(s) Examples
View source: R/generate_random_community.R
This function generates a random community sample dataset that has a user-specified Shannon diversity index, species number, and total abundance.
1 2 3 4 5 6 7 8 9 | generate_random_community(
H_index,
shannon.base = exp(1),
sp_num,
ntotal,
tol = 1e-04,
maxiter = 100,
silent = FALSE
)
|
H_index |
The value of the generated communty Shannon diversity index H'. |
shannon.base |
A numeric value indicating the logarithm base for the Shanon indices. Defaults to e. |
sp_num |
Numeric. The number of species in the generated community sample. |
ntotal |
Numeric. The total number of individuals in the generated community sample. |
tol |
Numeric. The tolerance of the diffrence of the diversity index of the generated community relative abundance and the H_index argument. Defaults to 0.0001. |
maxiter |
Numeric. The maximum number of iterations to be performed. Defaults to 100. |
silent |
Logical. Indicates if convergence success or failure messages are omitted. Defaults to FALSE. |
This function generates random community sample data: a numeric vector whose elements represent a sample. The generated sample data is composed of a number of species with a total number of individuals set by the user, such that the community has a Shannon diversity index approximately equal to a user-specified argument.
A list containing the following components:
community: If convergence is successful, a numeric vector with the abundance of each species, else NA
n_ite: If convergence is successful, the number of iterations used to achieve convergence, else NA
David Ramirez Delgado linfocitoth1@gmail.com
Hugo Salinas hugosal@comunidad.unam.mx
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | # Generate a community with diversity index 2, composed of 20 species
# and 200 total individuals sampled
set.seed(26)
result <- generate_random_community(H_index = 2.7, sp_num = 20, ntotal = 200,
maxiter = 300)
random_community <- result$community
#Compute H index
total <- sum(random_community)
-sum(random_community/total*log(random_community/total))
#Default maxiter argument will not converge
set.seed(26)
generate_random_community(H_index = 2.7, sp_num = 20, ntotal = 200)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.