Calculate Phylogenetic Mean Pairwise Distance (MPD) per Species per Site
calculate_phylo_mpd.Rd
This function computes the mean pairwise phylogenetic distance (MPD) for each species within sites, optionally weighting by species abundance and scaling the values relative to the maximum phylogenetic distance in the site.
Arguments
- phy
A phylogenetic tree of class phylo. Must contain all species present in df.
- df
A data frame containing species occurrence or abundance data. Must include columns: species, site, and presence_absence (1 for presence, 0 for absence).
- relative
Logical; if TRUE (default), MPD values are scaled by the maximum pairwise distance observed in the site's phylogeny, resulting in values between 0 and 1.
- weighted
Logical; if TRUE (default), MPD is abundance-weighted per species. If FALSE, unweighted MPD (simple mean of distances) is calculated.
Value
A data frame that includes all rows from df augmented with a new column EU (Evolutionary Uniqueness), representing the (scaled) mean pairwise phylogenetic distance for each species within each site. Species with fewer than two co-occurring species at a site receive NA.
Details
The function repeatedly prunes the phylogeny to include only species present each site. It calculates MPD for each species by averaging (or abundance-weighting) distances to other species present at the same site. Results are scaled relative to the maximum distance if relative = TRUE.
Examples
phy <- rtree(4)
#> Error in rtree(4): could not find function "rtree"
phy$tip.label <- c("Species1", "Species2", "Species3", "Species4")
#> Error: object 'phy' not found
df <- data.frame(
species = c("Species1", "Species2", "Species3", "Species4", "Species1"),
site = c("SiteA", "SiteA", "SiteB", "SiteB", "SiteB"),
presence_absence = c(1, 1, 1, 1, 1),
abundance = c(10, 5, 3, 8, 2)
)
result <- calculate_phylo_mpd(phy, df, relative = TRUE, weighted = TRUE)
#> Error: object 'phy' not found
print(result)
#> Error: object 'result' not found