Title: | Community Ecology Tests |
---|---|
Description: | Functions and data sets to perform and demonstrate community ecology statistical tests, including Hutcheson's t-test (Hutcheson (1970) <doi:10.1016/0022-5193(70)90124-4>, Zar (2010) ISBN:9780321656865). |
Authors: | Hugo Salinas [aut, cre], David Ramirez-Delgado [aut] |
Maintainer: | Hugo Salinas <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.0.1 |
Built: | 2024-10-31 16:32:22 UTC |
Source: | https://github.com/hugosal/ecoltest |
This function generates a random community sample dataset that has a user-specified Shannon diversity index, species number, and total abundance.
generate_random_community( H_index, shannon.base = exp(1), sp_num, ntotal, tol = 1e-04, maxiter = 100, silent = FALSE )
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 [email protected]
Hugo Salinas [email protected]
# 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)
# 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)
This function performs Hutcheson's t-test for significance of the difference between the diversity indices of two communities.
Hutcheson_t_test( x, y, shannon.base = exp(1), alternative = "two.sided", difference = 0 )
Hutcheson_t_test( x, y, shannon.base = exp(1), alternative = "two.sided", difference = 0 )
x , y
|
Numeric vectors of abundance of species for community sample x and community sample y. |
shannon.base |
A numeric value indicating the logarithm base for the Shannon indices. Defaults to exp(1). |
alternative |
A character indicating the alternative hypothesis. Can be "two.sided"(default), "less", "greater", or "auto". |
difference |
A numeric value indicating the hypothesized difference between the diversity indexes. Defaults to 0. |
This function performs Hutcheson's t-test for comparing two sample's Shannon diversity indices. This test is based on Shannon diversity indices computed using a logarithm base specified by the user. One-sided and two-sided tests are available.
A list of class "htest" containing the following components:
statistic: Value of the Hutcheson t-statistic.
parameter: The degrees of freedom of the t-statistic parameter.
p.value: The test's p-value.
estimate: The Shannon diversity indices of x and y.
null.value: The hypothesized value of the difference between the Shannon diversty indexes.
method: Name of the test.
alternative: The alternative hypothesis.
data.name: Name of the data used in the test.
Missing values will be replaced with zero values.
David Ramirez Delgado [email protected].
Hugo Salinas [email protected].
Zar, Jerrold H. 2010. Biostatistical Analysis. 5th ed. Pearson. pp. 174-176.
Hutcheson, Kermit. 1970. A Test for Comparing Diversities Based on the Shannon Formula. Journal of Theoretical Biology 29: 151-54.
See t.test
in stats package for
t-test.
data("polychaeta_abundance") # two-sided test Hutcheson_t_test(x=polychaeta_abundance$Sample.1, y=polychaeta_abundance$Sample.2, shannon.base = 10) # one-sided test Hutcheson_t_test(x=polychaeta_abundance$Sample.1, y=polychaeta_abundance$Sample.2, shannon.base = 10, alternative = "greater")
data("polychaeta_abundance") # two-sided test Hutcheson_t_test(x=polychaeta_abundance$Sample.1, y=polychaeta_abundance$Sample.2, shannon.base = 10) # one-sided test Hutcheson_t_test(x=polychaeta_abundance$Sample.1, y=polychaeta_abundance$Sample.2, shannon.base = 10, alternative = "greater")
This function computes the p-values of the Hutcheson t-test to test the significance of the difference between more than two communities Shannon diversity indexes, in a pairwise way.
multiple_Hutcheson_t_test(x, shannon.base = exp(1))
multiple_Hutcheson_t_test(x, shannon.base = exp(1))
x |
Numeric dataframe or matrix of abundance of species per community sample. Columns must correspond to the samples and rows to species. |
shannon.base |
Numeric value indicating the logarithm base for computing the Shannon indexes. Defaults to exp(1). |
This function performs Hutcheson's t-tests for comparing multiple
diversity indexes pairwise. This test is based on the Shannon diversity
index computed using a logarithm base specified by the user. The alternative
hypothesis is one-sided, chosen automatically according to the sign of
the difference between each pair of communities tested. The resulting
p-values of the test are returned in a matrix. To see full details of
the results of the test comparing two communities it is better
to use Hutcheson_t_test()
.
A matrix whose entries are the p-values from the test result rounded to five digits. Self-comparison elements (matrix diagonal) are flagged with NA. The names of the rows and columns are the names of the communities with their Shannon diversity index.
Missing values will be replaced with zero.
David Ramirez Delgado [email protected].
Hugo Salinas [email protected].
See Hutcheson_t_test
for Hutcheson's t-test details.
data("polychaeta_abundance") multiple_Hutcheson_t_test(x = polychaeta_abundance, shannon.base = 10)
data("polychaeta_abundance") multiple_Hutcheson_t_test(x = polychaeta_abundance, shannon.base = 10)
A dataset containing the abundance of 38 species of Polychaeta collected in 2013 from six samples from different locations in Bahía de los Ángeles, Ensenada, Baja California, México, by Victoria María Díaz Castañeda, PhD. (Senior Scientist; Laboratorio de Ecología del bentos marino, Departamentoe de Ecología Marina, CICESE).
polychaeta_abundance
polychaeta_abundance
A data frame with 39 rows and 6 variables. Rownames are the name of the species, the columns correspond to number of sample:
The abundance of each species in the sample 1
The abundance of each species in the sample 2
The abundance of each species in the sample 3
The abundance of each species in the sample 4
The abundance of each species in the sample 5
The abundance of each species in the sample 6