[Picante-commits] r184 - in pkg: . R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Apr 3 21:45:08 CEST 2009
Author: skembel
Date: 2009-04-03 21:45:07 +0200 (Fri, 03 Apr 2009)
New Revision: 184
Added:
pkg/R/phylobeta.R
pkg/R/pic3.R
pkg/R/traitgram.R
pkg/man/comdist.Rd
pkg/man/comdistnt.Rd
pkg/man/comm.phylo.qr.Rd
pkg/man/mntd.Rd
pkg/man/pic3.Rd
pkg/man/ses.mntd.Rd
pkg/man/traitgram.Rd
Removed:
pkg/man/mnnd.Rd
pkg/man/ses.mnnd.Rd
Modified:
pkg/DESCRIPTION
pkg/R/phylodiversity.R
pkg/man/mpd.Rd
pkg/man/picante-package.Rd
pkg/man/ses.mpd.Rd
Log:
Added several new functions - comdist, comdistnt (community phylogenetic beta diversity), traitgram (plot continuous traits on a tree), renamed *mnnd functions to *mntd, added abundance weighting for community alpha and beta diversity (mpd/mntd).
Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION 2009-04-01 21:55:40 UTC (rev 183)
+++ pkg/DESCRIPTION 2009-04-03 19:45:07 UTC (rev 184)
@@ -1,11 +1,11 @@
Package: picante
Type: Package
Title: R tools for integrating phylogenies and ecology
-Version: 0.6-1
-Date: 2009-3-18
+Version: 0.7-0
+Date: 2009-4-3
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
-Suggests: brglm, circular
+Suggests: brglm, circular, quantreg
Description: Phylocom integration, community analyses, null-models, traits and evolution in R
License: GPL-2
Added: pkg/R/phylobeta.R
===================================================================
--- pkg/R/phylobeta.R (rev 0)
+++ pkg/R/phylobeta.R 2009-04-03 19:45:07 UTC (rev 184)
@@ -0,0 +1,71 @@
+#phylobeta diversity functions
+
+#comdist
+#mean pairwise distance among taxa from two communities
+comdist <- function(comm,dis,abundance.weighted=FALSE,exclude.conspecifics=FALSE) {
+ N <- dim(comm)[1]
+ #relativize abundances for inter-sample comparisons
+ comm <- decostand(comm,method="total",MARGIN=1)
+ comdis <- matrix(nrow=N,ncol=N)
+ for (i in 1:(N-1)) {
+ for (j in (i+1):N) {
+ sppInSample1 <- names(comm[i, comm[i, ] > 0])
+ sppInSample2 <- names(comm[j, comm[j, ] > 0])
+ if ((length(sppInSample1) > 1) && (length(sppInSample2) > 1)) {
+ sample.dis <- dis[sppInSample1, sppInSample2]
+ if (exclude.conspecifics) {
+ sample.dis[sample.dis == 0] <- NA
+ }
+ if (abundance.weighted) {
+ sample.weights <- comm[i,sppInSample1] %*% t(comm[j,sppInSample2])
+ comdis[i,j] <- weighted.mean(sample.dis,sample.weights,na.rm=TRUE)
+ }
+ else {
+ comdis[i,j] <- mean(sample.dis,na.rm=TRUE)
+ }
+ }
+ else{
+ comdis[i,j] <- NA
+ }
+ }
+ }
+ rownames(comdis) <- colnames(comdis) <- rownames(comm)
+ as.dist(t(comdis))
+}
+
+#comdistnn
+#mean distance to closest relative between taxa from two communities
+comdistnt <- function(comm,dis,abundance.weighted=FALSE,exclude.conspecifics=FALSE) {
+ N <- dim(comm)[1]
+ comm <- decostand(comm,method="total",MARGIN=1)
+ comdisnt <- matrix(nrow=N,ncol=N)
+ for (i in 1:(N-1)) {
+ for (j in (i+1):N) {
+ sppInSample1 <- names(comm[i, comm[i, ] > 0])
+ sppInSample2 <- names(comm[j, comm[j, ] > 0])
+ if ((length(sppInSample1) >= 1) && (length(sppInSample2) >= 1)) {
+ sample.dis <- dis[sppInSample1, sppInSample2]
+ if (exclude.conspecifics) {
+ sample.dis[sample.dis == 0] <- NA
+ }
+ sample1NT <- apply(sample.dis,1,min,na.rm=TRUE)
+ sample2NT <- apply(sample.dis,2,min,na.rm=TRUE)
+ if (abundance.weighted) {
+ sample1.weights <- comm[i,sppInSample1]
+ sample2.weights <- comm[j,sppInSample2]
+ sample.weights <- c(sample1.weights,sample2.weights)
+ comdisnt[i,j] <- weighted.mean(c(sample1NT,sample2NT),sample.weights,na.rm=TRUE)
+ }
+ else
+ {
+ comdisnt[i,j] <- mean(c(sample1NT,sample2NT))
+ }
+ }
+ else{
+ comdisnt[i,j] <- NA
+ }
+ }
+ }
+ rownames(comdisnt) <- colnames(comdisnt) <- rownames(comm)
+ as.dist(t(comdisnt))
+}
Modified: pkg/R/phylodiversity.R
===================================================================
--- pkg/R/phylodiversity.R 2009-04-01 21:55:40 UTC (rev 183)
+++ pkg/R/phylodiversity.R 2009-04-03 19:45:07 UTC (rev 184)
@@ -34,6 +34,66 @@
results
}
+
+`comm.phylo.qr` <-
+function(samp,phylo,metric=c("cij","checkerboard","jaccard","roij"),
+ null.model=c("sample.taxa.labels","pool.taxa.labels",
+ "frequency","richness","independentswap","trialswap"),
+ quant=0.75, runs=999, show.plot=FALSE, ...)
+{
+
+ if (!require(quantreg)) {
+ stop("The 'quantreg' package is required to use this function.")
+ }
+
+ metric <- match.arg(metric)
+ null.model <- match.arg(null.model)
+ results <- list("obs.qr.intercept"=NA,"obs.qr.slope"=NA,"obs.qr.slope.p"=NA,"obs.rank"=NA,"runs"=runs,
+ "random.qr.slopes"=vector(length=runs))
+ phylo.dist <- as.dist(cophenetic(prune.sample(samp,phylo)))
+ pool.phylo.dist <- as.dist(cophenetic(phylo))
+ taxa.names <- rownames(as.matrix(phylo.dist))
+ samp.dist <- as.dist(as.matrix(species.dist(samp,metric))[taxa.names,taxa.names])
+ results$quantile <- quant
+ qrres <- coef(rq(samp.dist~phylo.dist,tau=quant, na.action=na.omit))
+ names(qrres) <- NULL
+ results$obs.qr.intercept <- qrres[1]
+ results$obs.qr.slope <- qrres[2]
+
+ if (show.plot) {
+ plot(samp.dist~phylo.dist,xlab="Phylogenetic distance",ylab="Co-occurrence")
+ }
+
+ if (null.model=="sample.taxa.labels") for (run in 1:runs)
+ {
+ phylo.dist <- as.dist(taxaShuffle(as.matrix(phylo.dist))[taxa.names,taxa.names])
+ results$random.qr.slopes[run] <- coef(rq(samp.dist~phylo.dist,tau=quant,
+ na.action=na.omit))[2]
+ }
+ else if (null.model=="pool.taxa.labels") for (run in 1:runs)
+ {
+ phylo.dist <- as.dist(taxaShuffle(as.matrix(pool.phylo.dist))[taxa.names,taxa.names])
+ results$random.qr.slopes[run] <- coef(rq(samp.dist~phylo.dist,tau=quant,
+ na.action=na.omit))[2]
+ }
+ else for (run in 1:runs)
+ {
+ samp.dist <- species.dist(randomizeSample(samp,null.model,...),metric)
+ results$random.qr.slopes[run] <- coef(rq(samp.dist~phylo.dist,tau=quant,
+ na.action=na.omit))[2]
+ }
+ results$obs.rank <- rank(as.vector(c(results$obs.qr.slope,results$random.qr.slopes)))[1]
+ results$obs.qr.slope.p <- results$obs.rank/(runs+1)
+
+ if (show.plot) {
+ abline(results$obs.qr.intercept,results$obs.qr.slope)
+ legend("topleft",paste("q",as.character(quant),sep=""))
+ }
+
+ results
+}
+
+
`taxaShuffle` <-
function(x) {
#todo replace with vegan's permuted.index?
@@ -44,7 +104,8 @@
x
}
-mpd <- function(samp, dis)
+
+mpd <- function(samp, dis, abundance.weighted=FALSE)
{
N <- dim(samp)[1]
mpd <- numeric(N)
@@ -52,80 +113,102 @@
sppInSample <- names(samp[i, samp[i, ] > 0])
if (length(sppInSample) > 1) {
sample.dis <- dis[sppInSample, sppInSample]
- mpd[i] <- mean(sample.dis[lower.tri(sample.dis)])
+ if (abundance.weighted) {
+ sample.weights <- t(as.matrix(samp[i,sppInSample,drop=FALSE])) %*% as.matrix(samp[i,sppInSample,drop=FALSE])
+ mpd[i] <- weighted.mean(sample.dis,sample.weights)
+
+ }
+ else {
+ mpd[i] <- mean(sample.dis[lower.tri(sample.dis)])
+ }
}
else{
- mpd[i] <- 0
+ mpd[i] <- NA
}
}
mpd
}
-`mnnd` <-
-function(samp,dis) {
+mntd <- function(samp, dis, abundance.weighted=FALSE)
+{
N <- dim(samp)[1]
- mnnd <- numeric(N)
+ mntd <- numeric(N)
for (i in 1:N) {
- sppInSample <- names(samp[i,samp[i,]>0])
+ sppInSample <- names(samp[i,samp[i,] > 0])
if (length(sppInSample) > 1) {
sample.dis <- dis[sppInSample,sppInSample]
diag(sample.dis) <- NA
- mnnd[i] <- mean(apply(sample.dis,2,min,na.rm=TRUE))
+ if (abundance.weighted)
+ {
+ mntds <- apply(sample.dis,2,min,na.rm=TRUE)
+ sample.weights <- samp[i,sppInSample]
+ mntd[i] <- weighted.mean(mntds, sample.weights)
+ }
+ else
+ {
+ mntd[i] <- mean(apply(sample.dis,2,min,na.rm=TRUE))
+ }
}
else {
- mnnd[i] <- 0
+ mntd[i] <- NA
}
}
- mnnd
+ mntd
}
+
`ses.mpd` <-
function (samp, dis, null.model = c("taxa.labels", "sample.pool",
- "phylogeny.pool", "independentswap", "trialswap"), runs = 999, iterations = 1000)
+ "phylogeny.pool", "independentswap", "trialswap"),
+ abundance.weighted = FALSE, runs = 999, iterations = 1000)
{
dis <- as.matrix(dis)
- mpd.obs <- mpd(samp, dis)
+ mpd.obs <- mpd(samp, dis, abundance.weighted = abundance.weighted)
null.model <- match.arg(null.model)
mpd.rand <- switch(null.model,
- taxa.labels = t(replicate(runs, mpd(samp, taxaShuffle(dis)))),
- sample.pool = t(replicate(runs, mpd(randomizeSample(samp,null.model="richness"), dis))),
+ taxa.labels = t(replicate(runs, mpd(samp, taxaShuffle(dis), abundance.weighted=abundance.weighted))),
+ sample.pool = t(replicate(runs, mpd(randomizeSample(samp,null.model="richness"), dis, abundance.weighted))),
phylogeny.pool = t(replicate(runs, mpd(randomizeSample(samp,null.model="richness"),
- taxaShuffle(dis)))),
- independentswap = t(replicate(runs, mpd(randomizeSample(samp,null.model="independentswap", iterations), dis))),
- trialswap = t(replicate(runs, mpd(randomizeSample(samp,null.model="trialswap", iterations), dis)))
+ taxaShuffle(dis), abundance.weighted))),
+ independentswap = t(replicate(runs, mpd(randomizeSample(samp,null.model="independentswap", iterations), dis, abundance.weighted))),
+ trialswap = t(replicate(runs, mpd(randomizeSample(samp,null.model="trialswap", iterations), dis, abundance.weighted)))
)
- mpd.obs.rank <- apply(X = rbind(mpd.obs, mpd.rand), MARGIN = 2,
- FUN = rank)[1, ]
mpd.rand.mean <- apply(X = mpd.rand, MARGIN = 2, FUN = mean, na.rm=TRUE)
mpd.rand.sd <- apply(X = mpd.rand, MARGIN = 2, FUN = sd, na.rm=TRUE)
mpd.obs.z <- (mpd.obs - mpd.rand.mean)/mpd.rand.sd
+ mpd.obs.rank <- apply(X = rbind(mpd.obs, mpd.rand), MARGIN = 2,
+ FUN = rank)[1, ]
+ mpd.obs.rank <- ifelse(is.na(mpd.rand.mean),NA,mpd.obs.rank)
data.frame(ntaxa=specnumber(samp),mpd.obs, mpd.rand.mean, mpd.rand.sd, mpd.obs.rank,
mpd.obs.z, mpd.obs.p=mpd.obs.rank/(runs+1),runs=runs, row.names = row.names(samp))
}
-`ses.mnnd` <-
+
+`ses.mntd` <-
function (samp, dis, null.model = c("taxa.labels", "sample.pool",
- "phylogeny.pool", "independentswap", "trialswap"), runs = 999, iterations = 1000)
+ "phylogeny.pool", "independentswap", "trialswap"),
+ abundance.weighted = FALSE, runs = 999, iterations = 1000)
{
dis <- as.matrix(dis)
- mnnd.obs <- mnnd(samp, dis)
+ mntd.obs <- mntd(samp, dis, abundance.weighted)
null.model <- match.arg(null.model)
- mnnd.rand <- switch(null.model,
- taxa.labels = t(replicate(runs, mnnd(samp, taxaShuffle(dis)))),
- sample.pool = t(replicate(runs, mnnd(randomizeSample(samp,null.model="richness"), dis))),
- phylogeny.pool = t(replicate(runs, mnnd(randomizeSample(samp,null.model="richness"),
- taxaShuffle(dis)))),
- independentswap = t(replicate(runs, mnnd(randomizeSample(samp,null.model="independentswap", iterations), dis))),
- trialswap = t(replicate(runs, mnnd(randomizeSample(samp,null.model="trialswap", iterations), dis)))
+ mntd.rand <- switch(null.model,
+ taxa.labels = t(replicate(runs, mntd(samp, taxaShuffle(dis), abundance.weighted))),
+ sample.pool = t(replicate(runs, mntd(randomizeSample(samp,null.model="richness"), dis, abundance.weighted))),
+ phylogeny.pool = t(replicate(runs, mntd(randomizeSample(samp,null.model="richness"),
+ taxaShuffle(dis), abundance.weighted))),
+ independentswap = t(replicate(runs, mntd(randomizeSample(samp,null.model="independentswap", iterations), dis, abundance.weighted))),
+ trialswap = t(replicate(runs, mntd(randomizeSample(samp,null.model="trialswap", iterations), dis, abundance.weighted)))
)
- mnnd.obs.rank <- apply(X = rbind(mnnd.obs, mnnd.rand), MARGIN = 2,
+ mntd.rand.mean <- apply(X = mntd.rand, MARGIN = 2, FUN = mean, na.rm=TRUE)
+ mntd.rand.sd <- apply(X = mntd.rand, MARGIN = 2, FUN = sd, na.rm=TRUE)
+ mntd.obs.z <- (mntd.obs - mntd.rand.mean)/mntd.rand.sd
+ mntd.obs.rank <- apply(X = rbind(mntd.obs, mntd.rand), MARGIN = 2,
FUN = rank)[1, ]
- mnnd.rand.mean <- apply(X = mnnd.rand, MARGIN = 2, FUN = mean, na.rm=TRUE)
- mnnd.rand.sd <- apply(X = mnnd.rand, MARGIN = 2, FUN = sd, na.rm=TRUE)
- mnnd.obs.z <- (mnnd.obs - mnnd.rand.mean)/mnnd.rand.sd
- data.frame(ntaxa=specnumber(samp),mnnd.obs, mnnd.rand.mean, mnnd.rand.sd, mnnd.obs.rank,
- mnnd.obs.z, mnnd.obs.p=mnnd.obs.rank/(runs+1),runs=runs, row.names = row.names(samp))
+ mntd.obs.rank <- ifelse(is.na(mntd.rand.mean),NA,mntd.obs.rank)
+ data.frame(ntaxa=specnumber(samp),mntd.obs, mntd.rand.mean, mntd.rand.sd, mntd.obs.rank,
+ mntd.obs.z, mntd.obs.p=mntd.obs.rank/(runs+1),runs=runs, row.names = row.names(samp))
}
@@ -497,7 +580,7 @@
#all species in tree present in sampunity
PD <- sum(tree$edge.length)
}
- else
+ else
{
#subset of tree species present in sampunity
sub.tree<-drop.tip(tree,treeabsent)
@@ -511,7 +594,7 @@
}
else {
PD<-sum(sub.tree$edge.length)
- }
+ }
}
PDs<-c(PDs,PD)
Added: pkg/R/pic3.R
===================================================================
--- pkg/R/pic3.R (rev 0)
+++ pkg/R/pic3.R 2009-04-03 19:45:07 UTC (rev 184)
@@ -0,0 +1,47 @@
+## pic3 is a minor modification of the pic function from the ape
+## library that returns the nodal values at each node of the
+## tree in a third column, along with the contrasts and the
+## variance of the contrasts.
+
+pic3 = function (x, phy, scaled = TRUE, var.contrasts = TRUE)
+{
+ if (class(phy) != "phylo")
+ stop("object 'phy' is not of class \"phylo\"")
+ if (is.null(phy$edge.length))
+ stop("your tree has no branch lengths: you may consider setting them equal to one, or using the function `compute.brlen'.")
+ nb.tip <- length(phy$tip.label)
+ nb.node <- phy$Nnode
+ if (nb.node != nb.tip - 1)
+ stop("'phy' is not rooted and fully dichotomous")
+ if (length(x) != nb.tip)
+ stop("length of phenotypic and of phylogenetic data do not match")
+ if (any(is.na(x)))
+ stop("the present method cannot (yet) be used directly with missing data: you may consider removing the species with missing data from your tree with the function `drop.tip'.")
+ phy <- reorder(phy, "pruningwise")
+ phenotype <- numeric(nb.tip + nb.node)
+ if (is.null(names(x))) {
+ phenotype[1:nb.tip] <- x
+ } else {
+ if (all(names(x) %in% phy$tip.label))
+ phenotype[1:nb.tip] <- x[phy$tip.label]
+ else {
+ phenotype[1:nb.tip] <- x
+ warning("the names of argument \"x\" and the names of the tip labels did not match: the former were ignored in the analysis.")
+ }
+ }
+ contr <- var.con <- numeric(nb.node)
+ ans <- .C("pic", as.integer(nb.tip), as.integer(nb.node),
+ as.integer(phy$edge[, 1]), as.integer(phy$edge[, 2]),
+ as.double(phy$edge.length), as.double(phenotype), as.double(contr),
+ as.double(var.con), as.integer(var.contrasts), as.integer(scaled),
+ PACKAGE = "ape")
+ contr <- ans[[7]]
+ if (var.contrasts) {
+ contr <- cbind(contr, ans[[8]])
+ contr <- cbind(contr, ans[[6]][-(1:nb.tip)])
+ dimnames(contr) <- list(1:nb.node + nb.tip, c("contrasts",
+ "variance","node.vals"))
+ }
+ else names(contr) <- 1:nb.node + nb.tip
+ return(contr)
+}
\ No newline at end of file
Added: pkg/R/traitgram.R
===================================================================
--- pkg/R/traitgram.R (rev 0)
+++ pkg/R/traitgram.R 2009-04-03 19:45:07 UTC (rev 184)
@@ -0,0 +1,69 @@
+traitgram = function(
+ ## draws a phylogeny with tips and nodes positioned
+ ## by trait value, and brownian ancestral value
+ ## node height by branch lengths
+
+ x,phy,
+ xaxt='s',
+ underscore = FALSE,
+ show.names = TRUE,
+ show.xaxis.vals = TRUE,
+ method = c('ace','pic'),
+ ...)
+
+{
+ require(ape)
+ Ntaxa = length(phy$tip.label)
+ Ntot = Ntaxa + phy$Nnode
+ phy = node.age(phy)
+ ages = phy$ages[match(1:Ntot,phy$edge[,2])]
+ ages[Ntaxa+1]=0
+ #ages
+
+ if (class(x) %in% c('matrix','array')) {
+ xx = as.numeric(x)
+ names(xx) = row.names(x)
+ } else xx = x
+
+ if (!is.null(names(xx))) {
+ umar = 0.1
+ if (!all(names(xx) %in% phy$tip.label)) {
+ print('trait and phy names do not match')
+ return()
+ }
+ xx = xx[match(phy$tip.label,names(xx))]
+ } else umar = 0.1
+
+ lmar = 0.2
+ if (xaxt=='s') if (show.xaxis.vals) lmar = 1 else lmar = 0.5
+ if (method[1]=='ace') xanc = ace(xx,phy)$ace
+ else xanc = pic3(xx,phy)[,3]
+ xall = c(xx,xanc)
+
+ a0 = ages[phy$edge[,1]]
+ a1 = ages[phy$edge[,2]]
+ x0 = xall[phy$edge[,1]]
+ x1 = xall[phy$edge[,2]]
+
+ tg = par(bty='n',mai=c(lmar,0.1,umar,0.1))
+ if (show.names) {
+ maxNameLength = max(nchar(names(xx)))
+ ylim = c(min(ages),max(ages)*(1+maxNameLength/50))
+ if (!underscore) names(xx) = gsub('_',' ',names(xx))
+ } else ylim = range(ages)
+ plot(range(c(x0,x1)),range(c(a0,a1)),
+ type='n',xaxt='n',yaxt='n',
+ xlab='',ylab='',bty='n',ylim=ylim,cex.axis=0.8)
+ if (xaxt=='s') if (show.xaxis.vals) axis(1,labels=TRUE)
+ else axis(1,labels=FALSE)
+ segments(x0,a0,x1,a1)
+ if (show.names) {
+ text(sort(xx),max(ages),
+ labels = names(xx)[order(xx)],
+ adj = -0,
+ srt=90)
+ }
+ on.exit(par(tg))
+}
+
+
Added: pkg/man/comdist.Rd
===================================================================
--- pkg/man/comdist.Rd (rev 0)
+++ pkg/man/comdist.Rd 2009-04-03 19:45:07 UTC (rev 184)
@@ -0,0 +1,30 @@
+\name{comdist}
+\alias{comdist}
+\title{ Calculates inter-community mean pairwise distance }
+\description{
+ Calculates MPD (mean pairwise distance) separating taxa in two communities, a measure of phylogenetic beta diversity
+}
+\usage{
+comdist(comm, dis, abundance.weighted = FALSE, exclude.conspecifics = FALSE)
+
+}
+
+\arguments{
+ \item{comm}{ Community data matrix }
+ \item{dis}{ Interspecific distance matrix }
+ \item{abundance.weighted}{ Should mean pairwise distances separating species in two communities be weighted by species abundances? (default = FALSE)}
+ \item{exclude.conspecifics}{ Should conspecific taxa in different communities be excluded from MPD calculations? (default = FALSE)}
+}
+\value{
+ Distance object of MPD values separating each pair of communities.
+}
+\details{
+ This function calculates a measure of phylogenetic beta diversity: the expected phylogenetic distance separating two individuals or taxa drawn randomly from different communities.
+}
+\references{ C.O. Webb, D.D. Ackerly, and S.W. Kembel. 2008. Phylocom: software for the analysis of phylogenetic community structure and trait evolution. Bioinformatics 18:2098-2100. }
+\author{ Steven Kembel <skembel at uoregon.edu> }
+\seealso{ \code{\link{mpd}}, \code{\link{ses.mpd}} }
+\examples{
+data(phylocom)
+comdist(phylocom$sample, cophenetic(phylocom$phylo), abundance.weighted=TRUE)}
+\keyword{univar}
Added: pkg/man/comdistnt.Rd
===================================================================
--- pkg/man/comdistnt.Rd (rev 0)
+++ pkg/man/comdistnt.Rd 2009-04-03 19:45:07 UTC (rev 184)
@@ -0,0 +1,32 @@
+\name{comdistnt}
+\alias{comdistnt}
+\alias{comdistnn}
+\title{ Calculates inter-community mean nearest taxon distance }
+\description{
+ Calculates MNTD (mean nearest taxon distance) separating taxa in two communities, a measure of phylogenetic beta diversity
+}
+\usage{
+comdistnt(comm, dis, abundance.weighted = FALSE, exclude.conspecifics = FALSE)
+}
+
+\arguments{
+ \item{comm}{ Community data matrix }
+ \item{dis}{ Interspecific distance matrix }
+ \item{abundance.weighted}{ Should mean nearest taxon distances from each species to species in the other community be weighted by species abundance? (default = FALSE)}
+ \item{exclude.conspecifics}{ Should conspecific taxa in different communities be exclude from MNTD calculations? (default = FALSE) }
+}
+\value{
+ Distance object of MNTD values separating each pair of communities.
+}
+\details{
+ This metric has also been referred to as MNND (mean nearest neighbour distance).
+
+ This function calculates a measure of phylogenetic beta diversity: the average phylogenetic distance to the most similar taxon or individual in the other community for taxa or individuals in two communities.
+}
+\references{ C.O. Webb, D.D. Ackerly, and S.W. Kembel. 2008. Phylocom: software for the analysis of phylogenetic community structure and trait evolution. Bioinformatics 18:2098-2100. }
+\author{ Steven Kembel <skembel at uoregon.edu> }
+\seealso{ \code{\link{mntd}}, \code{\link{ses.mntd}} }
+\examples{
+data(phylocom)
+comdistnt(phylocom$sample, cophenetic(phylocom$phylo), abundance.weighted=FALSE)}
+\keyword{univar}
Added: pkg/man/comm.phylo.qr.Rd
===================================================================
--- pkg/man/comm.phylo.qr.Rd (rev 0)
+++ pkg/man/comm.phylo.qr.Rd 2009-04-03 19:45:07 UTC (rev 184)
@@ -0,0 +1,56 @@
+\name{comm.phylo.qr}
+\alias{comm.phylo.qr}
+
+\title{ Quantile regression slopes between species co-occurrence and phylogenetic distances }
+\description{
+ Calculates measures of community phylogenetic structure (quantile regression between co-occurrence and phylogenetic distance) to patterns expected under various null models
+}
+\usage{
+comm.phylo.qr(samp, phylo, metric = c("cij", "checkerboard", "jaccard", "roij"),
+ null.model = c("sample.taxa.labels", "pool.taxa.labels",
+ "frequency", "richness", "independentswap","trialswap"),
+ quant = 0.75, runs = 999, show.plot = FALSE, ...)
+}
+\arguments{
+ \item{samp}{ Community data matrix }
+ \item{phylo}{ Phylogenetic tree }
+ \item{metric}{ Metric of co-occurrence to use (see \code{\link{species.dist}})}
+ \item{null.model}{ Null model to use (see Details section for description) }
+ \item{quant}{ Quantile of slope to be fit (using \code{\link[quantreg]{rq}}) }
+ \item{runs}{ Number of runs (randomizations) }
+ \item{show.plot}{ Option to display a plot of co-occurrence versus phylogenetic distance with quantile regression slope fit }
+ \item{...}{ Additional arguments to \link{randomizeSample}}
+}
+\value{
+ A list with elements:
+ \item{obs.qr.intercept }{ Observed co-occurrence/phylogenetic distance quantile regression intercept}
+ \item{obs.qr.slope }{ Observed co-occurrence/phylogenetic distance quantile regression slope}
+ \item{obs.qr.slope.p}{ P-value of observed quantile regression slope significance versus null model (calculated based on comparison with randomizations)}
+ \item{obs.rank}{ Rank of observed quantile regression slope vs. random}
+ \item{runs}{ Number of runs (randomizations) }
+ \item{random.qr.slopes}{A vector of quantile regression slopes calculated for each randomization}
+}
+\details{
+This function fits a quantile regression of co-occurrence versus phylogenetic distances separating species, and compares observed patterns to the patterns expected under some null model. The quantile regressions are fit using the \code{\link[brglm]{rq}} function from the \code{quantreg} package.
+
+Currently implemented null models (arguments to null.model):
+\describe{
+ \item{sample.taxa.labels}{Shuffle phylogeny tip labels (only within set of taxa present in community data)}
+ \item{pool.taxa.labels}{Shuffle phylogeny tip labels (across all taxa included in phylogenetic tree)}
+ \item{frequency}{Randomize community data matrix abundances within species (maintains species occurence frequency)}
+ \item{richness}{Randomize community data matrix abundances within samples (maintains sample species richness)}
+ \item{independentswap}{Randomize community data matrix maintaining species occurrence frequency and site richnessing using independent swap}
+ \item{trialswap}{Randomize community data matrix maintaining species occurrence frequency and site richnessing using trial swap}
+ }
+}
+\references{
+Cavender-Bares J., D.A. Ackerly, D. Baum and F.A. Bazzaz. 2004. Phylogenetic overdispersion in Floridian oak communities, American Naturalist, 163(6):823-843.
+Slingsby, J. A. and G. A. Verboom. 2006. Phylogenetic relatedness limits coexistence at fine spatial scales: evidence from the schoenoid sedges (Cyperaceae: Schoeneae) of the Cape Floristic Region, South Africa. The American Naturalist 168:14-27.
+}
+\author{ Steven Kembel <skembel at uoregon.edu> }
+\seealso{ \code{\link{randomizeSample}} }
+\examples{
+data(phylocom)
+comm.phylo.qr(phylocom$sample, phylocom$phylo, metric="cij",null.model="sample.taxa.labels",
+show.plot=TRUE)}
+\keyword{univar}
Deleted: pkg/man/mnnd.Rd
===================================================================
--- pkg/man/mnnd.Rd 2009-04-01 21:55:40 UTC (rev 183)
+++ pkg/man/mnnd.Rd 2009-04-03 19:45:07 UTC (rev 184)
@@ -1,21 +0,0 @@
-\name{mnnd}
-\alias{mnnd}
-\title{ Mean nearest neighbour distance }
-\description{
- Calculates MNND (mean nearest neighbour distance) for taxa in a community
-}
-\usage{
-mnnd(samp, dis)
-}
-
-\arguments{
- \item{samp}{ Community data matrix }
- \item{dis}{ Interspecific distance matrix }
-}
-\value{
- Vector of MNND values for each community.
-}
-\references{ Webb, C., D. Ackerly, M. McPeek, and M. Donoghue. 2002. Phylogenies and community ecology. Annual Review of Ecology and Systematics 33:475-505. }
-\author{ Steven Kembel <skembel at uoregon.edu> }
-\seealso{ \code{\link{ses.mnnd}} }
-\keyword{univar}
Added: pkg/man/mntd.Rd
===================================================================
--- pkg/man/mntd.Rd (rev 0)
+++ pkg/man/mntd.Rd 2009-04-03 19:45:07 UTC (rev 184)
@@ -0,0 +1,30 @@
+\name{mntd}
+\alias{mntd}
+\alias{mnnd}
+\title{ Mean nearest taxon distance }
+\description{
+ Calculates MNTD (mean nearest taxon distance) for taxa in a community
+}
+\usage{
+mntd(samp, dis, abundance.weighted=FALSE)
+}
+
+\arguments{
+ \item{samp}{ Community data matrix }
+ \item{dis}{ Interspecific distance matrix }
+ \item{abundance.weighted}{ Should mean nearest taxon distances for each species be weighted by species abundance? (default = FALSE)}
+}
+\value{
+ Vector of MNTD values for each community.
+}
+\details{
+ This metric has also been referred to as MNND (mean nearest neighbour distance), and the function was named \code{mnnd} in picante versions < 0.7.
+}
+\references{ Webb, C., D. Ackerly, M. McPeek, and M. Donoghue. 2002. Phylogenies and community ecology. Annual Review of Ecology and Systematics 33:475-505. }
+\author{ Steven Kembel <skembel at uoregon.edu> }
+\seealso{ \code{\link{ses.mntd}} }
+\examples{
+data(phylocom)
+mntd(phylocom$sample, cophenetic(phylocom$phylo), abundance.weighted=TRUE)
+}
+\keyword{univar}
Modified: pkg/man/mpd.Rd
===================================================================
--- pkg/man/mpd.Rd 2009-04-01 21:55:40 UTC (rev 183)
+++ pkg/man/mpd.Rd 2009-04-03 19:45:07 UTC (rev 184)
@@ -2,15 +2,16 @@
\alias{mpd}
\title{ Mean pairwise distance }
\description{
- Calculates mean pairwise distance for a community
+ Calculates mean pairwise distance separating taxa in a community
}
\usage{
-mpd(samp, dis)
+mpd(samp, dis, abundance.weighted=FALSE)
}
\arguments{
\item{samp}{ Community data matrix }
\item{dis}{ Interspecific distance matrix }
+ \item{abundance.weighted}{ Should mean pairwise distances be weighted by species abundance? (default = FALSE)}
}
\value{
@@ -19,4 +20,8 @@
\references{ Webb, C., D. Ackerly, M. McPeek, and M. Donoghue. 2002. Phylogenies and community ecology. Annual Review of Ecology and Systematics 33:475-505. }
\author{ Steven Kembel <skembel at uoregon.edu> }
\seealso{ \code{\link{ses.mpd}}}
+\examples{
+data(phylocom)
+mpd(phylocom$sample, cophenetic(phylocom$phylo), abundance.weighted=TRUE)
+}
\keyword{univar}
Added: pkg/man/pic3.Rd
===================================================================
--- pkg/man/pic3.Rd (rev 0)
+++ pkg/man/pic3.Rd 2009-04-03 19:45:07 UTC (rev 184)
@@ -0,0 +1,38 @@
+\name{pic3}
+\alias{pic3}
+
+\title{ Independent contrasts }
+\description{
+ Modification of pic function from ape to return internal node values as well as contrasts and variance of contrasts.
+}
+\usage{
+pic3(x, phy, scaled = TRUE, var.contrasts = TRUE)
+}
+
+\arguments{
+ \item{x}{ Trait vector (same order as phy\$tip.label) }
+ \item{phy}{ phylo object }
+ \item{scaled}{ TRUE = standardize contrasts by branch lengths }
+ \item{...}{ TRUE = return variance of contrasts }
+}
+\value{
+ Matrix with three columns:
+ \item{row.names }{node numbers}
+ \item{contrasts }{independent contrast value}
+ \item{variance }{variance of contrasts (sum of subtending branch lengths)}
+ \item{node.vals }{values calculated at internal nodes by contrast algorithm}
+}
+\references{
+Felsenstein J (1985) Phylogenies and the comparative method. American Naturalist 125: 1-15.
+
+Garland T, Jr, Harvey PH & Ives AR (1992) Procedures for the analysis of comparative data using phylogenetically independent contrasts. Systematic Biology 41: 18-32.
+ }
+\author{ Original pic function by Emmanuel Paradis <Emmanuel.Paradis at mpl.ird.fr> modified to return node.vals by David Ackerly <dackerly at berkeley.edu> }
+\seealso{ \code{\link{pic}} }
+\section{Warning }{ Assumes that trait data are sorted in the same order as phylo\$tip.label }
+\examples{
+randtree <- rcoal(20)
+randtraits <- evolve.brownian(randtree)
+pic3(randtraits,randtree)
+}
+\keyword{univar}
\ No newline at end of file
Modified: pkg/man/picante-package.Rd
===================================================================
--- pkg/man/picante-package.Rd 2009-04-01 21:55:40 UTC (rev 183)
+++ pkg/man/picante-package.Rd 2009-04-03 19:45:07 UTC (rev 184)
@@ -12,8 +12,8 @@
\tabular{ll}{
Package: \tab picante\cr
Type: \tab Package\cr
-Version: \tab 0.6-1\cr
-Date: \tab 2009-3-18\cr
+Version: \tab 0.7-0\cr
+Date: \tab 2009-4-3\cr
License: \tab GPL-2\cr
}
}
Deleted: pkg/man/ses.mnnd.Rd
===================================================================
--- pkg/man/ses.mnnd.Rd 2009-04-01 21:55:40 UTC (rev 183)
+++ pkg/man/ses.mnnd.Rd 2009-04-03 19:45:07 UTC (rev 184)
@@ -1,50 +0,0 @@
-\name{ses.mnnd}
-\alias{ses.mnnd}
-
-\title{ Standardized effect size of MNND }
-\description{
- Standardized effect size of mean nearest neighbour distances in communities. When used with a phylogenetic distance matrix, equivalent to -1 times the Nearest Taxon Index (NTI).
-}
-\usage{
-ses.mnnd(samp, dis, null.model = c("taxa.labels","sample.pool", "phylogeny.pool",
- "independentswap", "trialswap"), runs = 999, iterations = 1000)
-}
-
-\arguments{
- \item{ samp }{ Community data matrix }
- \item{ dis }{ Distance matrix (generally a phylogenetic distance matrix)}
- \item{ null.model }{ Null model to use (see Details section for description) }
- \item{ runs }{ Number of randomizations }
- \item{ iterations }{ Number of iterations to use for each randomization (for independent swap and trial null models) }
-}
-
-\value{
- A data frame of results for each community
- \item{ntaxa}{Number of taxa in community}
- \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{
-Currently implemented null models (arguments to null.model):
-\describe{
- \item{taxa.labels}{ Shuffle distance matrix labels (across all taxa included in distance matrix)}
- \item{sample.pool}{ Randomize community data matrix by drawing species from pool of species occurring in at least one community (sample pool) with equal probability}
- \item{phylogeny.pool}{ Randomize community data matrix by drawing species from pool of species occurring in the distance matrix (phylogeny pool) with equal probability}
- \item{frequency}{ Randomize community data matrix abundances within species (maintains species occurence frequency)}
- \item{richness}{ Randomize community data matrix abundances within samples (maintains sample species richness)}
- \item{independentswap}{ Randomize community data matrix with the independent swap algorithm (Gotelli 2000) maintaining species occurrence frequency and sample species richness }
[TRUNCATED]
To get the complete diff run:
svnlook diff /svnroot/picante -r 184
More information about the Picante-commits
mailing list