[Picante-commits] r91 - branches/gsoc/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Jun 9 09:32:26 CEST 2008


Author: mrhelmus
Date: 2008-06-09 09:32:26 +0200 (Mon, 09 Jun 2008)
New Revision: 91

Modified:
   branches/gsoc/R/phylodiversity.R
Log:
Coded Faith's PD, the sum of the branch lengths of a community phylogeny.

Modified: branches/gsoc/R/phylodiversity.R
===================================================================
--- branches/gsoc/R/phylodiversity.R	2008-06-09 07:26:23 UTC (rev 90)
+++ branches/gsoc/R/phylodiversity.R	2008-06-09 07:32:26 UTC (rev 91)
@@ -444,3 +444,35 @@
   }
 }
 
+sum.bl<-function(samp,tree){
+  
+  # Make sure that the species line up
+  tree<-pruneMissing(samp[1,],tree)$tree
+  samp<-samp[,tree$tip.label]
+  species<-colnames(samp)
+  
+  # reduce given Cmatrix to the species observed in samp
+  SR<-rowSums(samp)
+  samp<-samp[SR>1,] # prune out locations with <2 species
+  SR<-SR[SR>1]
+
+  # numbers of locations and species
+  nlocations=dim(samp)[1]
+  nspecies=dim(samp)[2]
+
+  ##################################
+  # calculate observed PDs
+  #
+  PDs=NULL
+
+  for(i in 1:nlocations)
+  {  
+    index<-species[samp[i,]==0]	#species not in sample
+    sub.tree<-drop.tip(tree,index)
+    PDs<-c(PDs,sum(sub.tree$edge.length))
+  }
+  
+  PDout<-data.frame(cbind(PDs,SR))
+  rownames(PDout)<-rownames(samp) 
+  return(PDout)
+}
\ No newline at end of file



More information about the Picante-commits mailing list