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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Dec 10 09:44:55 CET 2013


Author: jarioksa
Date: 2013-12-10 09:44:55 +0100 (Tue, 10 Dec 2013)
New Revision: 2814

Modified:
   pkg/vegan/R/ordispider.R
   pkg/vegan/inst/ChangeLog
   pkg/vegan/man/ordihull.Rd
Log:
add choice of spatial medians in ordispider

Modified: pkg/vegan/R/ordispider.R
===================================================================
--- pkg/vegan/R/ordispider.R	2013-12-09 08:09:23 UTC (rev 2813)
+++ pkg/vegan/R/ordispider.R	2013-12-10 08:44:55 UTC (rev 2814)
@@ -1,8 +1,10 @@
 `ordispider` <-
     function (ord, groups, display = "sites", w = weights(ord, display),
+              spiders = c("centroid", "median"),
               show.groups, label = FALSE, ...)
 {
     weights.default <- function(object, ...) NULL
+    spiders <- match.arg(spiders)
     if (inherits(ord, "cca") && missing(groups)) {
         lc <- scores(ord, display = "lc", ...)
         wa <- scores(ord, display = "wa", ...)
@@ -30,6 +32,8 @@
         groups <- groups[take]
         w <- w[take]
     }
+    if (spiders == "median" && sd(w) > sqrt(.Machine$double.eps))
+        warning("weights are ignored with 'median' spiders")
     out <- seq(along = groups)
     inds <- names(table(groups))
     if (label) 
@@ -41,7 +45,10 @@
         if (length(gr) > 1) {
             X <- pts[gr, ]
             W <- w[gr]
-            ave <- apply(X, 2, weighted.mean, w = W)
+            ave <- switch(spiders,
+                          "centroid" = apply(X, 2, weighted.mean, w = W),
+                          "median" = ordimedian(X, rep(1, nrow(X)))
+                          )
             spids[,gr] <- ave
             ordiArgAbsorber(ave[1], ave[2], X[, 1], X[, 2],
                             FUN = segments, ...)

Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog	2013-12-09 08:09:23 UTC (rev 2813)
+++ pkg/vegan/inst/ChangeLog	2013-12-10 08:44:55 UTC (rev 2814)
@@ -30,6 +30,9 @@
 	sure. Also fixed handling of tied values in assessing the P-values
 	in vectorfit.
 
+	* ordispider: can now use spatial medians as centres instead of
+	the default centroids. The kind of centre is defined by new
+	argument 'spiders'.
 
 	* tests for cca/rda/capscale: commented out test that failed with
 	the anova.cca. Known issue was that 'by = "term"' and 'by =

Modified: pkg/vegan/man/ordihull.Rd
===================================================================
--- pkg/vegan/man/ordihull.Rd	2013-12-09 08:09:23 UTC (rev 2813)
+++ pkg/vegan/man/ordihull.Rd	2013-12-10 08:44:55 UTC (rev 2814)
@@ -24,7 +24,8 @@
          draw = c("lines","polygon", "none"), w = weights(ord, display),
          col = NULL, alpha = 127, show.groups, label = FALSE, ...)
 ordispider(ord, groups, display="sites", w = weights(ord, display),
-         show.groups, label = FALSE, ...)
+	 spiders = c("centroid", "median"),  show.groups, 
+         label = FALSE, ...)
 ordicluster(ord, cluster, prune = 0, display = "sites",
          w = weights(ord, display), ...)
 \method{summary}{ordihull}(object, ...)
@@ -80,6 +81,9 @@
     corresponding value found from the Chi-squared distribution with
     2df. }
 
+  \item{spiders}{Are centres or spider bodies calculated either as
+    centroids (averages) or spatial medians.}
+
   \item{cluster}{Result of hierarchic cluster analysis, such as
     \code{\link{hclust}} or \code{\link[cluster]{agnes}}.}
 



More information about the Vegan-commits mailing list