4. Check Numerical Correctness of IndicesSource:
Most research results nowadays rely heavily on results generated by computational software. Yet, this software, while occupying an increasingly central place in science, is often poorly tested. Users are never presented any arguments about why they should trust the code provided to them.
We want to contribute to change this trend and in this vignette, we
show that indices computed by
fundiversity behave as
theoretically expected, and as presented in Villéger, Mason, and Mouillot (2008). We
also internally compared
fundiversity results with ones
obtained by other packages. You can see the equivalence between
functions in the benchmark
vignette that compares
fundiversity and alternative
For this, we reproduce the Figure 2 (including all of their facets) of their article. If you re-use this figure, please cite the original article.
We start by reproducing Figure 2 a, to check that the values computed
fundiversity are correct. These are the data found in
Figure 2 of the article:
data_a <- matrix(byrow = TRUE, ncol = 2, c( 0.0, 1.0, 0.5, 1.0, 1.0, 1.0, 1.5, 1.0, 2.0, 1.0, 1.0, 0.0, 1.0, 0.5, 1.0, 1.5, 1.0, 2.0 ) ) rownames(data_a) <- paste0("species", seq_len(nrow(data_a))) print(data_a) #> [,1] [,2] #> species1 0.0 1.0 #> species2 0.5 1.0 #> species3 1.0 1.0 #> species4 1.5 1.0 #> species5 2.0 1.0 #> species6 1.0 0.0 #> species7 1.0 0.5 #> species8 1.0 1.5 #> species9 1.0 2.0
plot(data_a, pch = 19, asp = 1, xlab = "Trait 1", ylab = "Trait 2")
We then compute the functional diversity indices.
As expected, we found an FRic value of 2 (should be 2), an FEve value of 1 (should be 1), and a FDiv value of 0.692 (should be 0.692).
If we change the abundance, but not the coordinates (i.e., not the species characteristics), we expect changes in FEve and FDiv but not FRic.
More precisely, equal increases in abundance for the species at the vertices of the convex hull don’t influence FEve, but lead to a higher FDiv. These correspond to the data found in panel c of the Figure 2.
We compute again the functional diversity indices:
As expected, we found an FRic value of 2 (should be 2), an FEve value of 1 (should be 1), and a FDiv value of 0.714 (should be 0.714).
Conversely, changes of abundances on a single trait axis don’t impact FDiv but reduce FEve (this correspond to the panel b of Figure 2):
We can compute weighted functional diversity indices:
As expected, we found an FRic value of 2 (should be 2), an FEve value of 0.778 (should be 0.778), and a FDiv value of 0.692 (should be 0.692).
We now change the species characteristics (i.e., the coordinates) instead of the abundances. The changes of coordinates without changing abundances can affect all diversity indices. If the coordinates are only changed for species that are not on the convex hull would only affect FEve and FDiv.
For example, we can change the coordinates of species to be at the same distance of the centroid of the species, so that it doesn’t affect the value of FDiv, but put them further away from points on the convex hull. This would decrease FEve because species would be spaced less evenly in the space (it corresponds to panel d of Figure 2):
As expected, we found an FRic value of 2 (should be 2), an FEve value of 0.891 (should be 0.891), and a FDiv value of 0.692 (should be 0.692).
We can also change the coordinates of species (their traits) to only affect FDiv and not FEve by, instead, moving species on the convex hull while keeping their distance to other points equal. This corresponds to the panel e Figure 2 of the paper:
We can then compute functional diversity indices:
As expected, we found an FRic value of 2 (should be 2), an FEve value of 1 (should be 1), and a FDiv value of 0.78 (should be 0.78).