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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jan 10 18:53:15 CET 2013


Author: jarioksa
Date: 2013-01-10 18:53:14 +0100 (Thu, 10 Jan 2013)
New Revision: 2360

Modified:
   pkg/vegan/R/stressplot.wcmdscale.R
   pkg/vegan/inst/ChangeLog
Log:
use row weights in stressplot of wcmdscale and cca

Modified: pkg/vegan/R/stressplot.wcmdscale.R
===================================================================
--- pkg/vegan/R/stressplot.wcmdscale.R	2013-01-10 13:37:21 UTC (rev 2359)
+++ pkg/vegan/R/stressplot.wcmdscale.R	2013-01-10 17:53:14 UTC (rev 2360)
@@ -4,8 +4,6 @@
 `stressplot.wcmdscale` <-
     function(object, k = 2, pch,  p.col = "blue", l.col = "red", lwd = 2, ...)
 {
-    ## NB: Ignores weights
-
     ## Check that original distances can be reconstructed: this
     ## requires that all axes were calculated instead of 'k' first.
     hasdims <- NCOL(object$points)
@@ -16,11 +14,13 @@
     ## Get the ordination distances in k dimensions
     if (k > NCOL(object$points))
         stop("'k' cannot exceed the number of real dimensions")
-    odis <- dist(object$points[,1:k, drop = FALSE])
+    w <- sqrt(object$weights)
+    u <- diag(w) %*% object$points
+    odis <- dist(u[,1:k, drop = FALSE])
     ## Reconstitute the original observed distances
-    dis <- dist(object$points)
+    dis <- dist(u)
     if (!is.null(object$negaxes))
-        dis <- sqrt(dis^2 - dist(object$negaxes)^2)
+        dis <- sqrt(dis^2 - dist(diag(w) %*% object$negaxes)^2)
     ## additive constant is not implemented in wcmdscale (which
     ## returns 'ac = NA'), but the next statement would take care of
     ## that: we want to have the input distances as observed distances
@@ -71,17 +71,17 @@
 `stressplot.cca` <-
     function(object, k = 2, pch, p.col = "blue", l.col = "red", lwd = 2, ...)
 {
-    ## NB: Ignores row weights!
-    
     ## Not yet done for pCCA
     if (!is.null(object$pCCA))
         stop("not implemented yet for partial CCA")
     ## Normalized scores to reconstruct data
     u <- cbind(object$CCA$u, object$CA$u)
     sev <- sqrt(c(object$CCA$eig, object$CA$eig))
+    w <- sqrt(object$rowsum)
+    u <- diag(w) %*% u %*% diag(sev)
     ## Distances
-    dis <- dist(u %*% diag(sev))
-    odis <- dist(u[,1:k, drop=FALSE] %*% diag(sev[1:k], nrow = k))
+    dis <- dist(u)
+    odis <- dist(u[,1:k, drop = FALSE])
     ##odis <- dist(sweep(Xbar, 2, sqrt(object$colsum), "*"))
     ## plot like above
         ## Plot

Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog	2013-01-10 13:37:21 UTC (rev 2359)
+++ pkg/vegan/inst/ChangeLog	2013-01-10 17:53:14 UTC (rev 2360)
@@ -20,8 +20,8 @@
 	2') against original observed distances.  These original distances
 	are found from the full space solution, and in capscale() and
 	wcmdscale() they are correct for the imaginary axes. The weights
-	are not used in wcmdscale() and cca(): I must first figure out if
-	they should be used or ignored.
+	are used in wcmdscale() and cca() so that their distances differ
+	from plotted ordinations, but agree with eigenvalues.
 
 	* wcmdscale: added method functions print(), plot() and
 	scores(). Now class "wcmdscale" results also retun the function



More information about the Vegan-commits mailing list