#####script to caculate functional diverisy metrics from trait and community composition datasets. Calculates FAD (Walker et al. 1999) and FD (Petchey and Gaston 2002). dat, this is a trait matrix, where col 1 is species names and col 2...n are various continuous traits (or 1 & 0 for discrete states). ##Needs ape ###written by Marc W Cadotte ####Nov 2009 funcDiv <- function(dat){ species<-dat[,1] traits<-scale(dat[,2:ncol(dat)]) h<-hclust(dist(traits),method="average") h$labels<-species[h$order] h.phy <- as.phylo(h) FD <- sum(h.phy$edge.length) FAD<-sum(dist(traits)) return(cbind(FAD,FD)) }