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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Jun 27 07:46:18 CEST 2008


Author: mrhelmus
Date: 2008-06-27 07:46:18 +0200 (Fri, 27 Jun 2008)
New Revision: 123

Modified:
   branches/gsoc/R/sppregs.R
Log:
Cleaned up tree and Cmatrix handling in sppregs

Modified: branches/gsoc/R/sppregs.R
===================================================================
--- branches/gsoc/R/sppregs.R	2008-06-25 07:18:59 UTC (rev 122)
+++ branches/gsoc/R/sppregs.R	2008-06-27 05:46:18 UTC (rev 123)
@@ -10,14 +10,20 @@
     if(is(tree)[1]=="phylo")
     {
       tree<-prune.sample(samp,tree)
+      # Make sure that the species line up
+      samp<-samp[,tree$tip.label]
       # Make a correlation matrix of the species pool phylogeny
       Cmatrix<-vcv.phylo(tree,cor=TRUE)
     } else {
       Cmatrix<-tree
-      Cmatrix<-Cmatrix[sppnames,sppnames]
+      species<-colnames(samp)
+      preval<-colSums(samp)/sum(samp)
+      species<-species[preval>0]
+      Cmatrix<-Cmatrix[species,species]
+      samp<-samp[,colnames(Cmatrix)]
     }
-  cors.phylo<-Cmatrix[lower.tri(Cmatrix)] #vector of pairwise phylogenetic correlations among species
-  samp<-samp[,colnames(Cmatrix)]          #only those species in the phylogeny are regressed
+    cors.phylo<-Cmatrix[lower.tri(Cmatrix)] #vector of pairwise phylogenetic correlations among species
+    samp<-samp[,colnames(Cmatrix)]          #only those species in the phylogeny are regressed
   }
   
   nplots<-dim(samp)[1]     # number of units in the occurence data



More information about the Picante-commits mailing list