[Picante-commits] r168 - in branches/phylosor: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Nov 6 19:29:44 CET 2008
Author: hmorlon
Date: 2008-11-06 19:29:44 +0100 (Thu, 06 Nov 2008)
New Revision: 168
Added:
branches/phylosor/R/phylosor.R
branches/phylosor/man/phylosor.Rd
Log:
Adding phylosor beta diversity metric code and documentation
Added: branches/phylosor/R/phylosor.R
===================================================================
--- branches/phylosor/R/phylosor.R (rev 0)
+++ branches/phylosor/R/phylosor.R 2008-11-06 18:29:44 UTC (rev 168)
@@ -0,0 +1,52 @@
+phylosor=function(samp,tree)
+{
+ s=nrow(samp)
+ sample_names=rownames(samp)
+ pairs=s*(s-1)/2
+
+ plot1.list=c()
+ plot2.list=c()
+ sor.list=c()
+ phylosor.list=c()
+
+
+ count=0
+ for (l in 1:(s-1))
+ {
+ spl=sum(samp[l,])
+ pdl=.pdshort(samp[l,],tree)
+ for (k in (l+1):s)
+ {
+ count=count+1
+ spk=sum(samp[k,])
+ pdk=.pdshort(samp[k,],tree)
+ sharedlk=sum(samp[l,]*samp[k,])
+ pdsharedlk=.pdshort(samp[l,],tree)+.pdshort(samp[k,],tree)-.pdshort((samp[l,]+samp[k,]),tree)
+ avglk=0.5*(spl+spk)
+ pdavglk=0.5*(pdl+pdk)
+ sorlk=sharedlk/avglk
+ phylosorlk=pdsharedlk/pdavglk
+ plot1.list=c(plot1.list,sample_names[l])
+ plot2.list=c(plot2.list,sample_names[k])
+ sor.list=c(sor.list,sorlk)
+ phylosor.list=c(phylosor.list,phylosorlk)
+ }
+ }
+ data.frame(plot1=plot1.list,plot2=plot2.list,sor=sor.list,phylosor=phylosor.list)}
+
+
+
+.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: branches/phylosor/man/phylosor.Rd
===================================================================
--- branches/phylosor/man/phylosor.Rd (rev 0)
+++ branches/phylosor/man/phylosor.Rd 2008-11-06 18:29:44 UTC (rev 168)
@@ -0,0 +1,25 @@
+\name{phylosor}
+\alias{phylosor}
+
+\title{Compute phylogenetic index of beta-diversity Phylosor}
+\description{Compute phylogenetic index of similarity Phylosor
+
+}
+\usage{
+phylosor(samp, tree)
+}
+
+\arguments{
+ \item{samp}{ Community data matrix }
+ \item{tree}{ Phylo object}
+}
+\value{
+ dataframe with four colums: plot number 1; plot number 2; sorensen index; phylosor index
+}
+\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> }
+\examples{
+data(phylocom)
+phylosor(phylocom$sample, phylocom$phylo)}
+\keyword{univar}
More information about the Picante-commits
mailing list