Learn R Programming

Diversity measures based on Entropy

divent is an R package that provides functions to estimate alpha, beta and gamma diversity of communities, including phylogenetic and functional diversity.

It is a reboot of the package entropart to make it tidy, easier to use and optimize the code that has been added along years of research.

Installation

You can install the development version of divent from GitHub with:

# install.packages("pak")
pak::pak("EricMarcon/divent")

Details

In the divent package, individuals of different species are counted in several communities which may (or not) be aggregated to define a metacommunity. In the metacommunity, the probability to find a species in the weighted average of probabilities in communities. This is a naming convention, which may correspond to plots in a forest inventory or any data organized the same way.

# Abundances of three communities with four species
abd <- matrix(
  c(
    10,  0, 25, 10, 
    20, 15, 10, 35, 
     0, 10,  5,  2
  ),
  ncol = 4
)
# Community weights
w <- c(1, 2, 1)

# Organize the data
library("divent")
abd |>
  as_abundances(weights = w) |>
  # Plot it
  plot(type = "Metacommunity")

Basic functions allow computing diversity of a community. Example data is a 6.25ha plot of rainforest in Paracou, French Guiana, divided into 4 subplots.

paracou_6_abd |>
  autoplot()

Entropies such as Shannon’s, Simpson’s, or Hurlbert’s, and explicit diversity (i.e. effective number of species), aka Hill numbers, are estimated.

# Diversity of a tropical rainforest
div_richness(paracou_6_abd)
#> # A tibble: 4 × 5
#>   site      weight estimator   order diversity
#>   <chr>      <dbl> <chr>       <dbl>     <dbl>
#> 1 subplot_1   1.56 Jackknife 3     0       355
#> 2 subplot_2   1.56 Jackknife 2     0       348
#> 3 subplot_3   1.56 Jackknife 2     0       315
#> 4 subplot_4   1.56 Jackknife 2     0       296
ent_shannon(paracou_6_abd)
#> # A tibble: 4 × 5
#>   site      weight estimator order entropy
#>   <chr>      <dbl> <chr>     <dbl>   <dbl>
#> 1 subplot_1   1.56 UnveilJ       1    4.57
#> 2 subplot_2   1.56 UnveilJ       1    4.73
#> 3 subplot_3   1.56 UnveilJ       1    4.65
#> 4 subplot_4   1.56 UnveilJ       1    4.55
ent_simpson(paracou_6_abd)
#> # A tibble: 4 × 5
#>   site      weight estimator order entropy
#>   <chr>      <dbl> <chr>     <dbl>   <dbl>
#> 1 subplot_1   1.56 Lande         2   0.976
#> 2 subplot_2   1.56 Lande         2   0.978
#> 3 subplot_3   1.56 Lande         2   0.980
#> 4 subplot_4   1.56 Lande         2   0.972

By default, the best available estimator of diversity is used, according to the data. Diversity profiles are estimated.

profile_hill(paracou_6_abd) %>% autoplot

Communities can be simulated and plotted.

rc <- rcommunity(1, size = 10000, distribution = "lnorm")
autoplot(rc, fit_rac = TRUE, distribution = "lnorm")

Phylogenetic entropy and diversity can be calculated if a phylogenetic (or functional), ultrametric tree is provided, with the state-of-the-art estimation-bias correction.

# Phylogenetic diversity of order 1, based on the taxonomy
div_phylo(paracou_6_abd, tree = paracou_6_taxo, q = 1)
#> # A tibble: 4 × 4
#>   site      weight estimator diversity
#>   <chr>      <dbl> <chr>         <dbl>
#> 1 subplot_1   1.56 UnveilJ        41.0
#> 2 subplot_2   1.56 UnveilJ        52.9
#> 3 subplot_3   1.56 UnveilJ        46.1
#> 4 subplot_4   1.56 UnveilJ        43.2

Similarity-based diversity is calculated, based on a similarity matrix.

# Similarity is computed from the functional distance matrix of Paracou species
Z <- fun_similarity(paracou_6_fundist)
# Calculate diversity of order 2
div_similarity(paracou_6_abd, similarities = Z, q = 2)
#> # A tibble: 4 × 5
#>   site      weight estimator order diversity
#>   <chr>      <dbl> <chr>     <dbl>     <dbl>
#> 1 subplot_1   1.56 UnveilJ       2      1.31
#> 2 subplot_2   1.56 UnveilJ       2      1.33
#> 3 subplot_3   1.56 UnveilJ       2      1.32
#> 4 subplot_4   1.56 UnveilJ       2      1.30

The diversity of a metacommunity, i.e. $\gamma$ diversity, can be partitioned into $\alpha$ (that of communities) and $\beta$ diversities.

# Partitioning of diversity of order 1 (Shannon)
div_part(paracou_6_abd, q = 1)
#> # A tibble: 7 × 6
#>   site          scale     estimator order diversity weight
#>   <chr>         <chr>     <chr>     <dbl>     <dbl>  <dbl>
#> 1 Metacommunity gamma     "UnveilJ"     1    111.     6.25
#> 2 Metacommunity beta      ""            1      1.09  NA   
#> 3 Metacommunity alpha     ""            1    102.    NA   
#> 4 subplot_1     community "UnveilJ"     1     96.3    1.56
#> 5 subplot_2     community "UnveilJ"     1    113.     1.56
#> 6 subplot_3     community "UnveilJ"     1    105.     1.56
#> 7 subplot_4     community "UnveilJ"     1     94.6    1.56

Vignettes

A quick introduction is in vignette("divent").

A full documentation is available online, in the “Articles” section of the web site of the vignette.

The documentation of the development version is also available.

Reference

Marcon, E. and Herault, B. (2015). entropart: An R Package to Measure and Partition Diversity. Journal of Statistical Software. 67(8): 1-26.

Copy Link

Version

Install

install.packages('divent')

Monthly Downloads

158

Version

0.5-3

License

GNU General Public License

Issues

Pull Requests

Stars

Forks

Maintainer

Eric Marcon

Last Published

August 27th, 2025

Functions in divent (0.5-3)

check_divent_args

check_divent_args
div_hurlbert

Hurlbert Diversity of a Community
div_pd

Faith's Phylogenetic Diversity of a Community
div_part

Diversity partition
div_richness

Number of Species of a Community
div_phylo

Phylogenetic Diversity of a Community
div_gen_simpson

Generalized Simpson's Diversity
div_hill

Hill number of a Community
div_similarity

Similarity-Based Diversity of a Community
coverage

Sample Coverage of a Community
ent_rao

Rao's Quadratic Entropy of a Community
ent_hurlbert

Hurlbert Entropy of a Community
ent_gen_simpson

Generalized Simpson's Entropy
ent_simpson

Simpson's Entropy of a Community
ent_allen

Allen et al.'s Phylogenetic Entropy of a Community
ent_similarity

Similarity-Based Entropy of a Community
ent_shannon

Shannon's Entropy of a Community
ent_phylo

Phylogenetic Entropy of a Community
e_n_q

Grassberger's expectation of n^q
divent-package

divent
ln_q

Deformed logarithm
mock_3sp

Mock data
ent_sp_simpson

Spatially Explicit Simpson's Entropy
fit_rac

Fit a distribution
exp_q

Deformed exponential
ent_tsallis

Tsallis Entropy of a Community
non_species_columns

Non-Species columns
fun_ordinariness

Functional ordinariness of a community
paracou_6

Paracou plot 6
paracou_6_fundist

Functional distances between Paracou plot 6 species
phylo_divent

Class phylo_divent
paracou_6_taxo

Taxonomy of Paracou plot 6 species
profile_similarity

Similarity-Based Diversity Profile of a Community
profile_phylo

Phylogenetic Diversity Profile of a Community
metacommunity

Aggregate communities into a metacommunity
profile_hill

Diversity Profile of a Community
probabilities

Probabilities of Species
rlseries

Log-Series Distribution
species_distribution

Species Distributions
rcommunity

Random communities
plot.phylo_divent

Plot phylo_divent Objects
reexports

Objects exported from other packages
plot.species_distribution

Plot Profile Objects
fun_similarity

Functional similarity
abd_freq_count

Abundance Frequency Count of a Community
abd_species

Abundances of Communities
autoplot.wmppp

ggplot method to plot wmppp objects
alphahull

alpha-shape calculation
accum_sp

Spatial Accumulation of Diversity
accum_hill

Diversity Accumulation of a Community
autoplot.accumulation

Plot Accumulation Objects
accum_div_phylo

Phylogenetic Diversity Accumulation of a Community
accum_sp_hill

Spatial Diversity Accumulation of a Community
autoplot.profile

Plot Profile Objects