Description Usage Arguments Value References Examples
View source: R/community_diversity.R
Calculates Shannon's or Inverse Simpson's diversity of a community, but only one measure of diversity can be calculated at a time and must be specified.
1 2 3 4 5 6 7 | community_diversity(
df,
time.var = NULL,
abundance.var,
replicate.var = NULL,
metric = c("Shannon", "InverseSimpson")
)
|
df |
A data frame containing species and abundance columns and optional columns of time and/or replicate. |
time.var |
The name of the optional time column |
abundance.var |
The name of the abundance column |
replicate.var |
The name of the optional replicate column. If specified, replicate must be unique within the dataset and cannot be nested within treatments or blocks. |
metric |
The diversity measure to return:
|
The community_diversity function returns a data frame with the following attributes:
time.var: A column that has the same name and type as the time.var column, if time.var is specified.
replicate.var: A column that has same name and type as the replicate.var column, if replicate.var is specified.
Shannon: A numeric column of Shannon's diversity if metric = "Shannon"
InverseSimpson: A numeric column of the inverse of Simpson's diversity if metric = "InverseSimpson"
Magurran, A.E. 2004. Measuring Biological Diversity. Blackwell Publishing, Malden MA, USA.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | data(pplots)
#Example with both time and replicates
df <- subset(pplots, plot == 25 | plot == 6)
community_diversity(df,
time.var="year",
replicate.var = "plot",
abundance.var = "relative_cover") # for Shannon's diversity measure
df <- subset(pplots, plot == 25 | plot == 6)
community_diversity(df,
time.var="year",
replicate.var = "plot",
abundance.var = "relative_cover",
metric = "InverseSimpson") # for Inverse of Simpson's diversity measure
#Example with no replicates
df <- subset(pplots, plot == 25)
community_diversity(df,
time.var="year",
abundance.var = "relative_cover") # for Shannon's diversity measure
#Example with no time or replicate
df <- subset(pplots, plot == 25 & year == 2002)
community_diversity(df,
abundance.var = "relative_cover") # for Shannon's diversity measure
|
year plot Shannon
1 2002 6 1.964799
2 2003 6 2.013032
3 2004 6 1.805089
4 2005 6 1.708760
5 2002 25 1.842618
6 2003 25 1.651746
7 2004 25 1.616162
8 2005 25 2.012171
year plot InverseSimpson
1 2002 6 4.050810
2 2003 6 5.012813
3 2004 6 2.920272
4 2005 6 3.749621
5 2002 25 4.072345
6 2003 25 3.970320
7 2004 25 2.927968
8 2005 25 5.847584
year Shannon
1 2002 1.842618
2 2003 1.651746
3 2004 1.616162
4 2005 2.012171
Shannon
1 1.842618
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.