# Analysis of community ecology data in R

David Zelený

### Site Tools

en:div-ind_r

Section: Diversity analysis

## Diversity indices

### R functions

• specnumber (library vegan) - calculates species richness for individual samples, optionally number of species for different groups of samples. Applies on sample x species matrix of abundances, presences absences or other type of data (calculation of richness does not consider species abundances). Argument group allows to calculate group-based species richness (i.e. number of species occurring in samples classified into given group). Just a little more clever than simple rowSums (x > 0).
• diversity (library vegan) - calculates Shannon and Simpson index. Applies on the sample x species matrix, where cells are species abundances. Argument index is either shannon (calculates Shannon entropy), simpson (calculates Gini-Simpson index, i.e. 1-Simpson, since Simpson index decreases with richness), and invsimpson (calculates reciprocal Simpson 1/D, which in fact is Simpson diversity - effective number of species calculated from Simpson's concentration index). Argument base can modify the base of the logarithm which is used to calculate Shannon (default is the natural logarithm, some prefer to use base = 2). The function works also if data are not genuine counts of individuals (abundances), but other measures (dominance, cover); in that case, the interpretation is not “randomly chosen individual” (Shannon) or “two randomly chosen individuals” (Simpson), but e.g. “randomly chosen bit's of biomass”.
• d (library vegetarian) - calculates Hill numbers for alpha, beta and gamma diversity. Applies on sample x species matrix of abundances (or biomass, cover etc.). Argument q modifies the coefficient q of the Hill numbers; default is q = 1, which is Shannon diversity (effective number of species calculated from Shannon's entropy). q can be any real number (also negative, although that makes no sense since this would give high weight to rare species). Allows estimating confidence intervals via bootstrapping. For level = 'alpha' it calculates diversity on the level of individual rows (samples), for level = 'gamma' on the level of the whole dataset. level = 'beta' calculates beta richness. Note: package vegetarian is currently not available on CRAN for the latest R versions; if you want to use it, you need to download it from the CRAN archive and install it manually in R Studio - go to Packages > Install > Install from package archive file (*zip, *tar.gz).
• H (library vegetarian) - calculates the original diversity indices (called “standard diversity indices”), not converted into effective number of species (Hill numbers). The function can calculate species richness, Shannon entropy, Simpson concentration index, Ginni-Simpson index, HCDT entropy, and Renyi entropy, and all this on alpha, beta or gamma level. 