[Picante-commits] r108 - pkg pkg/R pkg/man tags tags/0.2-0 tags/0.2-0/R tags/0.2-0/man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Jun 18 07:56:00 CEST 2008


Author: skembel
Date: 2008-06-18 07:56:00 +0200 (Wed, 18 Jun 2008)
New Revision: 108

Added:
   tags/0.2-0/
Modified:
   pkg/DESCRIPTION
   pkg/R/phylodiversity.R
   pkg/man/picante-package.Rd
   pkg/man/specaccum.psr.Rd
   tags/0.2-0/DESCRIPTION
   tags/0.2-0/R/phylodiversity.R
   tags/0.2-0/man/picante-package.Rd
   tags/0.2-0/man/specaccum.psr.Rd
Log:
Merging gsoc branch and tidying/tagging for 0.2-0 release

Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION	2008-06-16 08:09:59 UTC (rev 107)
+++ pkg/DESCRIPTION	2008-06-18 05:56:00 UTC (rev 108)
@@ -2,7 +2,7 @@
 Type: Package
 Title: Tools for integrating phylogenies and ecology
 Version: 0.2-0
-Date: 2008-6-10
+Date: 2008-6-17
 Author: Steve Kembel <skembel at berkeley.edu>, David Ackerly <dackerly at berkeley.edu>, Simon Blomberg <s.blomberg1 at uq.edu.au>, Peter Cowan <pdc at berkeley.edu>, Matthew Helmus <mrhelmus at wisc.edu>, Cam Webb <cwebb at oeb.harvard.edu>
 Maintainer: Steve Kembel <skembel at berkeley.edu>
 Depends: ape, vegan

Modified: pkg/R/phylodiversity.R
===================================================================
--- pkg/R/phylodiversity.R	2008-06-16 08:09:59 UTC (rev 107)
+++ pkg/R/phylodiversity.R	2008-06-18 05:56:00 UTC (rev 108)
@@ -151,18 +151,8 @@
     samp<-samp[,colnames(Cmatrix)]
   }
   
-    # 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]
-  
-    #cull the species that are not found in the samp set after all communities with 1 species are removed
-    preval<-colSums(samp)/sum(samp)
-    indexcov<-preval>0
-    Cmatrix<-Cmatrix[indexcov,indexcov]
-    samp<-samp[,indexcov]
-  
     # numbers of locations and species
+    SR<-rowSums(samp)
     nlocations<-dim(samp)[1]
     nspecies<-dim(samp)[2]
   
@@ -175,11 +165,16 @@
     {
       index<-seq(1:nrow(Cmatrix))[samp[i,]==1]	#species present
       n<-length(index)			#number of species present
-      C<-Cmatrix[index,index]	#C for individual locations
-      PSV<-(n*sum(diag(as.matrix(C)))-sum(C))/(n*(n-1))
-      PSVs<-c(PSVs,PSV)
+      if(n>1)
+      {
+        C<-Cmatrix[index,index]	#C for individual locations
+        PSV<-(n*sum(diag(as.matrix(C)))-sum(C))/(n*(n-1))
+      } else {
+        PSV<-NA
+      }
+        PSVs<-c(PSVs,PSV)
     }
-      PSVout<-cbind(PSVs,SR)
+    PSVout<-cbind(PSVs,SR)
   
   if(flag==2)
   {
@@ -224,14 +219,18 @@
   
       for (g in 1:nlocations)
       {
-        PSVout[g,3]<-PSVvar[PSVout[g,2]-1,2]
+        if(PSVout[g,2]>1)
+        {
+          PSVout[g,3]<-PSVvar[PSVout[g,2]-1,2]
+        } else {
+          PSVout[g,3]<-NA
+        }
       }
       return(data.frame(PSVout))
     }
   }
 }
 
-
 psr <- function(samp,tree,compute.var=TRUE){
   PSVout<-psv(samp,tree,compute.var)
   if(is.null(dim(PSVout))==TRUE) 
@@ -244,10 +243,12 @@
     PSRout<-cbind(PSVout[,1]*PSVout[,2],PSVout[,2])
     if(compute.var!=TRUE) {
       colnames(PSRout)<-c("PSR","SR")
+      rownames(PSRout)<-rownames(PSVout)
       return(data.frame(PSRout))
     } else {
       PSRout<-cbind(PSRout,PSVout[,3]*(PSVout[,2])^2)       
       colnames(PSRout)<-c("PSR","SR","vars")
+      rownames(PSRout)<-rownames(PSVout)
       return(data.frame(PSRout))
     }
   }
@@ -277,19 +278,8 @@
     samp<-samp[,colnames(Cmatrix)]
   }
   
-  # reduce given Cmatrix to the species observed in samp
-  SR<-apply(samp>0,1,sum)
-  # prune out locations with <2 species
-  samp<-samp[SR>1,]
-  SR<-SR[SR>1]
-
-  #cull the species that are not found in the samp set after all communities with 1 species are removed
-  preval<-colSums(samp)/sum(samp)
-  indexcov<-preval>0
-  Cmatrix<-Cmatrix[indexcov,indexcov]
-  samp<-samp[,indexcov]
-
   # numbers of locations and species
+  SR<-apply(samp>0,1,sum)
   nlocations<-dim(samp)[1]
   nspecies<-dim(samp)[2]
 
@@ -298,12 +288,15 @@
   PSEs<-NULL
   for(i in 1:nlocations){
     index<-seq(1,ncol(Cmatrix))[samp[i,]>0]	  # species present
-    C<-Cmatrix[index,index]		                #C for individual locations
     n<-length(index)                          #location species richness
+    if(n>1)
+    {    
+    C<-Cmatrix[index,index]		                #C for individual locations
     N<-sum(samp[i,])                          #location total abundance
     M<-samp[i,samp[i,]>0]                  #species abundance column
     mbar<-mean(M)                             #mean species abundance
     PSE<-(N*t(diag(as.matrix(C)))%*%M-t(M)%*%as.matrix(C)%*%M)/(N^2-N*mbar)   #phylogenetic species evenness
+    } else {PSE<-NA}
     PSEs<-c(PSEs,PSE)
   }
   PSEout=cbind(PSEs,SR)
@@ -316,6 +309,8 @@
   }
 }
 
+
+
 psc<-function(samp,tree){
   # Make samp matrix a pa matrix
   samp[samp>0]<-1
@@ -342,18 +337,8 @@
     samp<-samp[,colnames(Cmatrix)]
   }
 
-  # 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]
-
-  #cull the species that are not found in the samp set after all communities with 1 species are removed
-  preval<-colSums(samp)/sum(samp)
-  indexcov<-preval>0
-  Cmatrix<-Cmatrix[indexcov,indexcov]
-  samp<-samp[,indexcov]
-
   # numbers of locations and species
+  SR<-rowSums(samp)
   nlocations<-dim(samp)[1]
   nspecies<-dim(samp)[2]
 
@@ -366,10 +351,13 @@
   {
     index<-seq(1:nrow(Cmatrix))[samp[i,]==1]	#species present
     n<-length(index)			#number of species present
-    C<-Cmatrix[index,index]	#C for individual locations
-    diag(C)<--1
-    PSC<-sum(apply(C,1,max))/n
-    PSCs<-c(PSCs,PSC)
+    if(n>1)
+    {    
+      C<-Cmatrix[index,index]	#C for individual locations
+      diag(C)<--1
+      PSC<-sum(apply(C,1,max))/n
+    } else {PSC<-NA}
+      PSCs<-c(PSCs,PSC)
   }
     PSCout<-cbind(PSCs,SR)
  if (flag==2)
@@ -457,12 +445,8 @@
   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
+  SR<-rowSums(samp)
   nlocations=dim(samp)[1]
   nspecies=dim(samp)[2]
 
@@ -474,8 +458,14 @@
   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))
+    if(length(index)>=(nspecies-1))
+    {
+      PD<-NA
+    } else {
+      sub.tree<-drop.tip(tree,index)
+      PD<-sum(sub.tree$edge.length)
+    }
+      PDs<-c(PDs,PD)
   }
   
   PDout<-data.frame(cbind(PDs,SR))

Modified: pkg/man/picante-package.Rd
===================================================================
--- pkg/man/picante-package.Rd	2008-06-16 08:09:59 UTC (rev 107)
+++ pkg/man/picante-package.Rd	2008-06-18 05:56:00 UTC (rev 108)
@@ -13,7 +13,7 @@
 Package: \tab picante\cr
 Type: \tab Package\cr
 Version: \tab 0.2-0\cr
-Date: \tab 2008-06-10\cr
+Date: \tab 2008-06-17\cr
 License: \tab GPL-2\cr
 }
 }

Modified: pkg/man/specaccum.psr.Rd
===================================================================
--- pkg/man/specaccum.psr.Rd	2008-06-16 08:09:59 UTC (rev 107)
+++ pkg/man/specaccum.psr.Rd	2008-06-18 05:56:00 UTC (rev 108)
@@ -30,8 +30,8 @@
 
 \references{ Gotelli N.J. & Colwell R.K. (2001) Quantifying biodiversity: procedures and pitfalls in the measurement and comparison of species richness. Ecology Letters, 4, 379-391\cr
               \cr Helmus M.R., Bland T.J., Williams C.K. & Ives A.R. (2007) Phylogenetic measures of biodiversity. American Naturalist, 169, E68-E83 }
-\author{ Matthew Helmus \email{mrhelmus at gmail.com}
- }
+\author{ Matthew Helmus \email{mrhelmus at gmail.com} based on the \code{vegan} package \link[vegan]{specaccum} function by Roeland Kindt and Jari Oksanen. }
 \seealso{ \code{\link{psr}}, \code{\link[vegan]{specaccum}}}
 
 \keyword{univar}
+                                                                                                                 
\ No newline at end of file

Copied: tags/0.2-0 (from rev 107, pkg)

Modified: tags/0.2-0/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION	2008-06-16 08:09:59 UTC (rev 107)
+++ tags/0.2-0/DESCRIPTION	2008-06-18 05:56:00 UTC (rev 108)
@@ -2,7 +2,7 @@
 Type: Package
 Title: Tools for integrating phylogenies and ecology
 Version: 0.2-0
-Date: 2008-6-10
+Date: 2008-6-17
 Author: Steve Kembel <skembel at berkeley.edu>, David Ackerly <dackerly at berkeley.edu>, Simon Blomberg <s.blomberg1 at uq.edu.au>, Peter Cowan <pdc at berkeley.edu>, Matthew Helmus <mrhelmus at wisc.edu>, Cam Webb <cwebb at oeb.harvard.edu>
 Maintainer: Steve Kembel <skembel at berkeley.edu>
 Depends: ape, vegan

Modified: tags/0.2-0/R/phylodiversity.R
===================================================================
--- pkg/R/phylodiversity.R	2008-06-16 08:09:59 UTC (rev 107)
+++ tags/0.2-0/R/phylodiversity.R	2008-06-18 05:56:00 UTC (rev 108)
@@ -151,18 +151,8 @@
     samp<-samp[,colnames(Cmatrix)]
   }
   
-    # 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]
-  
-    #cull the species that are not found in the samp set after all communities with 1 species are removed
-    preval<-colSums(samp)/sum(samp)
-    indexcov<-preval>0
-    Cmatrix<-Cmatrix[indexcov,indexcov]
-    samp<-samp[,indexcov]
-  
     # numbers of locations and species
+    SR<-rowSums(samp)
     nlocations<-dim(samp)[1]
     nspecies<-dim(samp)[2]
   
@@ -175,11 +165,16 @@
     {
       index<-seq(1:nrow(Cmatrix))[samp[i,]==1]	#species present
       n<-length(index)			#number of species present
-      C<-Cmatrix[index,index]	#C for individual locations
-      PSV<-(n*sum(diag(as.matrix(C)))-sum(C))/(n*(n-1))
-      PSVs<-c(PSVs,PSV)
+      if(n>1)
+      {
+        C<-Cmatrix[index,index]	#C for individual locations
+        PSV<-(n*sum(diag(as.matrix(C)))-sum(C))/(n*(n-1))
+      } else {
+        PSV<-NA
+      }
+        PSVs<-c(PSVs,PSV)
     }
-      PSVout<-cbind(PSVs,SR)
+    PSVout<-cbind(PSVs,SR)
   
   if(flag==2)
   {
@@ -224,14 +219,18 @@
   
       for (g in 1:nlocations)
       {
-        PSVout[g,3]<-PSVvar[PSVout[g,2]-1,2]
+        if(PSVout[g,2]>1)
+        {
+          PSVout[g,3]<-PSVvar[PSVout[g,2]-1,2]
+        } else {
+          PSVout[g,3]<-NA
+        }
       }
       return(data.frame(PSVout))
     }
   }
 }
 
-
 psr <- function(samp,tree,compute.var=TRUE){
   PSVout<-psv(samp,tree,compute.var)
   if(is.null(dim(PSVout))==TRUE) 
@@ -244,10 +243,12 @@
     PSRout<-cbind(PSVout[,1]*PSVout[,2],PSVout[,2])
     if(compute.var!=TRUE) {
       colnames(PSRout)<-c("PSR","SR")
+      rownames(PSRout)<-rownames(PSVout)
       return(data.frame(PSRout))
     } else {
       PSRout<-cbind(PSRout,PSVout[,3]*(PSVout[,2])^2)       
       colnames(PSRout)<-c("PSR","SR","vars")
+      rownames(PSRout)<-rownames(PSVout)
       return(data.frame(PSRout))
     }
   }
@@ -277,19 +278,8 @@
     samp<-samp[,colnames(Cmatrix)]
   }
   
-  # reduce given Cmatrix to the species observed in samp
-  SR<-apply(samp>0,1,sum)
-  # prune out locations with <2 species
-  samp<-samp[SR>1,]
-  SR<-SR[SR>1]
-
-  #cull the species that are not found in the samp set after all communities with 1 species are removed
-  preval<-colSums(samp)/sum(samp)
-  indexcov<-preval>0
-  Cmatrix<-Cmatrix[indexcov,indexcov]
-  samp<-samp[,indexcov]
-
   # numbers of locations and species
+  SR<-apply(samp>0,1,sum)
   nlocations<-dim(samp)[1]
   nspecies<-dim(samp)[2]
 
@@ -298,12 +288,15 @@
   PSEs<-NULL
   for(i in 1:nlocations){
     index<-seq(1,ncol(Cmatrix))[samp[i,]>0]	  # species present
-    C<-Cmatrix[index,index]		                #C for individual locations
     n<-length(index)                          #location species richness
+    if(n>1)
+    {    
+    C<-Cmatrix[index,index]		                #C for individual locations
     N<-sum(samp[i,])                          #location total abundance
     M<-samp[i,samp[i,]>0]                  #species abundance column
     mbar<-mean(M)                             #mean species abundance
     PSE<-(N*t(diag(as.matrix(C)))%*%M-t(M)%*%as.matrix(C)%*%M)/(N^2-N*mbar)   #phylogenetic species evenness
+    } else {PSE<-NA}
     PSEs<-c(PSEs,PSE)
   }
   PSEout=cbind(PSEs,SR)
@@ -316,6 +309,8 @@
   }
 }
 
+
+
 psc<-function(samp,tree){
   # Make samp matrix a pa matrix
   samp[samp>0]<-1
@@ -342,18 +337,8 @@
     samp<-samp[,colnames(Cmatrix)]
   }
 
-  # 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]
-
-  #cull the species that are not found in the samp set after all communities with 1 species are removed
-  preval<-colSums(samp)/sum(samp)
-  indexcov<-preval>0
-  Cmatrix<-Cmatrix[indexcov,indexcov]
-  samp<-samp[,indexcov]
-
   # numbers of locations and species
+  SR<-rowSums(samp)
   nlocations<-dim(samp)[1]
   nspecies<-dim(samp)[2]
 
@@ -366,10 +351,13 @@
   {
     index<-seq(1:nrow(Cmatrix))[samp[i,]==1]	#species present
     n<-length(index)			#number of species present
-    C<-Cmatrix[index,index]	#C for individual locations
-    diag(C)<--1
-    PSC<-sum(apply(C,1,max))/n
-    PSCs<-c(PSCs,PSC)
+    if(n>1)
+    {    
+      C<-Cmatrix[index,index]	#C for individual locations
+      diag(C)<--1
+      PSC<-sum(apply(C,1,max))/n
+    } else {PSC<-NA}
+      PSCs<-c(PSCs,PSC)
   }
     PSCout<-cbind(PSCs,SR)
  if (flag==2)
@@ -457,12 +445,8 @@
   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
+  SR<-rowSums(samp)
   nlocations=dim(samp)[1]
   nspecies=dim(samp)[2]
 
@@ -474,8 +458,14 @@
   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))
+    if(length(index)>=(nspecies-1))
+    {
+      PD<-NA
+    } else {
+      sub.tree<-drop.tip(tree,index)
+      PD<-sum(sub.tree$edge.length)
+    }
+      PDs<-c(PDs,PD)
   }
   
   PDout<-data.frame(cbind(PDs,SR))

Modified: tags/0.2-0/man/picante-package.Rd
===================================================================
--- pkg/man/picante-package.Rd	2008-06-16 08:09:59 UTC (rev 107)
+++ tags/0.2-0/man/picante-package.Rd	2008-06-18 05:56:00 UTC (rev 108)
@@ -13,7 +13,7 @@
 Package: \tab picante\cr
 Type: \tab Package\cr
 Version: \tab 0.2-0\cr
-Date: \tab 2008-06-10\cr
+Date: \tab 2008-06-17\cr
 License: \tab GPL-2\cr
 }
 }

Modified: tags/0.2-0/man/specaccum.psr.Rd
===================================================================
--- pkg/man/specaccum.psr.Rd	2008-06-16 08:09:59 UTC (rev 107)
+++ tags/0.2-0/man/specaccum.psr.Rd	2008-06-18 05:56:00 UTC (rev 108)
@@ -30,8 +30,8 @@
 
 \references{ Gotelli N.J. & Colwell R.K. (2001) Quantifying biodiversity: procedures and pitfalls in the measurement and comparison of species richness. Ecology Letters, 4, 379-391\cr
               \cr Helmus M.R., Bland T.J., Williams C.K. & Ives A.R. (2007) Phylogenetic measures of biodiversity. American Naturalist, 169, E68-E83 }
-\author{ Matthew Helmus \email{mrhelmus at gmail.com}
- }
+\author{ Matthew Helmus \email{mrhelmus at gmail.com} based on the \code{vegan} package \link[vegan]{specaccum} function by Roeland Kindt and Jari Oksanen. }
 \seealso{ \code{\link{psr}}, \code{\link[vegan]{specaccum}}}
 
 \keyword{univar}
+                                                                                                                 
\ No newline at end of file



More information about the Picante-commits mailing list