[Vegan-commits] r928 - in pkg/vegan: R inst man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Aug 17 19:15:41 CEST 2009
Author: jarioksa
Date: 2009-08-17 19:15:39 +0200 (Mon, 17 Aug 2009)
New Revision: 928
Added:
pkg/vegan/R/treedist.R
Modified:
pkg/vegan/R/treedive.R
pkg/vegan/R/treeheight.R
pkg/vegan/inst/ChangeLog
pkg/vegan/man/treedive.Rd
Log:
treedist: dissimilarity based on species trees and other experimental changes that may be cancelled later
Added: pkg/vegan/R/treedist.R
===================================================================
--- pkg/vegan/R/treedist.R (rev 0)
+++ pkg/vegan/R/treedist.R 2009-08-17 17:15:39 UTC (rev 928)
@@ -0,0 +1,21 @@
+`treedist` <-
+ function(x, tree, ...)
+{
+ n <- nrow(x)
+ ABJ <- matrix(0, n , n)
+ dmat <- as.matrix(cophenetic(tree))
+ for(j in 1:n)
+ for (k in j:n) {
+ jk <- x[j,] > 0 | x[k,] > 0
+ if (sum(jk) > 1)
+ ABJ[k, j] <- treeheight(update(tree, d = as.dist(dmat[jk, jk])))
+ }
+ A <- diag(ABJ)
+ AB <- as.dist(outer(A, A, "+"))
+ ABJ <- as.dist(ABJ)
+ out <- (2 * ABJ - AB)/ABJ
+ attr(out, "method") <- "treedist"
+ attr(out, "call") <- match.call()
+ attr(out, "Labels") <- row.names(x)
+ out
+}
Modified: pkg/vegan/R/treedive.R
===================================================================
--- pkg/vegan/R/treedive.R 2009-08-17 14:10:09 UTC (rev 927)
+++ pkg/vegan/R/treedive.R 2009-08-17 17:15:39 UTC (rev 928)
@@ -1,11 +1,11 @@
`treedive` <-
function(comm, tree, match.force = FALSE)
{
- if (!inherits(tree, "hclust"))
- stop("'clus' must be an 'hclust' result object")
+ if (!inherits(tree, c("hclust", "spantree")))
+ stop("'clus' must be an 'hclust' or 'spantree' result object")
m <- as.matrix(cophenetic(tree))
## Check tree/comm match by names
- if (match.force || ncol(comm) != length(tree$order)) {
+ if (match.force || ncol(comm) != ncol(m)) {
if (match.force)
message("Forced matching of 'tree' labels and 'comm' names")
else
Modified: pkg/vegan/R/treeheight.R
===================================================================
--- pkg/vegan/R/treeheight.R 2009-08-17 14:10:09 UTC (rev 927)
+++ pkg/vegan/R/treeheight.R 2009-08-17 17:15:39 UTC (rev 928)
@@ -1,6 +1,8 @@
`treeheight` <-
function(tree)
{
+ if (inherits(tree, "spantree"))
+ return(sum(tree$dist))
tree <- as.hclust(tree)
m <- tree$merge
h <- tree$height
Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog 2009-08-17 14:10:09 UTC (rev 927)
+++ pkg/vegan/inst/ChangeLog 2009-08-17 17:15:39 UTC (rev 928)
@@ -6,6 +6,20 @@
* spantree: first argument 'd' like in hclust()instead of 'dis'.
Got a 'call' item so that update() works.
+
+ * treedive & treeheight: accept 'spantree' objects. EXPERIMENTAL
+ CHANGE THAT MAY BE CANCELLED.
+
+ * treedist: average distance of species trees for two
+ sites. Generalization of treedive(): builds a species tree of two
+ sites and sees how much of the tree is shared between two sites,
+ and how much is unique to the combination. The measure is similar
+ to Jaccard index: the proportion of unique (unshared) tree of the
+ combined tree. In principle, this is similar to UniFrac metric
+ (C. Lozupone & R. Knight, Appl. Environ. Microbiol. 71:8225-8235;
+ 2005), but numerically and computationally different (and the
+ current implementation may specify a new unpublished method). AN
+ EXPERIMENTAL CHANGE THAT MAY BE CANCELLED.
Version 1.16-23 (closed August 17, 2009)
Modified: pkg/vegan/man/treedive.Rd
===================================================================
--- pkg/vegan/man/treedive.Rd 2009-08-17 14:10:09 UTC (rev 927)
+++ pkg/vegan/man/treedive.Rd 2009-08-17 17:15:39 UTC (rev 928)
@@ -1,6 +1,7 @@
\name{treedive}
\alias{treedive}
\alias{treeheight}
+\alias{treedist} ## Undocumented!!
\title{ Functional Diversity estimated from a Species Dendrogram}
\description{
More information about the Vegan-commits
mailing list