tax2dist: Generate taxonomic distance matrix

View source: R/tax2dist.R

tax2distR Documentation

Generate taxonomic distance matrix

Description

Calculates taxonomic distances between species.

Usage

tax2dist(lookup, tax_distance, precompute_dist = TRUE)

Arguments

lookup

data.frame with colnames corresponding to nested taxonomic levels, e.g. c('Species', 'Genus', 'Family', 'Subclass'), and a row for each species

tax_distance

named vector with the distance attributed to each taxonomic level of lookup, listed from the lowest level up, and then the distance attributed to species that are not the same at any recorded taxonomic level, under a name that is not a column of lookup. The distances must not decrease. e.g. c(Species = 0, Genus = 1, Family = 2, Subclass = 3, Other = 4) from Shimatani.

precompute_dist

object of class logical or numeric. When TRUE (by default) a distance matrix is generated and stored in slot distance, when FALSE no distance matrix is generated, and when numeric a distance matrix is generated until the number of species exceeds the defined value. When it is not set, a taxonomy of more than 10,000 species is an error because of its size. TRUE generates a distance matrix of any size.

Details

Two species are at the distance of the lowest taxonomic level they share. Each row of lookup is a species, with a name of its own at the lowest level. A name at a higher level belongs to one taxon, so it must be under the same name at the level above wherever it appears: a genus cannot be in two families. tax2dist() gives an error otherwise.

Without a distance matrix, metacommunity() calculates the same diversity from the abundance of each taxon. That suits a taxonomy too large for a matrix. A matrix for 10,000 species takes 0.8 GB, so for more species than that tax2dist() gives an error unless precompute_dist is set.

Value

tax2dist() returns an object of class distance containing a matrix of pairwise taxonomic distances

References

Shimatani, K. 2001. On the measurement of species diversity incorporating species differences. Oikos 93:135–147.

Examples

# Create Lookup table
Species <- c("tenuifolium", "asterolepis", "simplex var.grandiflora", "simplex var.ochnacea")
Genus <- c("Protium", "Quararibea", "Swartzia", "Swartzia")
Family <- c("Burseraceae", "Bombacaceae", "Fabaceae", "Fabaceae")
Subclass <- c("Sapindales", "Malvales", "Fabales", "Fabales")
lookup <- cbind.data.frame(Species, Genus, Family, Subclass)

# Assign values for each level (Shimatani's taxonomic distance)
tax_distance <- c(Species = 0, Genus = 1, Family = 2, Subclass = 3, Other = 4)

# Generate pairwise distances
distance <- tax2dist(lookup, tax_distance)
similarity <- dist2sim(distance, "linear")


rdiversity documentation built on Dec. 3, 2026, 9:07 a.m.