[Picante-commits] r233 - pkg pkg/R pkg/inst/doc pkg/man www

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Apr 23 01:44:26 CEST 2011


Author: skembel
Date: 2011-04-23 01:44:26 +0200 (Sat, 23 Apr 2011)
New Revision: 233

Added:
   pkg/R/pcd.R
   pkg/man/pcd.Rd
Modified:
   pkg/DESCRIPTION
   pkg/R/phylodiversity.R
   pkg/inst/doc/picante-intro.pdf
   pkg/man/picante-package.Rd
   www/index.php
Log:
Add pcd function, pse single-community bugfix, web/package updates for 1.3 release

Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION	2010-07-18 21:06:09 UTC (rev 232)
+++ pkg/DESCRIPTION	2011-04-22 23:44:26 UTC (rev 233)
@@ -1,8 +1,8 @@
 Package: picante
 Type: Package
 Title: R tools for integrating phylogenies and ecology
-Version: 1.2-0
-Date: 2010-7-18
+Version: 1.3-0
+Date: 2011-4-22
 Author: Steven W. Kembel <skembel at uoregon.edu>, David D. Ackerly <dackerly at berkeley.edu>, Simon P. Blomberg <s.blomberg1 at uq.edu.au>, Will K. Cornwell <cornwell at zoology.ubc.ca>, Peter D. Cowan <pdc at berkeley.edu>, Matthew R. Helmus <mrhelmus at wisc.edu>, Helene Morlon <morlon.helene at gmail.com>, Campbell O. Webb <cwebb at oeb.harvard.edu>
 Maintainer: Steven W. Kembel <skembel at uoregon.edu>
 Depends: ape, vegan, nlme

Added: pkg/R/pcd.R
===================================================================
--- pkg/R/pcd.R	                        (rev 0)
+++ pkg/R/pcd.R	2011-04-22 23:44:26 UTC (rev 233)
@@ -0,0 +1,134 @@
+#Phylogenetic Community Dissimilarity from
+#Ives A.R. & Helmus M.R. (2010). Phylogenetic metrics of community similarity. The American Naturalist, 176, E128-E142.
+
+pcd <- function(comm, tree, PSVmncd=NULL, PSVpool=NULL, reps=10^4)
+{
+  SSii<-PSVmncd
+  SCii<-PSVpool
+
+  # Make comm matrix a pa matrix
+  comm[comm>0]<-1
+
+	# convert trees to VCV format
+	if (is(tree)[1] == "phylo")
+  {
+		if (is.null(tree$edge.length)) {tree <- compute.brlen(tree, 1)}    #If phylo has no given branch lengths
+		tree <- prune.sample(comm, tree)
+		V <- vcv.phylo(tree, cor = TRUE)
+		comm <- comm[, tree$tip.label]
+	} else {
+		V <- tree
+    species<-colnames(comm)
+    preval<-colSums(comm)/sum(comm)
+    species<-species[preval>0]
+    V<-V[species,species]
+    comm<-comm[,colnames(V)]
+  }
+
+  if (!is.null(SSii) & length(SSii)!=max(rowSums(comm))) {
+        stop("The length of PSVmncd is not equal to the species richness of the community with the highest species richness. Set PSVmncd=NULL, PSVpool=NULL and run pcd again.")
+  }
+
+	# m=number of communities; n=number of species; nsr=maximum sr value across all communities
+	m <- dim(comm)[1]
+	n <- dim(comm)[2]
+  nsr <-max(rowSums(comm))
+  if(is.null(SSii) & is.null(SCii))   #If the user already has calculated the mean conditional PSV values for all levels of SR
+  {                                   #and the PSV of the species pool
+  	SSii <- array(0,nsr)
+  	n1 <- 2
+  	for (n2 in 1:nsr)
+  	{
+  		temp <- array(0,reps)
+  		for (t in 1:reps)
+  		{
+  			rp <- sample(n)
+  			pick1 <- rp[1:n1]
+
+  			rp <- sample(n)
+  			pick2 <- rp[1:n2]
+
+  			C11 <- V[pick1,pick1]
+  			C22 <- V[pick2,pick2]
+  			C12 <- V[pick1,pick2]
+
+  			invC22 <- solve(C22)
+  			S11 <- C11 - C12%*%invC22%*%t(C12)
+  			SS11 <- (n1*sum(diag(S11))-sum(S11))/(n1*(n1-1))
+  			temp[t] <- SS11
+  		}
+  		SSii[n2] <- mean(temp)
+  	}
+  	SCii=1-(sum(V)-sum(diag(V)))/(n*(n-1))
+  }
+
+	# calculate PCD
+	PCD <- array(NA,c(m,m))
+	PCDc <- array(NA,c(m,m))
+	PCDp <- array(NA,c(m,m))
+	for (i in 1:(m-1))
+	{
+		for (j in (i+1):m)
+		{
+			pick1 <- (1:n)[comm[i,]==1]
+ 			pick2 <- (1:n)[comm[j,]==1]
+
+			n1 <- length(pick1)
+			n2 <- length(pick2)
+
+			C <- V[c(pick1, pick2),c(pick1, pick2)]
+
+			C11 <- C[1:n1,1:n1]
+			C22 <- C[(n1+1):(n1+n2),(n1+1):(n1+n2)]
+			C12 <- C[1:n1,(n1+1):(n1+n2)]
+			if(is.null(dim(C12)))
+      {
+        if(is.null(dim(C22))){C12<-as.matrix(C12)} else {C12<-t(as.matrix(C12))}
+      }
+
+			invC11 <- solve(C11)
+			S22 <- C22 - t(C12)%*%invC11%*%C12
+
+			invC22 <- solve(C22)
+			S11 <- C11 - C12%*%invC22%*%t(C12)
+      if(n1>1)
+      {
+			 SC11 <- (n1*sum(diag(C11))-sum(C11))/(n1*(n1-1))
+       SS11 <- (n1*sum(diag(S11))-sum(S11))/(n1*(n1-1))
+			} else {
+       SC11 <- (n1*sum(diag(C11))-sum(C11))/(n1*(n1))
+       SS11 <- (n1*sum(diag(S11))-sum(S11))/(n1*(n1))
+      }
+      if(n2>1)
+      {
+        SC22 <- (n2*sum(diag(C22))-sum(C22))/(n2*(n2-1))
+        SS22 <- (n2*sum(diag(S22))-sum(S22))/(n2*(n2-1))
+      } else {
+        SC22 <- (n2*sum(diag(C22))-sum(C22))/(n2*(n2))
+        SS22 <- (n2*sum(diag(S22))-sum(S22))/(n2*(n2))
+      }
+
+			D=(n1*SS11 + n2*SS22)/(n1*SC11 + n2*SC22)
+
+			a <- length(unique(c(pick1, pick2)))
+			b <- length(pick1)-a
+			cc <- length(pick2)-a
+			dsor <- 2*a/(2*a+b+cc) - 1
+
+			pred.D <- (n1*SSii[n2]+n2*SSii[n1])/(n1*SCii+n2*SCii)
+			pred.dsor <- 1 - 2*n1*n2/((n1+n2)*n)
+
+			PCD[i,j] <- D/pred.D
+			PCDc[i,j] <- dsor/pred.dsor
+			PCDp[i,j] <- PCD[i,j]/PCDc[i,j]
+		}
+	}
+	colnames(PCD)<-rownames(comm)
+  rownames(PCD)<-rownames(comm)
+  colnames(PCDc)<-rownames(comm)
+  rownames(PCDc)<-rownames(comm)
+  colnames(PCDp)<-rownames(comm)
+  rownames(PCDp)<-rownames(comm)
+
+  return(list(PCD=as.dist(t(PCD)), PCDc=as.dist(t(PCDc)), PCDp=as.dist(t(PCDp)),  PSVmncd=SSii, PSVpool=SCii))
+}

Modified: pkg/R/phylodiversity.R
===================================================================
--- pkg/R/phylodiversity.R	2010-07-18 21:06:09 UTC (rev 232)
+++ pkg/R/phylodiversity.R	2011-04-22 23:44:26 UTC (rev 233)
@@ -368,7 +368,7 @@
     if(is.null(tree$edge.length)){tree<-compute.brlen(tree, 1)}  #If phylo has no given branch lengths
     tree<-prune.sample(samp,tree) 
     # Make sure that the species line up
-    samp<-samp[,tree$tip.label]
+    samp<-samp[,tree$tip.label, drop=FALSE]
     # Make a correlation matrix of the species pool phylogeny
     Cmatrix<-vcv.phylo(tree,cor=TRUE)
   } else {
@@ -377,7 +377,7 @@
     preval<-colSums(samp)/sum(samp)
     species<-species[preval>0]
     Cmatrix<-Cmatrix[species,species]
-    samp<-samp[,colnames(Cmatrix)]
+    samp<-samp[,colnames(Cmatrix),drop=FALSE]
   }
   
   # numbers of locations and species

Modified: pkg/inst/doc/picante-intro.pdf
===================================================================
(Binary files differ)

Added: pkg/man/pcd.Rd
===================================================================
--- pkg/man/pcd.Rd	                        (rev 0)
+++ pkg/man/pcd.Rd	2011-04-22 23:44:26 UTC (rev 233)
@@ -0,0 +1,49 @@
+\name{pcd}
+\alias{pcd}
+\alias{PCD}
+
+\title{Phylogenetic Community Dissimilarity}
+\description{Pairwise dissimilarity in phylogenetic community composition that is partitioned into a nonphylogenetic and a phylogenetic component.}
+\usage{
+    pcd(comm, tree, PSVmncd=NULL, PSVpool=NULL, reps=10^4)
+}
+
+\arguments{
+  \item{comm}{ Community data matrix }
+  \item{tree}{ Object of class phylo or a phylogenetic covariance matrix }
+  \item{PSVmncd}{ Vector of null mean conditional \emph{phylogenetic species variability (\link[=psv]{PSV})} values }
+  \item{PSVpool}{ The standard, unconditional \emph{PSV} calculated for the species pool }
+  \item{reps}{ The number of random draws from the species pool used to produce \code{PSVmncd} }
+}
+
+\details{
+ \emph{Phylogenetic community dissimilarity (PCD)} is the pairwise differences between communities derived by asking how much of the variance 
+ among species in the values of a hypothetical nonselected trait in one community can be predicted by the known trait values of species in another community. 
+ \emph{PCD} is partitioned into a nonphylogenetic component that reflects shared species between communities (\emph{PCDc}) 
+ and a phylogenetic component that reflects the evolutionary relationships among nonshared species (\emph{PCDp}). In order to compare communities that vary 
+ in species richness, the metric is standardized under the assumption that the species in communities are selected at random from the species pool. The   
+ analyses here define the species pool as the list of all species in the set of communities in \code{comm}, but the species pool can be defined under 
+ any hypothesis of community assembly either by manipulating the code or inputting a user defined \code{PSVmncd} and \code{PSVpool}.
+}
+
+\value{
+The function returns a list with items:
+
+\item{PCD}{ A square matrix of \emph{PCD} values }
+\item{PCDc}{ A square matrix of \emph{PCDc} values }
+\item{PCDp}{ A square matrix of \emph{PCDp} values }
+\item{PSVmncd}{ A vector of null mean conditional \emph{PSV} values used to calculate \emph{PCD} }
+\item{PSVpool}{ The unconditional PSV of the species pool used to calculate \emph{PCD} }
+}
+
+\references{Ives A.R. & Helmus M.R. (2010). Phylogenetic metrics of community similarity. The American Naturalist, 176, E128-E142.}
+\author{ Anthony Ives <arives at wisc.edu> and Matthew Helmus <mrhelmus at gmail.com> }
+\seealso{\code{\link{psv}}, \code{\link{phylosor}}, \code{\link{unifrac}}}
+\note{
+The sampling procedure used to standardize \emph{PCD} and produce \code{PSVmncd} and \code{PSVpool} can be slow.
+}
+\examples{
+data(phylocom)
+pcd(phylocom$sample, phylocom$phylo)
+}
+\keyword{univar}

Modified: pkg/man/picante-package.Rd
===================================================================
--- pkg/man/picante-package.Rd	2010-07-18 21:06:09 UTC (rev 232)
+++ pkg/man/picante-package.Rd	2011-04-22 23:44:26 UTC (rev 233)
@@ -12,8 +12,8 @@
 \tabular{ll}{
 Package: \tab picante\cr
 Type: \tab Package\cr
-Version: \tab 1.2-0\cr
-Date: \tab 2010-7-18\cr
+Version: \tab 1.3-0\cr
+Date: \tab 2011-4-22\cr
 License: \tab GPL-2\cr
 }
 }

Modified: www/index.php
===================================================================
--- www/index.php	2010-07-18 21:06:09 UTC (rev 232)
+++ www/index.php	2011-04-22 23:44:26 UTC (rev 233)
@@ -36,15 +36,14 @@
 <p><strong>Developers:</strong> Peter Cowan, Matthew Helmus, Steven Kembel</p>
 <p><strong>Contributors:</strong> David Ackerly, Simon Blomberg, Will Cornwell, Peter Cowan, Matthew Helmus, Steven Kembel, Helene Morlon, Cam Webb<p>    
 <p>Development of picante has been supported by <a href="http://nserc.ca">NSERC</a>, <a href="http://www.nescent.org/index.php">NESCent</a>, the <a href="http://code.google.com/soc/2008/">Google Summer of Code</a>, and the <a href="http://www.moore.org/">Gordon and Betty Moore Foundation</a>.</p>
-<p>Thanks to Kyle Dexter, Catherine Graham, Nathaniel Hallinan, Nick Matzke, Alain Paquette, Juan Parra, Dan Rabosky, and Marten Winter for feedback and bug reports. Thanks to <a href="http://r-forge.r-project.org">R-Forge</a> for hosting the project.</p>
+<p>Thanks to Kyle Dexter, Catherine Graham, Nathaniel Hallinan, Nick Matzke, Alain Paquette, Emmanuel Paradis, Juan Parra, Dan Rabosky, and Marten Winter for feedback and bug reports. Thanks to <a href="http://r-forge.r-project.org">R-Forge</a> for hosting the project.</p>
 
 <h2>News</h2>
 <ul>
 <li>A manuscript describing Picante has been published in Bioinformatics.</li>
-<li>Picante 1.2 has been released
+<li>Picante 1.3 has been released
 <ul>
-<li>Contains a package vignette with information about data formats and examples of analyses</li>
-<li>Data from Ives & Godfray (2006) now included in the package, type <code><strong>help(IvesGodfray)</code></strong> in R for more information.</li>
+<li>The phylogenetic community dissimilarity (PCD) of Ives and Helmus (2010) is now included in function pcd</li>
 </ul>
 </li>
 <li>Lots of changes and new features in version 1.0
@@ -69,7 +68,7 @@
     <li>Phylogenetic species richness, evenness and variance of Helmus et al. (2007).</li>
     <li>Phylogenetic community-environment regressions of Helmus et al. (2007).</li>
     <li>Taxonomic and evolutionary distinctiveness of taxa for conservation biology.</li>
-    <li>Numerous phylogenetic beta diversity measures (phylosor, UniFrac, betaMPD, betaMNTD, Rao's quadratic entropy).</li>
+    <li>Numerous phylogenetic beta diversity measures (PCD, phylosor, UniFrac, betaMPD, betaMNTD, Rao's quadratic entropy).</li>
     </ul>
 <li>Phylogenetic signal (Blomberg <em>et al.</em>'s K statistic and P-value based on randomization test)</li>
 <li>Independent contrasts for traits with circular distributions</li>
@@ -91,7 +90,7 @@
 
 <h2>Obtaining picante</h2>
 <ul>
-<li>Version 1.2-0 is available on <a href="http://cran.r-project.org/">CRAN</a>. Simply type <strong><code>install.packages("picante")</code></strong> from within R.</li>
+<li>Version 1.3-0 is available on <a href="http://cran.r-project.org/">CRAN</a>. Simply type <strong><code>install.packages("picante")</code></strong> from within R.</li>
 <li>You can grab the latest nightly build <a href="http://r-forge.r-project.org/R/?group_id=134">here</a>, or by typing <strong><code>install.packages("picante",repos="http://R-Forge.R-project.org")</code></strong> from within R.</li>
 </ul>
 
@@ -108,6 +107,7 @@
 
 <h2>Release history</h2>
 <p><ul>
+<li>Version 1.3: Add function pcd. Fix single-community error in pse.</li>
 <li>Version 1.2: Bugfix release. Fix to evol.distinct function. Kcalc now behaves better with non-ultrametric trees.</li>
 <li>Version 1.1-1: Minor update to address deprecation of evolve.phylo function in ape package; deleted evolve.brownian function and changed example code.</li>
 <li>Version 1.1: Added package vignette, new example data set from Ives & Godfray (2006), function example code. Reinstated "richness" and "frequency" null models for ses.* functions.</li>



More information about the Picante-commits mailing list