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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Apr 9 10:08:08 CEST 2011


Author: jarioksa
Date: 2011-04-09 10:08:07 +0200 (Sat, 09 Apr 2011)
New Revision: 1581

Modified:
   pkg/vegan/R/goodness.metaMDS.R
   pkg/vegan/inst/ChangeLog
   pkg/vegan/man/goodness.metaMDS.Rd
Log:
implement goodness.monoMDS()

Modified: pkg/vegan/R/goodness.metaMDS.R
===================================================================
--- pkg/vegan/R/goodness.metaMDS.R	2011-04-08 09:42:40 UTC (rev 1580)
+++ pkg/vegan/R/goodness.metaMDS.R	2011-04-09 08:08:07 UTC (rev 1581)
@@ -1,6 +1,8 @@
-"goodness.metaMDS" <-
+`goodness.metaMDS` <-
     function(object, dis, ...)
 {
+    if (inherits(object, "monoMDS"))
+        return(NextMethod("goodness", object, ...))
     require(MASS) || stop("Needs MASS package")
     if (missing(dis))
         dis <- metaMDSredist(object)
@@ -19,3 +21,43 @@
     sqrt(colSums(as.matrix(res))/2*10000)
 }
 
+`goodness.monoMDS` <-
+    function(object, ...)
+{
+    ## Return vector 'x' for which sum(x^2) == stress
+    stresscomp <- function(y, yf, form)
+    {
+        num <- (y-yf)^2
+        if (form == 1)
+            den <- sum(y^2)
+        else
+            den <- sum((y-mean(y))^2)
+        num/den
+    }
+    ## Global, local
+    if (object$model %in% c("global", "linear")) {
+        x <- stresscomp(object$dist, object$dhat, object$isform)
+        mat <- matrix(0, object$nobj, object$nobj)
+        for (i in 1:object$ndis)
+            mat[object$iidx[i], object$jidx[i]] <- x[i]
+        res <- sqrt(colSums(mat + t(mat))/2)
+    }
+    ## Local: returns pointwise components of stress
+    else if (object$model == "local") {
+        res <- object$grstress/sqrt(object$ngrp)
+    } else if (object$model == "hybrid" && object$ngrp == 2) {
+        mat <- matrix(0, object$nobj, object$nobj)
+        gr <- seq_len(object$ndis) < object$istart[2]
+        x <- stresscomp(object$dist[gr], object$dhat[gr], object$isform)
+        x <- c(x, stresscomp(object$dist[!gr], object$dhat[!gr], object$isform))
+        i <- object$iidx
+        j <- object$jidx
+        for (k in 1:object$ndis) {
+            mat[i[k], j[k]] <- mat[i[k], j[k]] + x[k]
+        }
+        res <- sqrt(colSums(mat + t(mat))/4)
+    } else {
+        stop("unknown 'monoMDS' model")
+    }
+    res
+}

Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog	2011-04-08 09:42:40 UTC (rev 1580)
+++ pkg/vegan/inst/ChangeLog	2011-04-09 08:08:07 UTC (rev 1581)
@@ -19,12 +19,15 @@
 	metaMDS().
 
 	* 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 (goodness fails at least).
+	argument 'engine' to select either monoMDS() or isoMDS()).
 
 	* stressplot: is generic with a specific method for "monoMDS"
 	objects, and the old function as the default method.
 
+	* goodness: got a new method for "monoMDS" objects. The function
+	handles all monoMDS() models, but does not take into account
+	possible missing values in input dissimilarities.
+
 	* 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-08 09:42:40 UTC (rev 1580)
+++ pkg/vegan/man/goodness.metaMDS.Rd	2011-04-09 08:08:07 UTC (rev 1581)
@@ -1,5 +1,6 @@
 \name{goodness.metaMDS}
 \alias{goodness.metaMDS}
+\alias{goodness.monoMDS}
 \alias{stressplot}
 \alias{stressplot.default}
 \alias{stressplot.monoMDS}
@@ -31,7 +32,7 @@
 \details{
   Function \code{goodness.metaMDS} finds a goodness of fit statistic for
   observations (points).  This is defined so that sum of squared values
-  is equal to squared stress.  Large values indicate poor fit.
+  is equal to squared stress.  Large values indicate poor fit. 
 
   Function \code{stressplot} is draws a Sheaprd diagram which is a
   plot of ordination distances and monotone or linear fit line against
@@ -65,12 +66,12 @@
 
 \examples{
 data(varespec)
-mod <- metaMDS(varespec, engine = "isoMDS")
+mod <- metaMDS(varespec)
 stressplot(mod)
 gof <- goodness(mod)
 gof
 plot(mod, display = "sites", type = "n")
-points(mod, display = "sites", cex = gof/2)
+points(mod, display = "sites", cex = 2*gof/mean(gof))
 }
 \keyword{ multivariate }
 



More information about the Vegan-commits mailing list