Skip to contents

Two species can be close relatives with the same diet or members of distant lineages with different roles, and a species count treats both pairs alike. This article accumulates diversity measured on a phylogeny and in trait space: phylogenetic diversity and EvoHeritage, functional dispersion and richness, Rao’s quadratic entropy, and the redundancy of species relative to lineages or trait combinations. It ends with the diversity of an interaction network accumulated over sites. Installation is covered in Get started; the phylogenetic examples also need the ape package for the tree.

  1. Accumulate MPD, MNTD, Faith’s PD or EvoHeritage on a tree with spaccPhylo().

  2. Accumulate functional dispersion, richness or the aggregated index K with spaccFunc().

  3. Weight distances by abundance with metric = "rao" in either function.

  4. Compare taxonomic with phylogenetic or functional Hill numbers with diversityProfile() and spaccRedundancy().

  5. Accumulate interactions between two groups of species with spaccNetwork().

Example

Simulating communities, traits and a tree

The example uses 60 sites in a 100 by 100 plane and 30 species. Each species has a random centre, and its expected count at a site falls off as a Gaussian kernel of the squared distance from that centre, with a peak of 5 individuals and about 1.8 individuals at 32 units. Counts are drawn from a Poisson distribution, so each species is confined to a patch of the plane. Each species also carries two continuous traits drawn from a standard normal distribution, and sits on a random coalescent tree from ape. Traits and tree are independent of where the species live.

Simulation code
set.seed(123)
n_sites <- 60
n_species <- 30

coords <- data.frame(x = runif(n_sites, 0, 100),
                     y = runif(n_sites, 0, 100))

species <- matrix(0L, n_sites, n_species)
for (sp in seq_len(n_species)) {
  cx <- runif(1, 10, 90)
  cy <- runif(1, 10, 90)
  lambda <- 5 * exp(-0.001 * ((coords$x - cx)^2 + (coords$y - cy)^2))
  species[, sp] <- rpois(n_sites, lambda)
}
colnames(species) <- paste0("sp", seq_len(n_species))
pa <- (species > 0) * 1L

set.seed(1)
traits <- data.frame(body_size = rnorm(n_species),
                     wing_length = rnorm(n_species))
rownames(traits) <- colnames(species)
set.seed(2)
tree <- ape::rcoal(n_species, tip.label = colnames(species))

species holds the counts, pa their presence/absence, coords the site positions in columns x and y, and traits one row per species with the species names as row names. The tips of tree carry the same names; the functions match species to tips and trait rows by name.

species[1:3, 1:6]
#>      sp1 sp2 sp3 sp4 sp5 sp6
#> [1,]   0   0   4   0   3   0
#> [2,]   1   2   0   0   0   3
#> [3,]   2   1   5   1   7   0
head(traits, 3)
#>      body_size wing_length
#> sp1 -0.6264538   1.3586796
#> sp2  0.1836433  -0.1027877
#> sp3 -0.8356286   0.3876716

Accumulating phylogenetic diversity

spaccPhylo() orders the sites by nearest-neighbour distance from each starting site and computes the chosen metrics on the tree for the accumulated species at each step. Mean pairwise distance (MPD) is the mean phylogenetic distance between all pairs of present species, mean nearest taxon distance (MNTD) the mean distance from each species to its closest present relative, and Faith’s PD the total branch length spanned by the present species.

phylo_acc <- spaccPhylo(pa, coords, tree,
                        metric = c("mpd", "mntd", "pd"),
                        n_seeds = 20, progress = FALSE)
phylo_df <- summary(phylo_acc)
phylo_df[phylo_df$sites %in% c(1, 60), c("metric", "sites", "mean")]
#>     metric sites       mean
#> 1      mpd     1 1.07340920
#> 60     mpd    60 1.05641400
#> 61    mntd     1 0.20198748
#> 120   mntd    60 0.09207106
#> 121     pd     1 4.31532620
#> 180     pd    60 5.63488872
plot(phylo_acc)

Accumulation curves of MPD, MNTD and Faith's PD against sites accumulated; PD rises over the first sites, MPD stays flat and MNTD falls. 0 2 4 0 20 40 60 Sites accumulated Phylogenetic diversity Metric MNTD MPD PD Spatial Phylogenetic Diversity Accumulation

PD rises like richness, from 4.3 at one site to 5.6, because each new species adds branch length. MPD and MNTD are averages. MPD stays near 1.06 from the first site on, so a single site already spans the deep splits of the tree; MNTD halves, because the species added later are close relatives of those already present. A flat MPD with a rising PD says the region keeps adding species but no new deep branches.

Accumulating EvoHeritage

PD counts every unit of branch length as a feature that all descendants still carry. EvoHeritage (Rosindell et al. 2024) adds attrition: features arise along a branch and are lost at rate \(\rho\) per unit length, and a feature counts once if it survives to at least one accumulated species. metric = "evoheritage" with a vector rho gives one curve per rate.

evo_acc <- spaccPhylo(pa, coords, tree,
                      metric = "evoheritage", rho = c(0, 0.5, 5),
                      n_seeds = 20, progress = FALSE)
evo_df <- summary(evo_acc)
evo_df[evo_df$sites == max(evo_df$sites),
       c("metric", "mean", "lower", "upper")]
#>                 metric      mean     lower     upper
#> 60    evoheritage_rho0  5.634889  5.634889  5.634889
#> 120 evoheritage_rho0.5  6.662653  6.662653  6.662653
#> 180   evoheritage_rho5 14.942374 14.942374 14.942374
sum(colSums(pa) > 0)   # observed richness
#> [1] 30

The \(\rho = 0\) curve is PD. As \(\rho\) grows, long internal branches lose what they carry, and the value tends to the number of species. Values are in standardised units, the heritage at the end of a single branch of unit length, so a rate changes both how much of the deep branches survives and what one unit means. One unit per species is reached only once \(\rho L\) is large for the shortest terminal branches, which on a coalescent tree such as this one takes rates far above 5.

Accumulating functional diversity

spaccFunc() works the same way in trait space. Functional dispersion (FDis) is the abundance-weighted mean distance of species to the community centroid. Functional richness (FRic) is the volume of the box spanned by the present species, the product of their ranges on each trait; it is 0 until there are more species than traits. Traits enter on their own scales, so standardise them first when their units differ.

func_acc <- spaccFunc(species, coords, traits,
                      metric = c("fdis", "fric"),
                      n_seeds = 20, progress = FALSE)
func_df <- summary(func_acc)
func_df[func_df$sites %in% c(1, 20, 60), c("metric", "sites", "mean")]
#>     metric sites      mean
#> 1     fdis     1  1.039428
#> 20    fdis    20  1.105783
#> 60    fdis    60  1.111727
#> 61    fric     1  9.760990
#> 80    fric    20 12.777838
#> 120   fric    60 12.791856
plot(func_acc)

Accumulation curves of functional dispersion and functional richness against sites accumulated; FRic levels off after about 20 sites and FDis rises slowly. 2.5 5.0 7.5 10.0 12.5 0 20 40 60 Sites accumulated Functional diversity Metric FDIS FRIC Spatial Functional Diversity Accumulation

FRic is within 0.2% of its final value after 20 sites, once the species at the extremes of both traits have been found. FDis changes little, from 1.04 at one site to 1.11: the traits are drawn independently of where species live, so one site already spans much of the trait variation. An FDis curve that keeps climbing in real data says the region still gains functionally extreme species at large spatial scales.

metric = "K" aggregates four facets into one index between 0 and 1 (Wojcik et al. 2024): the share of the trait axis covered, the evenness of abundances, the evenness of the spacing along the trait axis, and the spread of abundance around the mean trait. Each facet is 1 for species spread uniformly along the axis with equal abundances, and K is their geometric mean, so the facet curves show which aspect a new site adds.

func_k <- spaccFunc(species, coords, traits, metric = "K",
                    n_seeds = 20, progress = FALSE)
k_df <- summary(func_k)
k_df[k_df$sites %in% c(1, 10, max(k_df$sites)),
     c("metric", "sites", "mean")]
#>                 metric sites      mean
#> 1           k_richness     1 0.8445416
#> 10          k_richness    10 0.9972453
#> 60          k_richness    60 1.0000000
#> 61  k_biomass_evenness     1 0.8403613
#> 70  k_biomass_evenness    10 0.8537784
#> 120 k_biomass_evenness    60 0.9583984
#> 121   k_trait_evenness     1 0.7393688
#> 130   k_trait_evenness    10 0.7797773
#> 180   k_trait_evenness    60 0.7876770
#> 181       k_dispersion     1 0.7842154
#> 190       k_dispersion    10 0.6361858
#> 240       k_dispersion    60 0.7249809
#> 241                  K     1 0.7950999
#> 250                  K    10 0.8033275
#> 300                  K    60 0.8601124

K rises from 0.80 at one site to 0.86 at 60. The facets show where the gain comes from: the share of the trait axes covered goes from 0.84 to 1 and biomass evenness from 0.84 to 0.96, while dispersion falls over the first 10 sites before it recovers.

Weighting by abundance with Rao’s Q

Rao’s quadratic entropy (Rao 1982) combines relative abundances with pairwise distances, giving an abundance-weighted mean distance between two individuals drawn at random. Both spaccPhylo() and spaccFunc() compute it with metric = "rao"; pass counts for the abundance weighting.

phylo_rao <- spaccPhylo(species, coords, tree, metric = "rao",
                        n_seeds = 20, progress = FALSE)
plot(phylo_rao)

Phylogenetic Rao's Q against sites accumulated, rising over the first sites and then levelling off. 0.7 0.8 0.9 1.0 1.1 0 20 40 60 Sites accumulated Phylogenetic diversity Metric RAO Spatial Phylogenetic Diversity Accumulation

For functional Rao the distance between species is the Euclidean distance in trait space.

func_rao <- spaccFunc(species, coords, traits, metric = "rao",
                      n_seeds = 20, progress = FALSE)
rao_df <- as.data.frame(func_rao)
rao_df[rao_df$sites %in% c(1, 20, 60), c("sites", "mean", "lower", "upper")]
#>    sites     mean    lower    upper
#> 1      1 1.457263 1.302655 1.786540
#> 20    20 1.557387 1.385320 1.670965
#> 60    60 1.542797 1.542797 1.542797

Functional Rao’s Q changes little along the curve, from 1.46 at one site to 1.54: once the community spans the main distance structure, further species near existing ones barely change the abundance-weighted mean distance. With presence/absence data it reduces to an equal-weight form. Abundances are held in double precision, so continuous values such as percent cover or biomass are used directly.

cover <- species / max(species)   # fractional values in [0, 1]
func_rao_cover <- spaccFunc(cover, coords, traits, metric = "rao",
                            n_seeds = 10, progress = FALSE)
tail(as.data.frame(func_rao_cover), 3)
#>    metric sites     mean    lower    upper           sd
#> 58    rao    58 1.546363 1.545214 1.547375 9.213009e-04
#> 59    rao    59 1.545109 1.543456 1.547028 1.753545e-03
#> 60    rao    60 1.542797 1.542797 1.542797 1.958249e-16

Dividing every count by the same number leaves the relative abundances unchanged, so the last value is the same 1.54 as with counts.

Comparing taxonomic with phylogenetic and functional Hill numbers

diversityProfile() with traits gives similarity-sensitive Hill numbers across orders \(q\) (Leinster & Cobbold 2012), and with tree phylogenetic Hill numbers. Each is an effective number of functional units or lineages and declines with \(q\) like the taxonomic profile.

fp <- diversityProfile(species, traits = traits, q = seq(0, 3, by = 0.5))
fp
#> Functional diversity profile: 60 sites, 30 species
#> q range: [0.0, 3.0] (7 values)
#> Per-site: mean D_0 = 1.6, mean D_1 = 1.6, mean D_2 = 1.6
#> Regional: D_0 = 1.7, D_1 = 1.7, D_2 = 1.7

The values lie between 1.6 and 1.7 and fall only slightly with \(q\). The similarity of two species is one minus their trait distance scaled to a maximum of 1, so most pairs of these 30 species count as largely similar, and together they are worth fewer than two fully distinct functional units.

The ratio of the taxonomic to the phylogenetic or functional Hill number is at least 1, and equals 1 only when all species are equally and maximally distinct (a star tree, or every pair at the largest trait distance). spaccRedundancy() tracks this ratio along the accumulation, with a tree or with traits.

red <- spaccRedundancy(species, coords, tree = tree,
                       n_seeds = 20, progress = FALSE)
red
#> spacc phylogenetic redundancy: 60 sites, 30 species, 20 seeds
#> Orders (q): 0, 1, 2
#>   q = 0: mean final redundancy = 4.42
#>   q = 1: mean final redundancy = 7.58
#>   q = 2: mean final redundancy = 11.44
plot(red)

Ratio of taxonomic to phylogenetic Hill number against sites accumulated for q = 0, 1 and 2. 3 6 9 12 0 20 40 60 Sites accumulated Redundancy ratio Order q = 0 q = 1 q = 2 Spatial Phylogenetic Redundancy

The ratio rises along the accumulation at every order, most at \(q = 2\), where it ends at 11.4. The region keeps adding species that are close relatives of those already present, which the falling MNTD above shows as well.

Accumulating interaction networks

An interaction network, such as plants and their pollinators, has its own diversity: each observed pair of a lower-level and an upper-level species is a unit, and its number of observations is its abundance (Chiu et al. 2023). spaccNetwork() takes one row per observed interaction, with the site and the two species in columns site, lower and upper, and an optional count. The example draws 600 visits at 30 sites; the plant species visited shift from west to east, the 20 bee species do not.

set.seed(7)
net_xy <- data.frame(x = runif(30, 0, 100), y = runif(30, 0, 100))
site <- sample(30, 600, replace = TRUE)
plant <- 1 + floor(net_xy$x[site] / 10) + rbinom(600, 2, 0.5)
visits <- data.frame(site = site,
                     lower = paste0("plant", plant),
                     upper = paste0("bee", sample(20, 600, replace = TRUE)))
head(visits, 3)
#>   site  lower upper
#> 1    2 plant4 bee17
#> 2   12 plant4 bee11
#> 3   21 plant8  bee3
net <- spaccNetwork(visits, net_xy, n_seeds = 20, progress = FALSE)
net
#> 208 interactions between 12 lower and 20 upper species
#>   q = 0: mean final interaction diversity = 208.0
#>   q = 1: mean final interaction diversity = 178.4
#>   q = 2: mean final interaction diversity = 158.3
#> Final coverage: interactions 0.919, lower 1.000, upper 1.000
#> Final connectance: 0.867

The interaction Hill numbers of order \(q\) are ordinary Hill numbers of the interaction frequencies at the accumulated sites. The same orders give the Hill numbers of each level, from each species’ summed frequency, the sample coverage of all three, and the connectance, the share of possible pairs between the species detected so far that were observed.

plot(net)

Interaction diversity against sites accumulated for q = 0, 1 and 2. 0 50 100 150 200 0 10 20 30 Sites accumulated Interaction diversity Order q = 0 q = 1 q = 2 Spatial Accumulation of Interactions

plot(net, component = "connectance")

Connectance against sites accumulated. 0.3 0.4 0.5 0.6 0.7 0.8 0 10 20 30 Sites accumulated Connectance Connectance along Accumulation

All 12 plant and 20 bee species are detected (coverage 1 for both levels), while the interaction coverage of 0.92 says that some pairs remain unobserved. Connectance rises along the curve to 0.87, because the bees in this simulation visit plants at random, so each plant species meets more of them as visits accumulate. plot(net, component = "species") shows the interaction curve next to the curves of the two levels, and component = "coverage" the three coverage curves.

Metric definitions

For the species present at a step, let \(d_{ij}\) be the distance between species \(i\) and \(j\), on the tree (sum of branch lengths between the tips) or in trait space, \(p_i\) the relative abundance of species \(i\), and \(t_i\) its trait vector with entries \(t_{ik}\) for traits \(k\).

  • MPD is the mean of \(d_{ij}\) over all pairs of present species; MNTD the mean over species of \(\min_{j \ne i} d_{ij}\). MPD responds to deep tree structure, MNTD to clustering near the tips.

  • Faith’s PD (Faith 1992) is the total branch length of the tree spanned by the present species and the root.

  • EvoHeritage passes a fraction \(e^{-\rho L}\) of what enters a branch of length \(L\) to its end; \(\rho = 0\) gives PD, large \(\rho\) tends to species richness.

  • FRic is \(\prod_k (\max_i t_{ik} - \min_i t_{ik})\), the volume of the box spanned by the present species, and 0 when there are no more species than traits.

  • FDis (Laliberté & Legendre 2010) is \(\sum_i p_i \lVert t_i - c \rVert\), with \(c = \sum_i p_i t_i\) the abundance-weighted centroid.

  • Rao’s quadratic entropy is \(Q = \sum_{i} \sum_{j} p_i p_j d_{ij}\). Its effective-number form is a phylogenetic or functional Hill number of order 2.

  • Redundancy is \(R_q = {}^{q}D / {}^{q}D(T)\) with a tree (Chao et al. 2010; \(T\) the abundance-weighted mean root-to-tip depth) or \(R_q = {}^{q}D / {}^{q}D^{Z}\) with traits (Leinster & Cobbold 2012; similarity \(Z = 1 - d\) from trait distances scaled to a maximum of 1 by default).

K combines, per trait, functional richness (the trait range over the axis length, by default the range over all species in traits; axis_length_k sets it), biomass evenness, trait evenness and dispersion (the abundance-weighted trait variance over that of a uniform distribution on the same range, capped at 1). Several traits combine as the geometric mean over traits. Trait evenness needs three species: with two, K is the cube root of the other three facets, and with fewer than two K is 0. With presence/absence data biomass evenness is 1.

With itv = TRUE, spaccFunc() reads traits as one row per individual or population, with a species column and an optional site column, so a species whose traits change along a gradient adds trait range as the accumulation reaches new parts of the gradient (Palacio et al. 2025).

Practical guidance

Abundance or incidence. Feed counts, cover or biomass for FDis, Rao’s Q and the Hill-number profiles; presence/absence reduces them to their equal-weight forms. MPD, MNTD and PD use presence only.

Traits. FRic is 0 until there is at least one more species than traits, so with 4 traits keep at least 5 species per step and prefer 10 or more, since a range set by one or two extreme species changes with every new extreme. Use at least 2 traits: with a single trait functional diversity reduces to a one-dimensional range. Rao’s Q and FDis work with fewer species but become noisy below about 5.

Trees. The tree must cover every species in the matrix; it may contain further tips. MPD and MNTD stabilise with about 15 or more species and swing widely below 10, where one or two pairs decide the value. PD and EvoHeritage need a tree with branch lengths, not a distance matrix.

Number of seeds. Use at least 50 seeds for reporting and 100 or more when the band itself is the result; this article uses 10 to 20 to keep the build fast.

When not to use these. With fewer than about 5 species an abundance-weighted mean distance is decided by one or two pairs, so Rao’s Q and FDis curves over the first sites carry little information. With a single trait, FRic is that trait’s range and the other functional metrics are one-dimensional too.

Question Function Input Result
How evolutionary diversity accumulates spaccPhylo() presence/absence + tree MPD, MNTD, PD, EvoHeritage
How trait diversity accumulates spaccFunc() abundance + traits FDis, FRic, K
Abundance-weighted dispersion of traits or lineages spaccPhylo(metric = "rao"), spaccFunc(metric = "rao") abundance + tree or traits Rao’s Q
How fast species outpace lineages or trait combinations spaccRedundancy() abundance + tree or traits taxonomic / phylogenetic or functional Hill number
How interaction diversity accumulates spaccNetwork() one row per interaction interaction Hill numbers, coverage, connectance

Where next

References

  • Chao, A., Chiu, C.-H. & Jost, L. (2010). Phylogenetic diversity measures based on Hill numbers. Philosophical Transactions of the Royal Society B, 365, 3599-3609.
  • Chiu, C.-H., Chao, A., Vogel, S., Kriegel, P. & Thorn, S. (2023). Quantifying and estimating ecological network diversity based on incomplete sampling data. Philosophical Transactions of the Royal Society B, 378, 20220183. https://doi.org/10.1098/rstb.2022.0183
  • Faith, D.P. (1992). Conservation evaluation and phylogenetic diversity. Biological Conservation, 61, 1-10.
  • Laliberté, E. & Legendre, P. (2010). A distance-based framework for measuring functional diversity from multiple traits. Ecology, 91, 299-305.
  • Leinster, T. & Cobbold, C.A. (2012). Measuring diversity: the importance of species similarity. Ecology, 93, 477-489.
  • Palacio, F.X., Ottaviani, G., Mammola, S., Graco-Roza, C., de Bello, F. & Carmona, C.P. (2025). Integrating intraspecific trait variability in functional diversity: an overview of methods and a guide for ecologists. Ecological Monographs, 95, e70024. https://doi.org/10.1002/ecm.70024
  • Rao, C.R. (1982). Diversity and dissimilarity coefficients: a unified approach. Theoretical Population Biology, 21, 24-43.
  • Rosindell, J., Manson, K., Gumbs, R., Pearse, W.D. & Steel, M. (2024). Phylogenetic biodiversity metrics should account for both accumulation and attrition of evolutionary heritage. Systematic Biology, 73, 158-182. https://doi.org/10.1093/sysbio/syad072
  • Wojcik, L.A., Gaedke, U., van Velzen, E. & Klauschies, T. (2024). Measuring overall functional diversity by aggregating its multiple facets: functional richness, biomass evenness, trait evenness and dispersion. Methods in Ecology and Evolution, 16, 215-227. https://doi.org/10.1111/2041-210X.14470