phylo.d: Calculates the phylogenetic D statistic

View source: R/phylo.d.R

phylo.dR Documentation

Calculates the phylogenetic D statistic


Calculates the D value, a measure of phylogenetic signal in a binary trait, and tests the estimated D value for significant departure from both random association and the clumping expected under a Brownian evolution threshold model.


phylo.d(data, phy, names.col, binvar, permut = 1000, rnd.bias=NULL)
## S3 method for class 'phylo.d'
print(x, ...)
## S3 method for class 'phylo.d'
summary(object, ...)
## S3 method for class 'phylo.d'
plot(x, bw=0.02, ...)



A '' or 'data.frame' object.


An object of class 'phylo', required when data is not a '' object.


A name specifying the column in 'data' that matches rows to tips in 'phy', required when data is not a '' object.


The name of the variable in data holding the binary variable of interest.


Number of permutations to be used in the randomisation test.


An optional name of a variable in data holding probability weights to bias the generation of the random distribution. See 'destails'


An object of class 'phylo.d'


An object of class 'phylo.d'


The bandwidth to be used for the density plots


Further arguments to print and summary methods


The sum of changes in estimated nodal values of a binary trait along edges in a phylogeny (D) provides a measure of the phylogenetic signal in that trait (Fritz and Purvis, 2010). If a trait is highly conserved, with only a basal division between two clades expressing either trait value, then the only change will be along the two daughters at the root. This will give a summed value of 1: the two differences between the root nodal value of 0.5 and the ancestors of the 1 and 0 clades. In contrast, if the trait is labile, more differences will be observed and the sum will be higher.

This function calculates the observed D for a binary trait on a tree and compares this to the value of D found using an equal number of simulations under each of two models:

Phylogenetic randomness

Trait values are randomly shuffled relative to the tips of the phylogeny and D is calculated.

Brownian threshold model

A continuous trait is evolved along the phylogeny under a Brownian process and then converted to a binary trait using a threshold that reproduces the relative prevalence of the observed trait.

The value of D depends on phylogeny size - more sister clades yield higher sums - and so the means of the two sets of simulated data are used as calibrations to scale both observed and simulated values of D to set points of 0 (as phylogenetically conserved as expected under a Brownian threshold model) and 1 (random). The value of D can be both smaller than 0 (highly conserved) and greater than 1 (overdispersed) and the distributions of scaled D from the simulations are used to assess the significance of the observed scaled D. The plot method generates density plots of the distributions of the two simulations relative to the observed D value.

rnd.bias is passed to sample as the prob argument to weight the random shuffles of the observed trait. The weights are not checked for validity.


Returns an object of class 'phylo.d', which is a list of the following:


The estimated D value


A p value, giving the result of testing whether D is significantly different from one


A p value, giving the result of testing whether D is significantly different from zero


A list of the Observed, MeanRandom and MeanBrownian sums of sister-clade differences


A list with elements random and brownian, containing the sums of sister-clade differences from random permutations and simulations of Brownian evolution under a threshold model


A list with the elements observed, random and brownian, containing the nodal values estimated for the observed trait and permutations. The values are as matrices with rows labelled by the node names in the comparative data object.


The binary variable used


The name of the phylogeny object used


The name of the dataframe used


The number of permutations used


If a bias was introduced to the calculation of the random distribution, the bias used, else NULL


Susanne Fritz <> and David Orme


Fritz, S. A. and Purvis, A. (2010). Selectivity in mammalian extinction risk and threat types: a new measure of phylogenetic signal strength in binary traits. Conservation Biology, 24(4):1042-1051.


BritishBirds <-,, binomial)
redPhyloD <- phylo.d(BritishBirds, binvar=Red_list)

caper documentation built on Sept. 26, 2023, 5:10 p.m.