Skip to content

Instantly share code, notes, and snippets.

@darmitage
Created December 12, 2011 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darmitage/1469414 to your computer and use it in GitHub Desktop.
Save darmitage/1469414 to your computer and use it in GitHub Desktop.
histograms of phylogenetic similarity
require(picante)
#function that maps dissimilarity to similarity & scales between 0 and 1
range01 <- function(x){exp((-1/max(x))*x)}
#Calculate branch lengths bewteen taxa
dist <- cophenetic(tree)
#calculate similarity between taxa from 0 to 1
Z <- range01(dist)
hist(Z)
#if you have a community matrix and want to do a site-by-site comparison of distances, you need to subset your matrix
#X = your site of interest (should be a row or set of rows in a community matrix)
site <- subset(names(samp[X,]), samp[X,] > 0)
Z <- Z[site,site]
upper <- col(Z) <= row(Z)
Z <- Z[upper]
hist(Z)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment