[Vegan-commits] r2855 - in pkg/vegan: R inst man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Feb 10 09:40:49 CET 2014


Author: jarioksa
Date: 2014-02-10 09:40:49 +0100 (Mon, 10 Feb 2014)
New Revision: 2855

Modified:
   pkg/vegan/R/tabasco.R
   pkg/vegan/inst/ChangeLog
   pkg/vegan/man/vegemite.Rd
Log:
tabasco can use reorder.hclust

Modified: pkg/vegan/R/tabasco.R
===================================================================
--- pkg/vegan/R/tabasco.R	2014-02-09 07:41:46 UTC (rev 2854)
+++ pkg/vegan/R/tabasco.R	2014-02-10 08:40:49 UTC (rev 2855)
@@ -19,32 +19,44 @@
                 sp.ind <- order(wascores(use, x))
         }
         else if (inherits(use, c("dendrogram", "hclust", "twins"))) {
+            ## "twins" and "dendrogram" are treated as "dendrogram",
+            ## but "hclust" is kept as "hclust": they differ in
+            ## reorder()
             if (inherits(use, "twins")) {
                 require(cluster) || stop("package cluster needed to handle 'use'")
+                use <- as.dendrogram(use)
             }
-            if (!inherits(use, "dendrogram"))
-                use <- as.dendrogram(use)
             if (!is.null(site.ind))
                 stop("'site.ind' cannot be used with dendrogram")
             ## Reorder tree if Rowv specified
             if (isTRUE(Rowv)) {
                 ## order by first CA axis -- decorana() is fastest
                 tmp <- decorana(x, ira = 1)
+                ## reorder() command is equal to all, but "dendrogram"
+                ## will use unweighted mean and "hclust" weighted
+                ## mean.
                 use <- reorder(use, scores(tmp, dis="sites", choices = 1),
-                               agglo.FUN = mean)
+                               agglo.FUN = "mean")
             } else if (length(Rowv) > 1) {
                 ## Rowv is a vector
                 if (length(Rowv) != nrow(x))
                     stop(gettextf("Rowv has length %d, but 'x' has %d rows",
                                   length(Rowv), nrow(x)))
-                use <- reorder(use, Rowv, agglo.FUN = mean)
+                use <- reorder(use, Rowv, agglo.FUN = "mean")
             }
-            site.ind <- seq_len(nrow(x))
-            names(site.ind) <- rownames(x)
-            site.ind <- site.ind[labels(use)]
+            if (inherits(use, "dendrogram")) { 
+                site.ind <- seq_len(nrow(x))
+                names(site.ind) <- rownames(x)
+                site.ind <- site.ind[labels(use)]
+            } else {
+                site.ind <- use$order
+            }
             if (is.null(sp.ind)) 
                 sp.ind <- order(wascores(order(site.ind), x))
             pltree <- use
+            ## heatmap needs a "dendrogram"
+            if(!inherits(pltree, "dendrogram"))
+                pltree <- as.dendrogram(pltree)
         }
         else if (is.list(use)) {
             tmp <- scores(use, choices = 1, display = "sites")
@@ -66,24 +78,30 @@
     }
     ## see if sp.ind is a dendrogram or hclust tree
     if (inherits(sp.ind, c("hclust", "dendrogram", "twins"))) {
-        if (inherits(sp.ind, "twins"))
+        if (inherits(sp.ind, "twins")) {
             require("cluster") || stop("package cluster needed to handle 'sp.ind'")
-        if (!inherits(sp.ind, "dendrogram"))
             sp.ind <- as.dendrogram(sp.ind)
+        }
         sptree <- sp.ind
         ## Consider reordering species tree
         if (isTRUE(Colv) && !is.null(site.ind)) {
             sptree <- reorder(sptree, wascores(order(site.ind), x),
-                                  agglo.FUN = mean)
+                                  agglo.FUN = "mean")
         } else if (length(Colv) > 1) {
             if (length(Colv) != ncol(x))
                 stop(gettextf("Colv has length %d, but 'x' has %d columns",
                               length(Colv), ncol(x)))
-            sptree <- reorder(sptree, Colv, agglo.FUN = mean)
+            sptree <- reorder(sptree, Colv, agglo.FUN = "mean")
         }
-        sp.ind <- seq_len(ncol(x))
-        names(sp.ind) <- colnames(x)
-        sp.ind <- sp.ind[labels(sptree)]
+        if (inherits(sptree, "dendrogram")) {
+            sp.ind <- seq_len(ncol(x))
+            names(sp.ind) <- colnames(x)
+            sp.ind <- sp.ind[labels(sptree)]
+        } else {
+            sp.ind <- sptree$order
+        }
+        if (!inherits(sptree, "dendrogram"))
+            sptree <- as.dendrogram(sptree)
         ## reverse: origin in the upper left corner
         sptree <- rev(sptree)
     }

Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog	2014-02-09 07:41:46 UTC (rev 2854)
+++ pkg/vegan/inst/ChangeLog	2014-02-10 08:40:49 UTC (rev 2855)
@@ -45,6 +45,13 @@
 	with three points was reported by Paul Bacquet (Louvain,
 	Belgium). 
 
+	* tabasco: "hclust" objects (use, sp.ind) are reordered using
+	weighted means. This is a better method than the unweighted means
+	used for reordering of dendrograms. Earlier "hclust" objects were
+	changed to dendrograms, but now we provide reorder.hclust() and
+	rev.hclust() in vegan, and can use improved method of ordering the
+	table.
+
 	* treedive, treedist: default is now match.force = TRUE, and
 	treedive() gained new argument 'verbose' to turn of most messages
 	-- which is practical in oecosimu().

Modified: pkg/vegan/man/vegemite.Rd
===================================================================
--- pkg/vegan/man/vegemite.Rd	2014-02-09 07:41:46 UTC (rev 2854)
+++ pkg/vegan/man/vegemite.Rd	2014-02-10 08:40:49 UTC (rev 2855)
@@ -81,10 +81,14 @@
   also for species).  When \code{use} is an object from
   \code{\link{hclust}}, \code{\link[cluster]{agnes}} or a
   \code{\link{dendrogram}}, the sites are ordered similarly as in the
-  cluster dendrogram.  Function \code{tabasco} re-orders the
-  dendrogram if \code{Rowv = TRUE} or \code{Rowv} is a vector. Such
-  re-ordering is not available for \code{vegemite}, but it can be done
-  by hand using \code{\link{reorder.dendrogram}}.  In all cases where
+  cluster dendrogram.  Function \code{tabasco} re-orders the dendrogram
+  if \code{Rowv = TRUE} or \code{Rowv} is a vector. Such re-ordering is
+  not available for \code{vegemite}, but it can be done by hand using
+  \code{\link{reorder.dendrogram}} or \code{\link{reorder.hclust}}.
+  Please note that \code{\link{dendrogram}} and \code{\link{hclust}}
+  reordering can differ: unweighted means of merged branches are used in
+  \code{\link{dendrogram}}, but weighted means (= means of leaves of the
+  cluster) are used in \code{\link{reorder.hclust}}.  In all cases where
   species scores are missing, species are ordered by their weighted
   averages (\code{\link{wascores}}) on site order.
 



More information about the Vegan-commits mailing list