####function to calculate the sum of absolute phylogentically independent contrasts values and compare them to null values. Requires the package "ape". Arguments: dat is a vector of values sorted according to species in phylogeny, tree is the phylogeny and n.rand is the number of randomizations. Example sorting: dat<-trait.data$trait1[match(tree$tip.label,trait.data$species)] pic.func<-function(dat,tree,n.rand=1000){ pic.null<-NULL for (i in 1:n.rand){ tmp<-sample(dat,size=length(dat)) pic.null[i]<-sum(abs(pic(tmp,tree))) } results<-data.frame(pic.obs=sum(abs(pic(dat,tree))), pic.null.mean=mean(pic.null), pic.null.05=quantile(pic.null,probs=c(0.05,0.95))[1], pic.null.95=quantile(pic.null,probs=c(0.05,0.95))[2], row.names=NULL ) return(results) }