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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Mar 29 16:05:38 CEST 2009


Author: jarioksa
Date: 2009-03-29 16:05:37 +0200 (Sun, 29 Mar 2009)
New Revision: 765

Modified:
   pkg/vegan/R/metaMDS.R
   pkg/vegan/R/postMDS.R
   pkg/vegan/inst/ChangeLog
   pkg/vegan/man/metaMDS.Rd
Log:
improved heuristics for triggering halfchange scaling, with an option to override the heuristics in metaMDS

Modified: pkg/vegan/R/metaMDS.R
===================================================================
--- pkg/vegan/R/metaMDS.R	2009-03-29 07:02:24 UTC (rev 764)
+++ pkg/vegan/R/metaMDS.R	2009-03-29 14:05:37 UTC (rev 765)
@@ -13,11 +13,7 @@
         previous.best <- NULL
     out <- metaMDSiter(dis, k = k, trymax = trymax, trace = trace, 
                        plot = plot, previous.best = previous.best, ...)
-    maxdis <- attr(dis, "maxdis")
-    if (is.null(maxdis)) 
-        maxdis <- abs(max(dis) - 1) < 1e-4
-    points <- postMDS(out$points, dis, plot = max(0, plot - 1), 
-                      halfchange = maxdis, ...)
+    points <- postMDS(out$points, dis, plot = max(0, plot - 1), ...)
     if (is.null(rownames(points))) 
         rownames(points) <- rownames(comm)
     if (wascores) {

Modified: pkg/vegan/R/postMDS.R
===================================================================
--- pkg/vegan/R/postMDS.R	2009-03-29 07:02:24 UTC (rev 764)
+++ pkg/vegan/R/postMDS.R	2009-03-29 14:05:37 UTC (rev 765)
@@ -1,5 +1,5 @@
 "postMDS" <-
-    function (X, dist, pc = TRUE, center = TRUE, halfchange = TRUE, 
+    function (X, dist, pc = TRUE, center = TRUE, halfchange, 
               threshold = 0.8, nthreshold = 10, plot = FALSE, ...) 
 {
     Size <- attributes(dist)$Size
@@ -13,6 +13,16 @@
         x <- prcomp(x, center = center)$x
         dimnames(x) <- dn
     }
+    ## Check halfchange scaling, if not explicitly defined
+    if (missing(halfchange)) {
+        maxdis <- attr(dist, "maxdis")
+        ## play safe: if 'maxdis' is missing or FALSE, skip halfchange
+        ## scaling ('maxdis' is set in metaMDSdist).
+        if (!is.null(maxdis) && maxdis)
+            halfchange <- TRUE
+        else
+            halfchange <- FALSE
+    }
     if (halfchange) {
         dist <- as.vector(dist)
         ordi <- as.vector(vegdist(x, "euclidean"))
@@ -27,7 +37,8 @@
             hc <- (1 - k[1])/2/k[2]
             x <- x/hc
         }
-    } else {
+    }
+    if (!halfchange) {
         scl <- max(dist)/max(vegdist(x, "euclidean"))
         x <- x*scl
     }

Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog	2009-03-29 07:02:24 UTC (rev 764)
+++ pkg/vegan/inst/ChangeLog	2009-03-29 14:05:37 UTC (rev 765)
@@ -4,13 +4,17 @@
 
 Version 1.16-16 (openen Mar 25, 2009)
 
-	* metaMDS: scale ordination scores to the same range as
-	input dissimilarities if halfchange = FALSE (not yet documented,
-	still experimental). Better heuristics to decide whether to use
-	halfchange scaling: the old heuristics failed if Euclidean or
-	other open-ended dissimilarities were small (max < 1), like after
-	wisconsin() in metaMDSdist. This changes an undocumented internal
-	'maxdis' argument to logical in metaMDSdist.
+	* metaMDS: scales ordination scores to the same range as input
+	dissimilarities if halfchange = FALSE. Better heuristics to decide
+	whether to use halfchange scaling: the old heuristics failed if
+	Euclidean or other open-ended dissimilarities were small (max <
+	1), like after wisconsin() in metaMDSdist.  The heuristics are now
+	in postMDS instead of metaMDS wrapper, and this changed the
+	default of internal argument 'halfchage' in postMDS, and now the
+	user can set the 'halfchange' argument in metaMDS. The
+	undocumented internal 'maxdis' argument is changed to logical in
+	metaMDSdist (TRUE if maximum dissimilarity = 1 for a pair of sites
+	with nothin shared).
 
 	* mrpp: reports now "classification strength" when weight.type = 3
 	or weights n*(n-1) are used. Returns mean dissimilarities and

Modified: pkg/vegan/man/metaMDS.Rd
===================================================================
--- pkg/vegan/man/metaMDS.Rd	2009-03-29 07:02:24 UTC (rev 764)
+++ pkg/vegan/man/metaMDS.Rd	2009-03-29 14:05:37 UTC (rev 765)
@@ -40,7 +40,7 @@
 metaMDSiter(dist, k = 2, trymax = 20, trace = 1, plot = FALSE, previous.best, 
     ...)   
 initMDS(x, k=2)
-postMDS(X, dist, pc=TRUE, center=TRUE, halfchange=TRUE, threshold=0.8,
+postMDS(X, dist, pc=TRUE, center=TRUE, halfchange, threshold=0.8,
         nthreshold=10, plot=FALSE, ...)
 metaMDSredist(object, ...)
 metaMDSrotate(object, vec, choices, ...)
@@ -96,12 +96,16 @@
  \item{dist}{Dissimilarity matrix used in multidimensional scaling. }
   \item{pc}{Rotate to principal components. }
   \item{center}{Centre the configuration. }
-  \item{halfchange}{Scale axes to half-change units.}
-  \item{threshold}{Largest dissimilarity used in half-change scaling. }
-  \item{nthreshold}{ Minimum number of points in half-change scaling. }
-  \item{object}{A result object from \code{metaMDS}.}
-  \item{vec}{A continuous site variable (vector).}
-  \item{...}{Other parameters passed to functions.}
+ \item{halfchange}{Scale axes to half-change units. This defaults
+  \code{TRUE} when dissimilarities were evaluated within
+  \code{metaMDS} and the dissimilarity index has an upper limit of
+  \eqn{1}. If \code{FALSE}, the ordination dissimilarities are scaled
+  to the same range as the input dissimilarities.}
+ \item{threshold}{Largest dissimilarity used in half-change scaling. }
+ \item{nthreshold}{ Minimum number of points in half-change scaling. }
+ \item{object}{A result object from \code{metaMDS}.}
+ \item{vec}{A continuous site variable (vector).}
+ \item{...}{Other parameters passed to functions.}
 }
 \details{
   Non-metric Multidimensional Scaling (NMDS) is commonly regarded as the
@@ -166,29 +170,29 @@
     monitor the final stresses, and \code{plot = TRUE} will display
     Procrustes overlay plots from each comparison.
 
-    \item Scaling of the results: \code{metaMDS} will run \code{postMDS}
-    for the final result. Function \code{postMDS} provides the following
-    ways of ``fixing'' the
-    indeterminacy of scaling and orientation of axes in NMDS:
-    Centring moves the origin to the
-    average of the axes.  Principal components rotate the configuration
-    so that the variance of points is maximized on first
-    dimension (with function \code{metaMDSrotate} you can alternatively 
-    rotate the configuration so that the first axis is parallel to an 
-    environmental variable). 
-    Half-change scaling scales the configuration so that one 
-    unit means halving of community similarity from replicate similarity.
-    Half-change scaling is
-    based on closer dissimilarities where the relation between ordination
-    distance and community dissimilarity is rather linear; the limit is
-    controlled by parameter \code{threshold}.  If there are enough points
-    below this threshold (controlled by the parameter
-    \code{nthreshold}), dissimilarities are regressed on distances.
-    The intercept of this regression is taken as the replicate
-    dissimilarity, and half-change is the distance where similarity
-    halves according to linear regression.  Obviously the method is
-    applicable only for dissimilarity indices scaled to \eqn{0 \ldots 1},
-    such as Kulczynski, Bray-Curtis and Canberra indices.
+    \item Scaling of the results: \code{metaMDS} will run
+    \code{postMDS} for the final result. Function \code{postMDS}
+    provides the following ways of ``fixing'' the indeterminacy of
+    scaling and orientation of axes in NMDS: Centring moves the origin
+    to the average of the axes.  Principal components rotate the
+    configuration so that the variance of points is maximized on first
+    dimension (with function \code{metaMDSrotate} you can
+    alternatively rotate the configuration so that the first axis is
+    parallel to an environmental variable).  Half-change scaling
+    scales the configuration so that one unit means halving of
+    community similarity from replicate similarity.  Half-change
+    scaling is based on closer dissimilarities where the relation
+    between ordination distance and community dissimilarity is rather
+    linear; the limit is controlled by parameter \code{threshold}.  If
+    there are enough points below this threshold (controlled by the
+    parameter \code{nthreshold}), dissimilarities are regressed on
+    distances.  The intercept of this regression is taken as the
+    replicate dissimilarity, and half-change is the distance where
+    similarity halves according to linear regression.  Obviously the
+    method is applicable only for dissimilarity indices scaled to
+    \eqn{0 \ldots 1}, such as Kulczynski, Bray-Curtis and Canberra
+    indices. If half-change scaling is not used, the ordination is
+    scaled to the same range as the original dissimilarities.
 
     \item Species scores: Function adds the species scores to the final
     solution as weighted averages using function



More information about the Vegan-commits mailing list