--- title: "Partitioning beta diversity" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Partitioning beta diversity} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r, include = FALSE} knitr::opts_chunk$set( dev.args = list(bg = "white"), collapse = TRUE, comment = "#>", fig.width = 7, fig.height = 4 ) ``` ```{r setup} library(tidydiversity) library(dplyr) library(ggplot2) ``` Beta diversity measures how communities differ. Baselga (2010) showed that dissimilarity has two parts: **turnover**, where species replace each other, and **nestedness**, where poorer sites hold a subset of the species at richer sites. The examples use `png_ants`, ants at nutrient baits along Mt Wilhelm, Papua New Guinea (Moses et al. 2023). ## The concept Two communities can differ in two ways: | Pattern | Example | What it suggests | |---|---|---| | **Turnover** (replacement) | Lowland species are replaced by different montane species | Environmental filtering, dispersal barriers, history | | **Nestedness** (loss) | The montane site holds only a subset of the lowland species | Species lost along a gradient of harshness or habitat area | The Sørensen dissimilarity (0 = same species, 1 = no species shared) mixes both. Baselga's partition splits it into turnover (Simpson dissimilarity) and nestedness, which add up to the total, so you can say *how* sites differ, not only *how much*. Conservation advice differs: with turnover every site is needed to protect the species; with nestedness the richest site protects most of them. ## Pairwise dissimilarity ```{r} pairs <- beta_pair(png_ants, .by = season) pairs ``` Turnover and nestedness add up to the total. Use `index = "jaccard"` for the Jaccard family. The results match the betapart package. ```{r} pairs |> group_by(season) |> summarise(across(c(turnover, nestedness, total), mean)) ``` **How to read it.** Sites differ strongly (mean total dissimilarity 0.86-0.87: on average a pair shares only about 13% of its species), and almost all of the difference is turnover (0.82-0.83) rather than nestedness (0.04). Ant species are *replaced* along Mt Wilhelm, not simply lost. Several high-elevation pairs share no species at all (total = 1). ## Many sites at once ```{r} beta_multi(png_ants, .by = season) ``` The multiple-site version measures dissimilarity among all five sites at once (Baselga 2010) and tells the same story: turnover dominates in both seasons. ## Distance decay `beta_decay()` adds the distance between sites along a gradient. Here turnover rises with elevational distance while nestedness stays low. ```{r} decay <- beta_decay(png_ants, gradient = elevation, .by = season) decay ``` ```{r, fig.alt = "Dissimilarity against elevational distance"} autoplot(decay) ``` `beta_decay_model()` fits a distance-decay curve to the similarities (one minus dissimilarity) and tests it. The exponential model S = a exp(-b d) gives the similarity `a` between sites at the same elevation and the rate `b`; `half_distance` is the elevational distance over which similarity halves. Pairs of sites share sites, so they are not independent: the p-value comes from permuting site labels, as in a Mantel test, and refitting the model each time. ```{r} set.seed(1) beta_decay_model(decay, permutations = 999) ``` **How to read it.** In the wet season similarity decays steeply with elevational distance: it halves every `r round(beta_decay_model(decay, permutations = 0)$half_distance[2])` m, the curve explains 69% of the variation among pairs (`pseudo_r2`), and the permutation test is significant (*P* = 0.017). In the dry season the curve is flat and not significant (*P* = 0.35): sites near each other are already very dissimilar (`a` = 0.26, the similarity at zero distance), because sparse dry-season samples share few species by chance. With only five sites per season there are 120 distinct permutations, so the smallest attainable p-value is near 0.01 however strong the pattern. ## Shared species and similarity corrected for unseen species Classic Jaccard and Sørensen indices count only the species seen in both samples. A species shared by two sites but rare in one is easily missed, so incomplete samples look less similar than they are. Chao et al. (2000, 2005) estimate what was missed: ```{r shared} shared <- beta_shared(png_ants, unit = bait, n_units = baits, .by = season) filter(shared, season == "wet") ``` **How to read it.** `observed` is the number of species seen at both sites, `estimate` the estimated number truly shared. 200 m and 700 m share 8 observed species but an estimated 28: most shared species were found at only one bait in one of the two sites. Pairs with no observed shared species (all pairs with 2200 m) get no correction, because the estimator extrapolates only from shared species that were seen. ```{r chao-sim} chao <- beta_chao(png_ants, .by = season) filter(chao, season == "wet") |> select(site_1, site_2, jaccard, chao_jaccard, sorensen, chao_sorensen) ``` **How to read it.** The Chao indices weight species by their abundance (or incidence), so they measure the share of *individuals* belonging to shared species, corrected for shared species that were missed. Where the shared species are common, they are larger than the classic indices, which count species only. Between 200 m and 700 m, Sørensen similarity rises from `r round(chao$sorensen[chao$season == "wet" & chao$site_1 == "MW0200" & chao$site_2 == "MW0700"], 2)` to `r round(chao$chao_sorensen[chao$season == "wet" & chao$site_1 == "MW0200" & chao$site_2 == "MW0700"], 2)`: the two lowland sites are much more alike than their species lists suggest. Where the few shared species are rare at both sites (200 m and 1700 m), the Chao index is smaller than the classic one. Elevations far apart remain dissimilar under both indices, so the turnover along the mountain is real, not an artefact of sampling. ## Hill-number dissimilarity between pairs of sites Presence-absence indices treat a species with one worker like one with a thousand. `beta_hill_pair()` computes the Hill-number framework of Chao, Chiu and Jost (2014) for every pair of sites, so the order q sets how much weight common species get. At q = 0 `dis_sorensen` and `dis_jaccard` are the classic Sorensen and Jaccard indices; at q = 2 `dis_sorensen` is the Morisita-Horn index, driven by the dominant species. ```{r} wet <- dplyr::filter(png_ants, season == "wet") hp <- beta_hill_pair(wet, abundance = workers) hp ``` **How to read it.** `gamma` is the diversity of the two sites pooled, `alpha` the mean diversity per site, and `beta` = gamma / alpha the effective number of distinct communities: 1 if the two sites are identical, 2 if they share nothing. `dis_sorensen` rescales it to 0-1. ```{r, fig.alt = "Heatmaps of Sorensen-type dissimilarity between sites for q = 0, 1 and 2", fig.height = 3.6, fig.width = 9} autoplot(hp) ``` `beta_dist()` turns one order into a distance matrix for ordination, clustering or PERMANOVA: ```{r} beta_dist(hp, q = 2) ``` At q = 2 (Morisita-Horn), 700 m and 1200 m are fairly similar (0.54) although they share under half their species: their dominant species are the same. Read the three heatmaps together: dissimilarity that grows from q = 0 to q = 2 means the sites differ most in their *common* species. ## Beta diversity at equal sample coverage Beta diversity estimated from samples depends on sample size and completeness, so regions sampled with different effort cannot be compared directly. `beta_hill()` follows the iNEXT.beta3D framework of Chao et al. (2023): gamma and alpha Hill numbers are each standardised to the same sample coverage, and beta = gamma / alpha is the effective number of completely distinct sites (1 to the number of sites). ```{r} beta_hill(png_ants, .by = season) ``` **How to read it.** At `r round(beta_hill(png_ants, .by = season)$coverage[1], 3)` coverage, the five dry-season sites hold the equivalent of 3.1 completely distinct communities out of a possible 5 (`beta`), and the wet-season sites 2.8. `gamma` is the regional diversity and `alpha` the mean per site. Beta rises from q = 0 to q = 2, so the sites differ even more in their dominant species than in their species lists. The four `dis_` columns rescale beta to 0-1. `dis_sorensen` and `dis_jaccard` measure non-overlap (for q = 0 they are the classic Sorensen and Jaccard dissimilarities); the `turnover` versions measure species turnover. Give `coverage` to compare regions at chosen levels: ```{r} beta_hill(png_ants, q = 0, coverage = c(0.8, 0.9), .by = season) ``` Add `nboot` for bootstrap confidence intervals. The same function gives phylogenetic (`type = "PD"`, with `tree`) and functional (`type = "FD"`, with `distance`) beta diversity, and works on incidence data with `unit` when the same sampling units (plots, visits) were surveyed at every site. ```{r} set.seed(1) b <- beta_hill(png_ants, q = 0, coverage = 0.9, nboot = 20, .by = season) b[c("season", "beta", "beta_lower", "beta_upper")] ``` **Interpretation.** At 90% coverage, beta diversity is 3.1 in the dry season and 2.7 in the wet season, but the bootstrap intervals overlap widely (2.6-3.6 and 2.0-3.5): there is no evidence that turnover along the mountain differs between seasons. ## How to report it > Beta diversity among elevations was partitioned into turnover and > nestedness components of Sørensen dissimilarity (Baselga 2010) with > tidydiversity. Turnover accounted for 95% of the total dissimilarity > (mean pairwise turnover 0.82, nestedness 0.04). In the wet season, > similarity decayed exponentially with elevational distance (half > distance 293 m, pseudo-R² = 0.69, permutation *P* = 0.017). At equal > sample coverage (90%; Chao et al. 2023), the five elevations > represented 3.1 (95% CI 2.6-3.6) effectively distinct communities in > the dry season and 2.7 (2.0-3.5) in the wet season. ## References Baselga, A. (2010). Partitioning the turnover and nestedness components of beta diversity. *Global Ecology and Biogeography*, 19, 134-143. Chao, A., Chazdon, R. L., Colwell, R. K. and Shen, T.-J. (2005). A new statistical approach for assessing similarity of species composition with incidence and abundance data. *Ecology Letters*, 8, 148-159. Chao, A., Hwang, W.-H., Chen, Y.-C. and Kuo, C.-Y. (2000). Estimating the number of shared species in two communities. *Statistica Sinica*, 10, 227-246. Chao, A., Chiu, C.-H. and Jost, L. (2014). Unifying species diversity, phylogenetic diversity, functional diversity, and related similarity and differentiation measures through Hill numbers. *Annual Review of Ecology, Evolution, and Systematics*, 45, 297-324. Chao, A. et al. (2023). Rarefaction and extrapolation with beta diversity under a framework of Hill numbers: the iNEXT.beta3D standardization. *Ecological Monographs*, 93, e1588.