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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun May 5 19:07:39 CEST 2013


Author: jarioksa
Date: 2013-05-05 19:07:39 +0200 (Sun, 05 May 2013)
New Revision: 2500

Modified:
   pkg/vegan/R/rankindex.R
   pkg/vegan/inst/ChangeLog
   pkg/vegan/man/rankindex.Rd
Log:
rankindex gained Mahalanobis and Manhattan metrics for gradients

Modified: pkg/vegan/R/rankindex.R
===================================================================
--- pkg/vegan/R/rankindex.R	2013-05-05 15:58:34 UTC (rev 2499)
+++ pkg/vegan/R/rankindex.R	2013-05-05 17:07:39 UTC (rev 2500)
@@ -1,14 +1,22 @@
 "rankindex" <-
 function (grad, veg, indices = c("euc", "man", "gow", "bra", 
-    "kul"), stepacross = FALSE, method = "spearman", ...) 
+    "kul"), stepacross = FALSE, method = "spearman",
+     metric = c("euclidean", "mahalanobis", "manhattan", "gower"), ...) 
 {
+    metric = match.arg(metric)
+    if (metric == "gower")
+        require(cluster) || stop("metric = 'gower' needs package 'cluster'")
     grad <- as.data.frame(grad)
     if (any(sapply(grad, is.factor))) {
         require(cluster) || stop("factors in 'grad' need package 'cluster'")
         message("'grad' included factors: used cluster:::daisy")
         span <- daisy(grad)
     } else {
-        span <- vegdist(grad, "eucl")
+        span <- switch(metric,
+                       "euclidean" = dist(scale(grad, scale=TRUE)),
+                       "mahalanobis" = dist(veganMahatrans(scale(grad, scale=FALSE))),
+                       "manhattan" = dist(decostand(grad, "range"), "manhattan"),
+                       "gower" = daisy(grad, metric = "gower"))
     }
     veg <- as.matrix(veg)
     res <- numeric(length(indices))

Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog	2013-05-05 15:58:34 UTC (rev 2499)
+++ pkg/vegan/inst/ChangeLog	2013-05-05 17:07:39 UTC (rev 2500)
@@ -17,6 +17,11 @@
 	is changed to show the 'metric' and the name of the 'method' is
 	fully expanded. No more fails if 'upto' is too large.
 
+	* rankindex: can now use Mahalanobis or Manhattan
+	distances. Scales automatically gradient variables to unit
+	variance (Euclidean) or range (Manhattan), and the scaling is
+	already inbuilt in Mahalanobis and Gower.
+
 Version 2.1-29 (closed April 19, 2013)
 
 	* ordisurf: significant changes were made to this function:

Modified: pkg/vegan/man/rankindex.Rd
===================================================================
--- pkg/vegan/man/rankindex.Rd	2013-05-05 15:58:34 UTC (rev 2499)
+++ pkg/vegan/man/rankindex.Rd	2013-05-05 17:07:39 UTC (rev 2500)
@@ -8,7 +8,9 @@
 }
 \usage{
 rankindex(grad, veg, indices = c("euc", "man", "gow", "bra", "kul"),
-          stepacross = FALSE, method = "spearman", ...)
+          stepacross = FALSE, method = "spearman", 
+	  metric = c("euclidean", "mahalanobis", "manhattan", "gower"),
+	  ...)
 }
 
 \arguments{
@@ -23,18 +25,24 @@
     with no shared species are set \code{NA} using
     \code{\link{no.shared}} so that indices with no fixed
     upper limit can also be analysed.}
-  \item{method}{Correlation method used. }
+  \item{method}{Correlation method used.}
+  \item{metric}{Metric to evaluate the gradient separation. See Details.}
   \item{...}{Other parameters to \code{\link{stepacross}}.}
 }
 \details{
-  A good dissimilarity index for multidimensional scaling 
-  should have a high rank-order similarity with gradient separation.
-  The function compares most indices in \code{\link{vegdist}} against
-  gradient separation using rank correlation coefficients in
-  \code{\link{cor.test}}. The gradient separation between each
-  point is assessed as Euclidean distance for continuous variables, and
-  as Gower metric for mixed data using function
-  \code{\link[cluster]{daisy}} when \code{grad} has factors.
+  A good dissimilarity index for multidimensional scaling should have
+  a high rank-order similarity with gradient separation.  The function
+  compares most indices in \code{\link{vegdist}} against gradient
+  separation using rank correlation coefficients in
+  \code{\link{cor}}. The gradient separation between each point is
+  assessed using given \code{metric}. The default is to use Euclidean
+  distance of continuous variables scaled to unit variance, or to use
+  Gower metric for mixed data using function
+  \code{\link[cluster]{daisy}} when \code{grad} has factors. The other
+  alternatives are Mahalanabis distances which are based on
+  \code{grad} matrix scaled so that columns are orthogonal
+  (uncorrelated) and have unit variance, or Manhattan distances of
+  \code{grad} variables scaled to unit range.
 
   The \code{indices} argument can accept any dissimilarity 
   indices besides the ones calculated by the 
@@ -85,10 +93,9 @@
 \examples{
 data(varespec)
 data(varechem)
-## The next scales all environmental variables to unit variance.
-## Some would use PCA transformation.
-rankindex(scale(varechem), varespec)
-rankindex(scale(varechem), wisconsin(varespec))
+## The variables are automatically scaled
+rankindex(varechem, varespec)
+rankindex(varechem, wisconsin(varespec))
 ## Using non vegdist indices as functions
 funs <- list(Manhattan=function(x) dist(x, "manhattan"),
     Gower=function(x) cluster:::daisy(x, "gower"),



More information about the Vegan-commits mailing list