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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Apr 7 17:59:05 CEST 2011


Author: jarioksa
Date: 2011-04-07 17:59:05 +0200 (Thu, 07 Apr 2011)
New Revision: 1576

Modified:
   pkg/vegan/R/stressplot.R
   pkg/vegan/inst/ChangeLog
   pkg/vegan/man/goodness.metaMDS.Rd
Log:
stressplot is generic with a method for monoMDS

Modified: pkg/vegan/R/stressplot.R
===================================================================
--- pkg/vegan/R/stressplot.R	2011-04-06 16:21:47 UTC (rev 1575)
+++ pkg/vegan/R/stressplot.R	2011-04-07 15:59:05 UTC (rev 1576)
@@ -1,4 +1,56 @@
-"stressplot" <-
+`stressplot`<-
+    function(object, ...)
+{
+    UseMethod("stressplot")
+}
+
+`stressplot.monoMDS` <-
+    function(object, pch, p.col = "blue", l.col = "red", lwd = 2, ...)
+{
+    ## extract items to plot
+    x <- object$diss
+    y <- object$dist
+    yf <- object$dhat
+    ## all models plot dist against diss, but there can be duplicated
+    ## items in some models: remove duplicates in hybrid (iregn==3)
+    ## and local (ngrp > 1) models:
+    if (object$iregn == 3)
+        pts <- seq_along(x) < object$istart[2]
+    else if (object$ngrp > 2)
+        pts <- object$iidx > object$jidx
+    else
+        pts <- !logical(length(x))
+    ## Plotting character
+    if (missing(pch))
+        if (sum(pts) > 5000) pch <- "." else pch <- 1
+    ## plot points
+    plot(x[pts], y[pts], pch = pch, col = p.col, xlab = "Observed Dissimilarity",
+         ylab = "Ordination Distance", ...)
+    ## Fit lines: linear (iregn=2) and hybrid (iregn=3) have a smooth line
+    if (object$iregn > 1) {
+        if (object$iregn == 3) { 
+            yl <- range(yf[seq(object$istart[2], object$ndis)])
+            xl <- range(x[seq(object$istart[2], object$ndis)])
+        } else {
+            yl <- range(yf)
+            xl <- range(x)
+        }
+        lines(xl, yl, col = l.col, lwd = lwd, ...)
+    }
+    ## Monotone line except in linear, and local has several...
+    if (object$iregn != 2) {
+        ist <- c(object$istart, object$ndis - 1)
+        if (object$iregn == 3)
+            object$ngrp <- 1
+        for(j in 1:object$ngrp) {
+            k <- seq(ist[j], ist[j+1]-1)
+            lines(x[k], yf[k], type = "S", col = l.col, lwd = lwd, ...)
+        }
+    }
+    invisible(list("x" = x, "y" = y, "yf" = yf))
+}
+    
+`stressplot.default` <-
     function(object, dis, pch, p.col = "blue", l.col = "red", lwd = 2, ...)
 {
     require(MASS) || stop("Needs MASS package")
@@ -14,7 +66,7 @@
     if ( abs(stress - object$stress) > 0.001)
         stop("Dissimilarities and ordination do not match")
     if (missing(pch))
-        if (length(dis) > 5000) pch = "." else pch = 1
+        if (length(dis) > 5000) pch <- "." else pch <- 1
     plot(shep, pch = pch, col = p.col, xlab = "Observed Dissimilarity",
          ylab = "Ordination Distance", ...)
     lines(shep$x, shep$yf, type = "S", col = l.col, lwd = lwd, ...)

Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog	2011-04-06 16:21:47 UTC (rev 1575)
+++ pkg/vegan/inst/ChangeLog	2011-04-07 15:59:05 UTC (rev 1576)
@@ -20,9 +20,11 @@
 
 	* metaMDS: uses monoMDS() as its default engine (and gained
 	argument 'engine' to select either monoMDS() or isoMDS()). Not all
-	functions work with the new engine, yet (stressplot, goodness fail
-	at least).
+	functions work with the new engine, yet (goodness fails at least).
 
+	* stressplot: is generic with a specific method for "monoMDS"
+	objects, and the old function as the default method.
+
 	* metaMDSrotate: gained argument 'na.rm' (defaults FALSE) to
 	remove missing data from the continuous vector.
 	

Modified: pkg/vegan/man/goodness.metaMDS.Rd
===================================================================
--- pkg/vegan/man/goodness.metaMDS.Rd	2011-04-06 16:21:47 UTC (rev 1575)
+++ pkg/vegan/man/goodness.metaMDS.Rd	2011-04-07 15:59:05 UTC (rev 1576)
@@ -1,6 +1,8 @@
 \name{goodness.metaMDS}
 \alias{goodness.metaMDS}
 \alias{stressplot}
+\alias{stressplot.default}
+\alias{stressplot.monoMDS}
 
 \title{Goodness of Fit and Shepard Plot for Nonmetric Multidimensional Scaling }
 \description{
@@ -15,10 +17,10 @@
 }
 %- maybe also 'usage' for other objects documented here.
 \arguments{
-  \item{object}{A result object from \code{\link{metaMDS}} or
-    \code{\link[MASS]{isoMDS}}. }
-  \item{dis}{Dissimilarities.  Normally this should  not used with
-    \code{\link{metaMDS}}, but should be always used with
+  \item{object}{A result object from \code{\link{metaMDS}}, 
+    \code{\link{monoMDS}} or \code{\link[MASS]{isoMDS}}. }
+  \item{dis}{Dissimilarities.  Rhis should  not used with
+    \code{\link{metaMDS}} or \code{\link{monoMDS}}, but must be used with
     \code{\link[MASS]{isoMDS}}.}
   \item{pch}{Plotting character for points.  Default is dependent on the
     number of points. }
@@ -31,34 +33,36 @@
   observations (points).  This is defined so that sum of squared values
   is equal to squared stress.  Large values indicate poor fit.
 
-  Function \code{stressplot} is a wrapper to \code{\link[MASS]{Shepard}}
-  function in \pkg{MASS} package.  It plots ordination distances
-  against original dissimilarities, and draws a step line of the
-  nonlinear fit.  In addition, it adds to the graph two correlation-like
-  statistics on the goodness of fit.  The nonmetric fit is based on stress \eqn{S} and
-  defined as \eqn{\sqrt{1-S^2}}{sqrt(1-S^2)}.  The \dQuote{linear fit}
-  is the correlation between fitted values and ordination distances.
+  Function \code{stressplot} is draws a Sheaprd diagram which is a
+  plot of ordination distances and monotone or linear fit line against
+  original dissimilarities.  In addition, it adds to the graph two
+  correlation-like statistics on the goodness of fit.  The nonmetric
+  fit is based on stress \eqn{S} and defined as
+  \eqn{\sqrt{1-S^2}}{sqrt(1-S^2)}.  The \dQuote{linear fit} is the
+  correlation between fitted values and ordination distances.
 
-  Both functions can be used both with \code{\link{metaMDS}} and with
-  \code{\link[MASS]{isoMDS}}.  With \code{\link{metaMDS}}, the functions
-  try to reconstruct the dissimilarities using
-  \code{\link{metaMDSredist}}, and dissimilarities should not be given.
-  With  \code{\link[MASS]{isoMDS}} the dissimilarities must be given.
-  In either case, the functions inspect that dissimilarities are
-  consistent with current ordination, and refuse to analyse inconsistent
-  dissimilarities.  Function \code{goodness.metaMDS} is generic in
-  \code{vegan}, but you must spell its name completely with
-  \code{\link[MASS]{isoMDS}} which has no class.
-}
-\value{
-  Function \code{goodness} returns a vector of values. Function
-  \code{stressplot} returns invisibly a \code{\link[MASS]{Shepard}}
-  object. 
-}
+  Both functions can be used both with \code{\link{metaMDS}},
+  \code{\link{monoMDS}} and \code{\link[MASS]{isoMDS}}.  The original
+  dissimilarities should not be given for \code{\link{monoMDS}} or
+  \code{\link{metaMDS}} results (the latter tries to reconstruct the
+  dissimilarities using \code{\link{metaMDSredist}} if
+  \code{\link[MASS]{isoMDS}} was used as its engine).  With
+  \code{\link[MASS]{isoMDS}} the dissimilarities must be given.  In
+  either case, the functions inspect that dissimilarities are
+  consistent with current ordination, and refuse to analyse
+  inconsistent dissimilarities.  Function \code{goodness.metaMDS} is
+  generic in \code{vegan}, but you must spell its name completely with
+  \code{\link[MASS]{isoMDS}} which has no class.  } 
+
+\value{ Function \code{goodness} returns a vector of values. Function
+  \code{stressplot} returns invisibly an object with itmes for
+  original dissimilarities, ordination distances and fitted values.  }
+
 \author{Jari Oksanen. }
 
-\seealso{\code{\link{metaMDS}},  \code{\link[MASS]{isoMDS}},
-  \code{\link[MASS]{Shepard}}. }
+\seealso{\code{\link{metaMDS}},  \code{\link{monoMDS}}, 
+  \code{\link[MASS]{isoMDS}}, \code{\link[MASS]{Shepard}}. }
+
 \examples{
 data(varespec)
 mod <- metaMDS(varespec, engine = "isoMDS")



More information about the Vegan-commits mailing list