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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Jun 4 11:04:56 CEST 2008


Author: mrhelmus
Date: 2008-06-04 11:04:56 +0200 (Wed, 04 Jun 2008)
New Revision: 86

Modified:
   branches/gsoc/R/phylodiversity.R
Log:
Fix Bug: PSR works on just one community

Added Code: PSDcalc, a function that does PSV, PSR, and PSE on one data set. Use this function to document all of PSV,PSR,PSE together.

Modified: branches/gsoc/R/phylodiversity.R
===================================================================
--- branches/gsoc/R/phylodiversity.R	2008-06-04 07:56:08 UTC (rev 85)
+++ branches/gsoc/R/phylodiversity.R	2008-06-04 09:04:56 UTC (rev 86)
@@ -217,7 +217,7 @@
 
 PSRcalc <- function(samp,tree,compute.var=TRUE){
   PSVout<-PSVcalc(samp,tree,compute.var)
-  if(length(PSVout)==2) 
+  if(is.null(dim(PSVout))==TRUE) 
   {
     PSRout<-data.frame(cbind(PSVout[1]*PSVout[2],PSVout[2]))
     names(PSRout)<-c("PSR","SR")
@@ -294,7 +294,6 @@
   }
 }
 
-
 PSCcalc<-function(samp,tree,compute.var=TRUE){
   # Make samp matrix a pa matrix
   samp[samp>0]<-1
@@ -399,4 +398,23 @@
   spp.PSVout<-(spp.PSVs-obs.PSV)/sum(abs(spp.PSVs-obs.PSV))
   names(spp.PSVout)<-colnames(samp)
   return(spp.PSVout)
+}
+
+PSDcalc<-function(samp,tree,compute.var=TRUE){
+  if (is.null(dim(samp))) #if the samp matrix only has one site
+  {
+    PSDout<-data.frame(c(PSVcalc(samp,tree,compute.var)[1],PSRcalc(samp,tree,compute.var)[1],PSEcalc(samp,tree)))
+    names(PSDout)<-c("PSV","PSR","PSE","SR")
+    return(PSDout)
+  } else {
+    if (compute.var==TRUE)
+    {
+      PSDout<-cbind(PSVcalc(samp,tree,compute.var)[,c(1,3)],PSRcalc(samp,tree,compute.var)[,c(1,3)],PSEcalc(samp,tree))
+      colnames(PSDout)<-c("PSV","var.PSV","PSR","var.PSR","PSE","SR")
+    } else {
+      PSDout<-cbind(PSVcalc(samp,tree,compute.var)[,1],PSRcalc(samp,tree,compute.var)[,1],PSEcalc(samp,tree))
+      colnames(PSDout)<-c("PSV","PSR","PSE","SR")
+    }
+    return(data.frame(PSDout))
+  }
 }
\ No newline at end of file



More information about the Picante-commits mailing list