## 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).

**Instructions**

- Get the code and example datasets from here.
- Gain an understanding of how to use R.
- Use the dist() and hclust() functions to calculate a dendrogram from a trait matrix.
- 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.
- 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).
- 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