[Vegan-commits] r2392 - in pkg/vegan: R inst man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Jan 28 15:09:13 CET 2013
Author: jarioksa
Date: 2013-01-28 15:09:13 +0100 (Mon, 28 Jan 2013)
New Revision: 2392
Modified:
pkg/vegan/R/treedist.R
pkg/vegan/R/treedive.R
pkg/vegan/inst/ChangeLog
pkg/vegan/man/treedive.Rd
Log:
fix (treedive) and add (treedist) matching of tree and data by names
Modified: pkg/vegan/R/treedist.R
===================================================================
--- pkg/vegan/R/treedist.R 2013-01-28 08:15:37 UTC (rev 2391)
+++ pkg/vegan/R/treedist.R 2013-01-28 14:09:13 UTC (rev 2392)
@@ -1,9 +1,16 @@
`treedist` <-
- function(x, tree, relative = TRUE, ...)
+ function(x, tree, relative = TRUE, match.force = FALSE, ...)
{
n <- nrow(x)
ABJ <- matrix(0, n , n)
dmat <- as.matrix(cophenetic(tree))
+ ## match names
+ if (ncol(x) != ncol(dmat) || match.force) {
+ if(!match.force)
+ warning("Dimensions do not match between 'x' and 'tree' - matching by names")
+ nm <- colnames(x)
+ dmat <- dmat[nm, nm]
+ }
for(j in 1:n) {
for (k in j:n) {
jk <- x[j,] > 0 | x[k,] > 0
Modified: pkg/vegan/R/treedive.R
===================================================================
--- pkg/vegan/R/treedive.R 2013-01-28 08:15:37 UTC (rev 2391)
+++ pkg/vegan/R/treedive.R 2013-01-28 14:09:13 UTC (rev 2392)
@@ -19,6 +19,7 @@
if (!all(fnd))
warning("not all names of 'tree' found in 'comm'")
comm <- comm[, tree$labels[fnd]]
+ m <- m[tree$labels[fnd], tree$labels[fnd]]
if (length(unique(tree$labels)) != length(tree$labels))
stop("names not unique in 'tree': match wrong")
if (length(unique(colnames(comm))) != ncol(comm))
Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog 2013-01-28 08:15:37 UTC (rev 2391)
+++ pkg/vegan/inst/ChangeLog 2013-01-28 14:09:13 UTC (rev 2392)
@@ -17,6 +17,12 @@
matrix. This should not influence the results, but one metaMDS()
trace result has a small difference in nearly-zero rmse (was
1.094382e-06, is 1.09439e-06) in my desktop.
+
+ * treedive, treedist: treedive() did not correctly match data and
+ tree when the tree contained species that did not occur in the
+ data. Function treedist() tries to match tree and data when their
+ sizes differ, and argument 'match.force' was added to force
+ matching even when sizes do not differ.
Version 2.1-23 (closed January 25, 2013)
Modified: pkg/vegan/man/treedive.Rd
===================================================================
--- pkg/vegan/man/treedive.Rd 2013-01-28 08:15:37 UTC (rev 2391)
+++ pkg/vegan/man/treedive.Rd 2013-01-28 14:09:13 UTC (rev 2392)
@@ -13,17 +13,18 @@
\usage{
treedive(comm, tree, match.force = FALSE)
treeheight(tree)
-treedist(x, tree, relative = TRUE, ...)
+treedist(x, tree, relative = TRUE, match.force = FALSE, ...)
}
\arguments{
\item{comm, x}{Community data frame or matrix.}
\item{tree}{A dendrogram which for \code{treedive} must be for species
(columns).}
- \item{match.force}{Force matching of column names in \code{comm} and
- labels in \code{tree}. If \code{FALSE}, matching only happens when
- dimensions differ, and in that case the species must be in identical
- order in both.}
+ \item{match.force}{Force matching of column names in data
+ (\code{comm}, \code{x}) and labels in \code{tree}. If \code{FALSE},
+ matching only happens when dimensions differ (with a warning or
+ message). The order of data must match to the order in \code{tree}
+ if matching by names is not done.}
\item{relative}{Use distances relative to the height of combined tree.}
\item{\dots}{Other arguments passed to functions (ignored).}
}
@@ -81,6 +82,15 @@
can be used similarly.
}
+\seealso{
+ Function \code{treedive} is similar to the phylogenetic diversity
+ function \code{\link[picante]{pd}} in \pkg{picante}, but excludes tree
+ root if that is not needed to connect species. Function
+ \code{treedist} is similar to the phylogenetic similarity
+ \code{\link[picante]{phylosor}} in \pkg{picante}, but excludes
+ unneeded tree root and returns distances instead of similarities.
+}
+
\references{
Lozupone, C. and Knight, R. 2005. UniFrac: a new phylogenetic method
for comparing microbial communities. \emph{Applied and Environmental
More information about the Vegan-commits
mailing list