Skip to content

Calculating FD

Calculating FD
Below is advice for using some code and functions in R that use the same matrix notation as in Petchey & Gaston (2002). They’re updated to account for the development to FD that we published in 2006 (Petchey & Gaston 2006).


  1. Get the code and example datasets from here.
  2. Gain an understanding of how to use R.
  3. Use the dist() and hclust() functions to calculate a dendrogram from a trait matrix.
  4. Paste the Xtree function into R. Use it to transform the object returned by hclust() into an object from which total branch is easy to calculate.
  5. The object returned by Xtree() is a list containing a species by branch matrix (H1) and a branch length vector (h2) (see Petchey & Gaston (2002) for more information on these).
  6. Follow the methods in Petchey & Gaston (2002) to get FD from H1 and h2.

The FD.example.1.r file contains an example of using R to calculate the FD of a random community as it loses species; just paste the text into R. (Remember to paste in Xtree()!)

And here‘s an example of how to calculate the FD of communities that have different composition, and to see if FD correlates with an arbitrary measure of functioning).

And finally, for now, there is a demonstration of differences between FD and variance calculated on a single trait. See the file FDandvariance.r