[Picante-commits] r174 - in pkg: . R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Jan 28 01:52:48 CET 2009
Author: skembel
Date: 2009-01-28 01:52:47 +0100 (Wed, 28 Jan 2009)
New Revision: 174
Added:
pkg/R/phylosor.R
pkg/man/phylosor.Rd
pkg/man/phylosor.rnd.Rd
Modified:
pkg/DESCRIPTION
pkg/man/picante-package.Rd
pkg/man/ses.mnnd.Rd
Log:
Fix typos in ses.mnnd docs and update phylosor code to include correct version from Helene (incorporate randomizations etc)
Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION 2009-01-27 00:24:28 UTC (rev 173)
+++ pkg/DESCRIPTION 2009-01-28 00:52:47 UTC (rev 174)
@@ -1,8 +1,8 @@
Package: picante
Type: Package
Title: R tools for integrating phylogenies and ecology
-Version: 0.5-2
-Date: 2009-1-26
+Version: 0.5-3
+Date: 2009-1-27
Author: Steven Kembel <skembel at uoregon.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>, Helene Morlon <morlon.helene at gmail.com>, Campbell Webb <cwebb at oeb.harvard.edu>
Maintainer: Steven Kembel <skembel at uoregon.edu>
Depends: ape, vegan, nlme
Added: pkg/R/phylosor.R
===================================================================
--- pkg/R/phylosor.R (rev 0)
+++ pkg/R/phylosor.R 2009-01-28 00:52:47 UTC (rev 174)
@@ -0,0 +1,114 @@
+phylosor=function(samp,tree)
+{
+ s=nrow(samp)
+ phylodist=matrix(NA,s,s)
+ rownames(phylodist)=rownames(samp)
+ colnames(phylodist)=rownames(samp)
+
+ for (l in 1:(s-1))
+ {
+ pdl=.pdshort(samp[l,],tree)
+ for (k in (l+1):s)
+ {
+ pdk=.pdshort(samp[k,],tree)
+ pdtot=.pdshort((samp[l,]+samp[k,]),tree)
+ pdsharedlk=pdl+pdk-pdtot
+ phylodist[k,l]=2*pdsharedlk/(pdl+pdk)
+ }
+ }
+ return(as.dist(phylodist))
+}
+phylosor.rnd=function(samp,tree,cstSor=TRUE,null.model=c("taxa.labels","frequency","richness","independentswap","trialswap"),runs=999,iterations=1000)
+
+{
+
+ Res=list()
+
+ if (cstSor==TRUE)
+ {
+ if (null.model=="taxa.labels")
+ {
+ for (r in 1:runs)
+ {
+ Res<-c(Res,list(.phylosor.taxaShuffle(samp,tree)))}
+ }
+
+ else if (null.model=="richness")
+ {
+ for (r in 1:runs)
+ {Res<-c(Res,list(.phylosor.richness(samp,tree)))}
+ }
+
+ else stop("This null model does not maintain Sorensen similarity: use cstSor=FALSE, or choose an other null model")
+ }
+
+ else
+ {
+ if (null.model=="taxa.labels")
+ {
+ warning("This null model maintains Sorensen similarity")
+ for (r in 1:runs)
+ {
+ Res<-c(Res,list(.phylosor.taxaShuffle(samp,tree)))
+ }
+ }
+
+ else
+ for (r in 1:runs)
+ {
+ Res<-c(Res,list(phylosor(randomizeSample(samp, null.model),tree)))
+ }
+ }
+
+return(Res)
+}
+
+
+##########################################################################################
+.phylosor.taxaShuffle=function(samp,tree)
+ {
+ sampr=samp
+ colnames(sampr)=sample(colnames(samp))
+ return(phylosor(sampr,tree))
+ }
+
+##########################################################################################
+.phylosor.richness=function(samp,tree)
+{
+ s=nrow(samp)
+ phylodist=matrix(NA,s,s)
+ rownames(phylodist)=rownames(samp)
+ colnames(phylodist)=rownames(samp)
+
+ for (l in 1:(s-1))
+ {
+ for (k in (l+1):s)
+ {
+ sampr=samp
+ colnames(sampr)=sample(colnames(samp))
+ pdl=.pdshort(sampr[l,],tree)
+ pdk=.pdshort(sampr[k,],tree)
+ pdtot=.pdshort((sampr[l,]+sampr[k,]),tree)
+ pdsharedlk=pdl+pdk-pdtot
+ phylodist[k,l]=2*pdsharedlk/(pdl+pdk)
+ }
+ }
+ return(as.dist(phylodist))
+}
+
+#############################################################################################
+
+.pdshort=function(comm,tree)
+{
+
+ nbspecies=length(comm)
+ species = names(comm)
+ index = species[comm == 0]
+ if (length(index) >= (nbspecies - 1))
+ {PD <- NA}
+ else {
+ sub.tree <- drop.tip(tree, index)
+ PD <- sum(sub.tree$edge.length)}
+ return(PD)}
+
+
Added: pkg/man/phylosor.Rd
===================================================================
--- pkg/man/phylosor.Rd (rev 0)
+++ pkg/man/phylosor.Rd 2009-01-28 00:52:47 UTC (rev 174)
@@ -0,0 +1,21 @@
+\name{phylosor}
+\alias{phylosor}
+
+\title{Phylogenetic index of beta-diversity PhyloSor}
+\description{Fraction of branch-length shared between two communities}
+\usage{
+phylosor(samp, tree)
+}
+
+\arguments{
+ \item{samp}{ Community data matrix }
+ \item{tree}{ Object of class phylo}
+}
+\value{Distance matrix reporting the PhyloSor index of similarity between communities: fraction of branch-length shared}
+\references{Bryant, J.B., Lamanna, C., Morlon, H., Kerkhoff, A.J., Enquist, B.J., Green, J.L. 2008. Microbes on mountainsides: Contrasting elevational patterns of bacterial and plant diversity. Proceedings of the National Academy of Sciences 105 Supplement 1: 1505-11511}
+\author{ Helene Morlon <morlon.helene at gmail.com> and Steven Kembel <skembel at uoregon.edu> }
+\seealso{ \code{\link{phylosor.rnd}}}
+\examples{
+data(phylocom)
+phylosor(phylocom$sample, phylocom$phylo)}
+\keyword{univar}
Added: pkg/man/phylosor.rnd.Rd
===================================================================
--- pkg/man/phylosor.rnd.Rd (rev 0)
+++ pkg/man/phylosor.rnd.Rd 2009-01-28 00:52:47 UTC (rev 174)
@@ -0,0 +1,44 @@
+\name{phylosor.rnd}
+\alias{phylosor.rnd}
+
+\title{ Null PhyloSor values of phylogenetic beta-diversity }
+\description{
+ PhyloSor values obtained by randomization for different choices of null models
+}
+\usage{
+phylosor.rnd(samp,tree, cstSor=TRUE, null.model=c("taxa.labels",
+ "frequency","richness","independentswap","trialswap"),
+ runs=999, iterations=1000)
+}
+
+\arguments{
+ \item{ samp }{ Community data matrix }
+ \item{ tree }{ Object of class phylo}
+ \item{ cstSor }{ TRUE if the Sorensen similarity should be kept constant across communities. FALSE otherwise }
+ \item{ null.model }{ Null model to use (see Details section) }
+ \item{ runs }{ Number of randomizations }
+ \item{ iterations }{ Number of iterations to use for each randomization (for independent swap and trial null models) }
+}
+
+\value{
+ A list of length the number of runs. Each element of the list is a distance matrix containing the PhyloSor values of phylogenetic beta-diversity obtained by randomization
+}
+\details{
+Currently implemented null models (arguments to null.model):
+\describe{
+ \item{taxa.labels}{ Shuffle community data matrix labels. Maintains species richness in each community and species shared between communities. Should be used with cstSor=TRUE}
+ \item{frequency}{ Randomize community data matrix abundances within species (maintains species occurence frequency). Does not maintain species richness in communities nor species shared between communities. Can only be used with cstSor=FALSE}
+ \item{richness}{ With cstSor=TRUE: For each pair of community, maintains species richness in each community and species shared between communities. Sample in the species pool with equal probability;
+ With cstSor=FALSE: Maintains species richness in each community, does not maintain species shared between communities. Sample in the species pool with equal probability}
+ \item{independentswap}{ Randomize community data matrix with the independent swap algorithm (Gotelli 2000) maintaining species occurrence frequency and sample species richness. Can only be used with cstSor=FALSE}
+ \item{trialswap}{ Randomize community data matrix with the trial-swap algorithm (Miklos & Podani 2004) maintaining species occurrence frequency and sample species richness. Can only be used with cstSor=FALSE}
+ }
+}
+\references{Bryant, J.B., Lamanna, C., Morlon, H., Kerkhoff, A.J., Enquist, B.J., Green, J.L. 2008. Microbes on mountainsides: Contrasting elevational patterns of bacterial and plant diversity. Proceedings of the National Academy of Sciences 105 Supplement 1: 1505-11511}
+\author{ Helene Morlon <morlon.helene at gmail.com> and Steven Kembel <skembel at uoregon.edu> }
+\seealso{ \code{\link{phylosor}}, \code{\link{randomizeSample}} }
+\examples{
+data(phylocom)
+phylosor.rnd(phylocom$sample,phylocom$phylo,cstSor=TRUE,null.model="richness",runs=5)
+}
+\keyword{univar}
Modified: pkg/man/picante-package.Rd
===================================================================
--- pkg/man/picante-package.Rd 2009-01-27 00:24:28 UTC (rev 173)
+++ pkg/man/picante-package.Rd 2009-01-28 00:52:47 UTC (rev 174)
@@ -12,8 +12,8 @@
\tabular{ll}{
Package: \tab picante\cr
Type: \tab Package\cr
-Version: \tab 0.5-2\cr
-Date: \tab 2009-1-26\cr
+Version: \tab 0.5-3\cr
+Date: \tab 2009-1-27\cr
License: \tab GPL-2\cr
}
}
Modified: pkg/man/ses.mnnd.Rd
===================================================================
--- pkg/man/ses.mnnd.Rd 2009-01-27 00:24:28 UTC (rev 173)
+++ pkg/man/ses.mnnd.Rd 2009-01-28 00:52:47 UTC (rev 174)
@@ -21,12 +21,12 @@
\value{
A data frame of results for each community
\item{ntaxa}{Number of taxa in community}
- \item{mpd.obs}{Observed MNND in community}
- \item{mpd.rand.mean}{Mean MNND in null communities}
- \item{mpd.rand.sd}{Standard deviation of MNND in null communities}
- \item{mpd.obs.rank}{Rank of observed MNND vs. null communities}
- \item{mpd.obs.z}{Standardized effect size of MNND vs. null communities (= (mpd.obs - mpd.rand.mean) / mpd.rand.sd, equivalent to -NTI)}
- \item{mpd.obs.p}{P-value (quantile) of observed MNND vs. null communities (= mpd.obs.rank / runs + 1)}
+ \item{mnnd.obs}{Observed MNND in community}
+ \item{mnnd.rand.mean}{Mean MNND in null communities}
+ \item{mnnd.rand.sd}{Standard deviation of MNND in null communities}
+ \item{mnnd.obs.rank}{Rank of observed MNND vs. null communities}
+ \item{mnnd.obs.z}{Standardized effect size of MNND vs. null communities (= (mnnd.obs - mnnd.rand.mean) / mnnd.rand.sd, equivalent to -NTI)}
+ \item{mnnd.obs.p}{P-value (quantile) of observed MNND vs. null communities (= mnnd.obs.rank / runs + 1)}
\item{runs}{Number of randomizations}
}
\details{
More information about the Picante-commits
mailing list