[Picante-commits] r97 - in branches/gsoc: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Jun 11 09:25:05 CEST 2008
Author: mrhelmus
Date: 2008-06-11 09:25:05 +0200 (Wed, 11 Jun 2008)
New Revision: 97
Added:
branches/gsoc/R/specaccum.psr.R
branches/gsoc/man/psd.Rd
branches/gsoc/man/specaccum.psr.Rd
Removed:
branches/gsoc/R/specaccum.PSR.R
branches/gsoc/man/PSDcalc.Rd
branches/gsoc/man/specaccum.PSR.Rd
Modified:
branches/gsoc/R/phylodiversity.R
branches/gsoc/man/pd.Rd
Log:
Cleaned up the Documentation and changed all PSD code to lower case (e.g., from PSVcalc to psv)
Modified: branches/gsoc/R/phylodiversity.R
===================================================================
--- branches/gsoc/R/phylodiversity.R 2008-06-11 03:57:39 UTC (rev 96)
+++ branches/gsoc/R/phylodiversity.R 2008-06-11 07:25:05 UTC (rev 97)
@@ -118,7 +118,7 @@
}
-PSVcalc<-function(samp,tree,compute.var=TRUE){
+psv<-function(samp,tree,compute.var=TRUE){
# Make samp matrix a pa matrix
samp[samp>0]<-1
@@ -226,8 +226,8 @@
}
-PSRcalc <- function(samp,tree,compute.var=TRUE){
- PSVout<-PSVcalc(samp,tree,compute.var)
+psr <- function(samp,tree,compute.var=TRUE){
+ PSVout<-psv(samp,tree,compute.var)
if(is.null(dim(PSVout))==TRUE)
{
PSRout<-data.frame(cbind(PSVout[1]*PSVout[2],PSVout[2]))
@@ -247,7 +247,7 @@
}
}
-PSEcalc<-function(samp,tree){
+pse<-function(samp,tree){
flag=0
if (is.null(dim(samp))) #if the samp matrix only has one site
{
@@ -310,7 +310,7 @@
}
}
-PSCcalc<-function(samp,tree){
+psc<-function(samp,tree){
# Make samp matrix a pa matrix
samp[samp>0]<-1
flag=0
@@ -375,7 +375,7 @@
}
}
-spp.PSVcalc<-function(samp,tree){
+psv.spp<-function(samp,tree){
# Make samp matrix a pa matrix
samp[samp>0]<-1
if (is.null(dim(samp))) #if the samp matrix only has one site
@@ -406,7 +406,7 @@
Cmatrix<-Cmatrix[indexcov,indexcov]
samp<-samp[,indexcov]
- obs.PSV<-mean(PSVcalc(samp,Cmatrix,compute.var=FALSE)[,1])
+ obs.PSV<-mean(psv(samp,Cmatrix,compute.var=FALSE)[,1])
# numbers of locations and species
nlocations<-dim(samp)[1]
@@ -417,7 +417,7 @@
{
spp.samp<-samp[,-j]
spp.Cmatrix<-Cmatrix[-j,-j]
- spp.PSV<-mean(PSVcalc(spp.samp,spp.Cmatrix,compute.var=FALSE)[,1])
+ spp.PSV<-mean(psv(spp.samp,spp.Cmatrix,compute.var=FALSE)[,1])
spp.PSVs<-c(spp.PSVs,spp.PSV)
}
spp.PSVout<-(spp.PSVs-obs.PSV)/sum(abs(spp.PSVs-obs.PSV))
@@ -425,19 +425,19 @@
return(spp.PSVout)
}
-PSDcalc<-function(samp,tree,compute.var=TRUE){
+psd<-function(samp,tree,compute.var=TRUE){
if (is.null(dim(samp))) #if the samp matrix only has one site
{
- PSDout<-data.frame(c(PSVcalc(samp,tree,compute.var)[1],PSCcalc(samp,tree)[1],PSRcalc(samp,tree,compute.var)[1],PSEcalc(samp,tree)))
+ PSDout<-data.frame(c(psv(samp,tree,compute.var)[1],psc(samp,tree)[1],psr(samp,tree,compute.var)[1],pse(samp,tree)))
names(PSDout)<-c("PSV","PSC","PSR","PSE","SR")
return(PSDout)
} else {
if (compute.var==TRUE)
{
- PSDout<-cbind(PSVcalc(samp,tree,compute.var)[,c(1,3)],PSCcalc(samp,tree)[,1],PSRcalc(samp,tree,compute.var)[,c(1,3)],PSEcalc(samp,tree))
+ PSDout<-cbind(psv(samp,tree,compute.var)[,c(1,3)],psc(samp,tree)[,1],psr(samp,tree,compute.var)[,c(1,3)],pse(samp,tree))
colnames(PSDout)<-c("PSV","var.PSV","PSC","PSR","var.PSR","PSE","SR")
} else {
- PSDout<-cbind(PSVcalc(samp,tree,compute.var)[,1],PSCcalc(samp,tree)[,1],PSRcalc(samp,tree,compute.var)[,1],PSEcalc(samp,tree))
+ PSDout<-cbind(psv(samp,tree,compute.var)[,1],psc(samp,tree)[,1],psr(samp,tree,compute.var)[,1],pse(samp,tree))
colnames(PSDout)<-c("PSV","PSC","PSR","PSE","SR")
}
return(data.frame(PSDout))
Deleted: branches/gsoc/R/specaccum.PSR.R
===================================================================
--- branches/gsoc/R/specaccum.PSR.R 2008-06-11 03:57:39 UTC (rev 96)
+++ branches/gsoc/R/specaccum.PSR.R 2008-06-11 07:25:05 UTC (rev 97)
@@ -1,43 +0,0 @@
-specaccum.PSR<-function (samp, tree, permutations = 100, method = "random", ...)
-{
-
-#function adapted from the vegan package specaccum
-
- x <- as.matrix(samp)
- n <- nrow(x)
- p <- ncol(x)
- if (p == 1)
- {
- x <- t(x)
- n <- nrow(x)
- p <- ncol(x)
- }
- accumulator <- function(x,ind,tree)
- {
- n <- nrow(x)
- p <- ncol(x)
- xx<-x
- xx[1:n,1:p]<-0
- xx[apply(x[ind, ], 2, cumsum)>0]<-1
- PSV<-PSVcalc(xx,tree,compute.var=FALSE)
- PSV[,1]*PSV[,2]
- }
- METHODS <- c("collector", "random", "exact", "rarefaction",
- "coleman")
- method <- match.arg(method, METHODS)
-
- specaccum <- sdaccum <- sites <- perm <- NULL
- perm <- array(dim = c(n, permutations))
- for (i in 1:permutations)
- {
- r.x=0
- while(length(r.x)<n){r.x <- accumulator(x, sample(n),tree)}
- perm[, i]<-r.x
- }
- sites <- 1:n
- specaccum <- apply(perm, 1, mean)
- sdaccum <- apply(perm, 1, sd)
- out <- list(call = match.call(), method = method, sites = sites, richness = specaccum, sd = sdaccum, perm = perm)
- class(out) <- "specaccum"
- out
-}
\ No newline at end of file
Added: branches/gsoc/R/specaccum.psr.R
===================================================================
--- branches/gsoc/R/specaccum.psr.R (rev 0)
+++ branches/gsoc/R/specaccum.psr.R 2008-06-11 07:25:05 UTC (rev 97)
@@ -0,0 +1,43 @@
+specaccum.psr<-function (samp, tree, permutations = 100, method = "random", ...)
+{
+
+#function adapted from the vegan package specaccum
+
+ x <- as.matrix(samp)
+ n <- nrow(x)
+ p <- ncol(x)
+ if (p == 1)
+ {
+ x <- t(x)
+ n <- nrow(x)
+ p <- ncol(x)
+ }
+ accumulator <- function(x,ind,tree)
+ {
+ n <- nrow(x)
+ p <- ncol(x)
+ xx<-x
+ xx[1:n,1:p]<-0
+ xx[apply(x[ind, ], 2, cumsum)>0]<-1
+ PSV<-psv(xx,tree,compute.var=FALSE)
+ PSV[,1]*PSV[,2]
+ }
+ METHODS <- c("collector", "random", "exact", "rarefaction",
+ "coleman")
+ method <- match.arg(method, METHODS)
+
+ specaccum <- sdaccum <- sites <- perm <- NULL
+ perm <- array(dim = c(n, permutations))
+ for (i in 1:permutations)
+ {
+ r.x=0
+ while(length(r.x)<n){r.x <- accumulator(x, sample(n),tree)}
+ perm[, i]<-r.x
+ }
+ sites <- 1:n
+ specaccum <- apply(perm, 1, mean)
+ sdaccum <- apply(perm, 1, sd)
+ out <- list(call = match.call(), method = method, sites = sites, richness = specaccum, sd = sdaccum, perm = perm)
+ class(out) <- "specaccum"
+ out
+}
\ No newline at end of file
Deleted: branches/gsoc/man/PSDcalc.Rd
===================================================================
--- branches/gsoc/man/PSDcalc.Rd 2008-06-11 03:57:39 UTC (rev 96)
+++ branches/gsoc/man/PSDcalc.Rd 2008-06-11 07:25:05 UTC (rev 97)
@@ -1,80 +0,0 @@
-\name{PSDcalc}
-\alias{PSDcalc}
-\alias{PSVcalc}
-\alias{PSRcalc}
-\alias{PSEcalc}
-\alias{PSCcalc}
-\alias{spp.PSVcalc}
-\alias{PSV}
-\alias{PSR}
-\alias{PSE}
-\alias{PSD}
-\alias{PSC}
-\alias{spp.psvcalc}
-\alias{psv}
-\alias{psr}
-\alias{pse}
-\alias{psd}
-\alias{psc}
-\alias{spp.PSV}
-\title{ Phylogenetic Species Diversity Metrics }
-\description{
- Calculate the bounded phylogenetic biodiversity metrics: phylogenetic species variability, richness, evenness and clustering for one or multiple samples.
-}
-\usage{
-PSVcalc(samp,tree,compute.var=TRUE)
-PSRcalc(samp,tree,compute.var=TRUE)
-PSEcalc(samp,tree)
-PSCcalc(samp,tree,compute.var=TRUE)
-PSDcalc(samp,tree,compute.var=TRUE)
-spp.PSVcalc(samp,tree)
-}
-
-\arguments{
- \item{samp}{ Community data matrix }
- \item{tree}{ A phylo tree object or a phylogenetic covariance matrix }
- \item{compute.var}{ Computes the expected variances for PSV and PSR for each community }
-}
-\details{
- \emph{Phylogenetic species variability (PSV)} quantifies how phylogenetic relatedness decreases the variance of a hypothetical unselected/neutral trait
- shared by all species in a community. The expected value of PSV is statistically independent of species richness, is one when all species in a sample
- are unrelated (i.e., a star phylogeny) and approaches zero as species become more related. PSV is directly related to mean phylogenetic distance. The
- expected variance around PSV for any sample of a particular species richness can be approximated.
- To address how individual species contribute to the mean PSV of a data set, the function spp.PSVcalc gives signed proportions of the total deviation
- from the mean PSV that occurs when all species are removed from the data set one at a time. The absolute values of these \dQuote{species effects}
- tend to positively correlate with species prevalence.
- \cr
- \cr
- \emph{Phylogenetic species richness (PSR)} is the number of species in a sample multiplied by PSV. It can be considered the species richness of a sample
- after discounting by species relatedness. The value is maximum at the species richness of the sample, and decreases towards zero as relatedness
- increases. The expected variance around PSR for any sample of a particular species richness can be approximated.
- \cr
- \cr
- \emph{Phylogenetic species evenness (PSE)} is the metric PSV modified to incorporate relative species abundances. The maximum attainable value of PSE (i.e., 1)
- occurs only if species abundances are equal and species phylogeny is a star. PSE essentially grafts each individual of a species onto the tip of the
- phylogeny of its species with branch lengths of zero.
- \cr
- \cr
- \emph{Phylogenetic species clustering (PSC)} is a metric of the branch tip clustering of species across a sample's phylogeny. As PSC increases to 1, species
- are less related to one another the tips of the phylogeny. PSC is directly related to mean nearest neighbor distance.
-}
-
-\value{
- Returns a dataframe of the respective phylogenetic species diversity metric values
-}
-
-\note{These metrics are bounded either between zero and one (PSV, PSE, PSC) or zero and species richness (PSR); but the metrics asymptotically
- approach zero as relatedness increases. Zero can be assigned to communities with less than two species, but conclusions drawn from assigning
- communities zero values need be carefully explored for any data set. The data sets need not be species-community data sets but may be any sample
- data set with an associated phylogeny.
-}
-
-
-\references{ 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} }
-\seealso{ \code{\link{mpd}} ,\code{\link{mnnd}} }
-
-\keyword{univar}
-
-
-
Modified: branches/gsoc/man/pd.Rd
===================================================================
--- branches/gsoc/man/pd.Rd 2008-06-11 03:57:39 UTC (rev 96)
+++ branches/gsoc/man/pd.Rd 2008-06-11 07:25:05 UTC (rev 97)
@@ -24,9 +24,9 @@
\references{ Faith D.P. (1992) Conservation evaluation and phylogenetic diversity. Biological Conservation, 61, 1-10 }
-\author{ Matthew Helmus \email{mrhelmus at gmail.com}
+\author{ Matthew Helmus \email{mrhelmus at gmail.com}\cr
Jonathan Davies \email{davies at nceas.ucsb.edu}
}
-\seealso{ \code{\link{calcPSR}} }
+\seealso{ \code{\link{psr}} }
\keyword{univar}
Added: branches/gsoc/man/psd.Rd
===================================================================
--- branches/gsoc/man/psd.Rd (rev 0)
+++ branches/gsoc/man/psd.Rd 2008-06-11 07:25:05 UTC (rev 97)
@@ -0,0 +1,68 @@
+\name{psd}
+\alias{psd}
+\alias{psv.spp}
+\alias{psv}
+\alias{psr}
+\alias{pse}
+\alias{psc}
+\title{ Phylogenetic Species Diversity Metrics }
+\description{
+ Calculate the bounded phylogenetic biodiversity metrics: phylogenetic species variability, richness, evenness and clustering for one or multiple samples.
+}
+\usage{
+psv(samp,tree,compute.var=TRUE)
+psr(samp,tree,compute.var=TRUE)
+pse(samp,tree)
+psc(samp,tree,compute.var=TRUE)
+psd(samp,tree,compute.var=TRUE)
+psv.spp(samp,tree)
+}
+
+\arguments{
+ \item{samp}{ Community data matrix }
+ \item{tree}{ A phylo tree object or a phylogenetic covariance matrix }
+ \item{compute.var}{ Computes the expected variances for PSV and PSR for each community }
+}
+\details{
+ \emph{Phylogenetic species variability (PSV)} quantifies how phylogenetic relatedness decreases the variance of a hypothetical unselected/neutral trait
+ shared by all species in a community. The expected value of PSV is statistically independent of species richness, is one when all species in a sample
+ are unrelated (i.e., a star phylogeny) and approaches zero as species become more related. PSV is directly related to mean phylogenetic distance. The
+ expected variance around PSV for any sample of a particular species richness can be approximated.
+ To address how individual species contribute to the mean PSV of a data set, the function psv.spp gives signed proportions of the total deviation
+ from the mean PSV that occurs when all species are removed from the data set one at a time. The absolute values of these \dQuote{species effects}
+ tend to positively correlate with species prevalence.
+ \cr
+ \cr
+ \emph{Phylogenetic species richness (PSR)} is the number of species in a sample multiplied by PSV. It can be considered the species richness of a sample
+ after discounting by species relatedness. The value is maximum at the species richness of the sample, and decreases towards zero as relatedness
+ increases. The expected variance around PSR for any sample of a particular species richness can be approximated.
+ \cr
+ \cr
+ \emph{Phylogenetic species evenness (PSE)} is the metric PSV modified to incorporate relative species abundances. The maximum attainable value of PSE (i.e., 1)
+ occurs only if species abundances are equal and species phylogeny is a star. PSE essentially grafts each individual of a species onto the tip of the
+ phylogeny of its species with branch lengths of zero.
+ \cr
+ \cr
+ \emph{Phylogenetic species clustering (PSC)} is a metric of the branch tip clustering of species across a sample's phylogeny. As PSC increases to 1, species
+ are less related to one another the tips of the phylogeny. PSC is directly related to mean nearest neighbor distance.
+}
+
+\value{
+ Returns a dataframe of the respective phylogenetic species diversity metric values
+}
+
+\note{These metrics are bounded either between zero and one (PSV, PSE, PSC) or zero and species richness (PSR); but the metrics asymptotically
+ approach zero as relatedness increases. Zero can be assigned to communities with less than two species, but conclusions drawn from assigning
+ communities zero values need be carefully explored for any data set. The data sets need not be species-community data sets but may be any sample
+ data set with an associated phylogeny.
+}
+
+
+\references{ 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} }
+\seealso{ \code{\link{mpd}} ,\code{\link{mnnd}}, \code{\link{specaccum.psr}} }
+
+\keyword{univar}
+
+
+
Deleted: branches/gsoc/man/specaccum.PSR.Rd
===================================================================
--- branches/gsoc/man/specaccum.PSR.Rd 2008-06-11 03:57:39 UTC (rev 96)
+++ branches/gsoc/man/specaccum.PSR.Rd 2008-06-11 07:25:05 UTC (rev 97)
@@ -1,37 +0,0 @@
-\name{specaccum.PSR}
-\alias{specaccum.PSR}
-
-\title{ Phylogenetic Species Richness Sample-Based Rarefaction Curve }
-\description{
- Finds a sample-based rarefaction curve for phylogentic species richness for a set of samples.
-}
-\usage{
-specaccum.PSR(samp, tree, permutations = 100, method = "random", ...)
-}
-
-\arguments{
- \item{samp}{ Community data matrix }
- \item{tree}{ A phylo tree object or a phylogenetic covariance matrix}
- \item{permutations}{ Number of permutations with method method= "random" }
- \item{method} { Species accumulation method, currently only "random" is supported which add samples in random order. }
- \item{...}{ Other parameters to functions }
-}
-
-\value{
-The function returns an object of class "specaccum" with items:
-
-\item{call}{ Function call. }
-\item{method}{ Accumulator method. }
-\item{sites}{ Number of sites/samples. For method = "rarefaction" this is the average number of sites corresponding to a certain number of individuals.}
-\item{richness}{ The phylogenetic species richness corresponding to number of sites/samples. With method = "collector" this is the observed phylogenetic species richness, for other methods the average or expected phylogenetic species richness. }
-\item{sd}{ The standard deviation of phylogenetic apecies accumulation curve (or its standard error). This is NULL in method = "collector", and it is estimated from permutations in method = "random", and from analytic equations in other methods. }
-\item{perm}{ Permutation results with method = "random" and NULL in other cases. Each column in perm holds one permutation. }
-}
-
-\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
- 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}
- }
-\seealso{ \code{\link{calcPSR}}, \code{\link{specaccum}}}
-
-\keyword{univar}
Added: branches/gsoc/man/specaccum.psr.Rd
===================================================================
--- branches/gsoc/man/specaccum.psr.Rd (rev 0)
+++ branches/gsoc/man/specaccum.psr.Rd 2008-06-11 07:25:05 UTC (rev 97)
@@ -0,0 +1,37 @@
+\name{specaccum.PSR}
+\alias{specaccum.PSR}
+
+\title{ Phylogenetic Species Richness Sample-Based Rarefaction Curve }
+\description{
+ Finds a sample-based rarefaction curve for phylogentic species richness for a set of samples.
+}
+\usage{
+specaccum.PSR(samp, tree, permutations = 100, method = "random", ...)
+}
+
+\arguments{
+ \item{samp}{ Community data matrix }
+ \item{tree}{ A phylo tree object or a phylogenetic covariance matrix}
+ \item{permutations}{ Number of permutations with method \enc{method= "random"}{typewriter} }
+ \item{method}{ Species accumulation method, currently only \enc{"random"}{typewriter} is supported which adds samples in random order. }
+ \item{\dots}{ Other parameters to functions }
+}
+
+\value{
+The function returns an object of class \enc{"specaccum"}{typewriter} with items:
+
+\item{call}{ Function call. }
+\item{method}{ Accumulator method. }
+\item{sites}{ Number of sites/samples. For \enc{method = "rarefaction"}{typewriter} this is the average number of sites corresponding to a certain number of individuals.}
+\item{richness}{ The phylogenetic species richness corresponding to number of sites/samples. With \enc{method = "collector"}{typewriter} this is the observed phylogenetic species richness, for other methods the average or expected phylogenetic species richness. }
+\item{sd}{ The standard deviation of phylogenetic apecies accumulation curve (or its standard error). This is NULL in \enc{method = "collector"}{typewriter}, and it is estimated from permutations in \enc{method = "random"}{typewriter}, and from analytic equations in other methods. }
+\item{perm}{ Permutation results with \enc{method = "random"}{typewriter} and NULL in other cases. Each column in perm holds one permutation. }
+}
+
+\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}
+ }
+\seealso{ \code{\link{psr}}, \code{\link{specaccum}}}
+
+\keyword{univar}
More information about the Picante-commits
mailing list