[Vegan-commits] r870 - in branches/1.15: R inst man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Jun 12 12:39:07 CEST 2009


Author: jarioksa
Date: 2009-06-12 12:39:07 +0200 (Fri, 12 Jun 2009)
New Revision: 870

Modified:
   branches/1.15/R/capscale.R
   branches/1.15/R/print.cca.R
   branches/1.15/inst/NEWS
   branches/1.15/man/capscale.Rd
   branches/1.15/man/cca.object.Rd
Log:
merged 866-868 to branches/1.15: changed the way capscale displays negative inertia, fixes scaling of 0..1 range indices

Modified: branches/1.15/R/capscale.R
===================================================================
--- branches/1.15/R/capscale.R	2009-06-12 05:54:04 UTC (rev 869)
+++ branches/1.15/R/capscale.R	2009-06-12 10:39:07 UTC (rev 870)
@@ -46,7 +46,7 @@
         adjust <- 1
     }
     else {
-        adjust <- k
+        adjust <- sqrt(k)
     }
     nm <- attr(X, "Labels")
     ## cmdscale is only used if 'add = TRUE': it cannot properly
@@ -60,15 +60,14 @@
     if (is.null(rownames(X$points))) 
         rownames(X$points) <- nm
     X$points <- adjust * X$points
-    X$eig <- adjust * X$eig
-    tot.chi <- sum(X$eig) 
+    if (adjust == 1)
+        X$eig <- X$eig/k
     neig <- min(which(X$eig < 0) - 1, sum(X$eig > EPS))
     sol <- X$points[, 1:neig]
     fla <- update(formula, sol ~ .)
     environment(fla) <- environment()
     d <- ordiParseFormula(fla, data, envdepth = 1)
     sol <- rda.default(d$X, d$Y, d$Z, ...)
-    sol$tot.chi <- tot.chi
     if (!is.null(sol$CCA)) {
         colnames(sol$CCA$u) <- colnames(sol$CCA$biplot) <- names(sol$CCA$eig) <-
             colnames(sol$CCA$wa) <- colnames(sol$CCA$v) <-
@@ -83,8 +82,9 @@
             negax <- X$eig[X$eig < 0]
             names(negax) <- paste("NEG", seq_along(negax), sep="")
             sol$CA$eig <- c(sol$CA$eig, negax)
-            sol$CA$tot.chi <- abs(sum(sol$CA$eig))
-            sol$CA$rank <- length(sol$CA$eig)
+            sol$CA$imaginary.chi <- sum(negax)
+            sol$tot.chi <- sol$tot.chi + sol$CA$imaginary.chi
+            sol$CA$imaginary.rank <- length(negax)
         }
     }
     if (!is.null(comm)) {

Modified: branches/1.15/R/print.cca.R
===================================================================
--- branches/1.15/R/print.cca.R	2009-06-12 05:54:04 UTC (rev 869)
+++ branches/1.15/R/print.cca.R	2009-06-12 10:39:07 UTC (rev 870)
@@ -7,14 +7,15 @@
     }
     writeLines(strwrap(pasteCall(x$call)))
     cat("\n")
-    chi <- rbind(x$tot.chi, x$pCCA$tot.chi, x$CCA$tot.chi, x$CA$tot.chi)
-    rnk <- rbind(NA, x$pCCA$rank, x$CCA$rank, x$CA$rank)
+    chi <- c(x$tot.chi, x$pCCA$tot.chi, x$CCA$tot.chi, x$CA$tot.chi,
+             x$CA$imaginary.chi)
+    rnk <- c(NA, x$pCCA$rank, x$CCA$rank, x$CA$rank, x$CA$imaginary.rank)
     tbl <- cbind(chi, rnk)
-    tbl <- cbind(chi, rnk)
     colnames(tbl) <- c("Inertia", "Rank")
-    rn <- c("Total", "Conditional", "Constrained", "Unconstrained")
+    rn <- c("Total", "Conditional", "Constrained", "Unconstrained",
+            "Imaginary")
     rownames(tbl) <- rn[c(TRUE, !is.null(x$pCCA), !is.null(x$CCA), 
-                          !is.null(x$CA))]
+                          !is.null(x$CA), !is.null(x$CA$imaginary.chi))]
     printCoefmat(tbl, digits = digits, na.print = "")
     cat("Inertia is", x$inertia, "\n")
     if (!is.null(x$CCA$alias))

Modified: branches/1.15/inst/NEWS
===================================================================
--- branches/1.15/inst/NEWS	2009-06-12 05:54:04 UTC (rev 869)
+++ branches/1.15/inst/NEWS	2009-06-12 10:39:07 UTC (rev 870)
@@ -14,14 +14,19 @@
     - anova.cca: name clash if data were indexed with 'i'.
 
     - capscale: fixed handling of negative eigenvalues with
-      non-Euclidean distances. The negative eigenvalues are subtracted
-      from the total and unconstrained inertia, and the rank of the
-      unconstrained component is the number of all non-zero
-      eigenvalues, including negative ones. The procedure is based on
-      Gower, Linear Algebra and its Applications 67, 81-97 (1985).
-      New argument 'sqrt.dist' takes square root of the internally
-      calculated dissimilarities which avoids negative eigenvalues
-      with some indices, such as vegan Jaccard and Bray-Curtis.
+      non-Euclidean distances. The total inertia is the sum of all
+      eigenvalues so that negative eigenvalues are subtracted from the
+      total. The total inertia of negative components and their rank
+      (number) is given as 'Imaginary' component, and the negative
+      eigenvalues are listed after unconstrained positive eigenvalues.
+      The procedure is based on Gower, Linear Algebra and its
+      Applications 67, 81-97 (1985).  New argument 'sqrt.dist' takes
+      square root of the internally calculated dissimilarities and
+      avoids negative eigenvalues with some indices, such as vegan
+      Jaccard and Bray-Curtis. The adjustment is corrected for indices
+      with upper limit of one, and the reported eigenvalues and
+      inertia components are reduced by a factor of sqrt(n-1) and are
+      similar to those reported by 'cmdscale' or 'wcmdscale'.
 
     - eigenvals: a new function to extract eigenvalues from rda, cca,
       capscale, wcmdscale, prcomp, princomp, svd or eigen. If the

Modified: branches/1.15/man/capscale.Rd
===================================================================
--- branches/1.15/man/capscale.Rd	2009-06-12 05:54:04 UTC (rev 869)
+++ branches/1.15/man/capscale.Rd	2009-06-12 10:39:07 UTC (rev 870)
@@ -157,17 +157,17 @@
 \author{ Jari Oksanen }
 
 \note{ The function produces negative eigenvalues with many
-  dissimilarity indices. The negative eigenvalues are listed after
-  positive unconstrained eigenvalues with prefix \code{NEG}.
-  The total inertia and total unconstrained inertia are sums of all
-  eigenvalues, including negative ones, and the rank is the number of 
-  all nonzero eigenvalues (Gower 1985). No ordination scores are given
-  for negative eigenvalues.  If the negative eigenvalues are
-  disturbing, you can use argument \code{add = TRUE} passed to
-  \code{\link{cmdscale}}, or, preferably, a distance measure that does
-  not cause these warnings.  Alternatively, after square root
-  transformation of distances (argument \code{sqrt.dist = TRUE}) many
-  indices do not produce negative eigenvalues.
+  dissimilarity indices. The non-Euclidean component of inertia is
+  given under the title \code{Imaginary}, and the negative eigenvalues
+  are listed after unconstrained eigenvalues with prefix \code{NEG}.
+  The total inertia is the sum of all eigenvalues, including negative
+  ones (Gower 1985). No ordination scores are given for negative
+  eigenvalues.  If the negative eigenvalues are disturbing, you can
+  use argument \code{add = TRUE} passed to \code{\link{cmdscale}}, or,
+  preferably, a distance measure that does not cause these warnings.
+  Alternatively, after square root transformation of distances
+  (argument \code{sqrt.dist = TRUE}) many indices do not produce
+  negative eigenvalues.
 
   The inertia is named after the dissimilarity index as defined in the
   dissimilarity data, or as \code{unknown distance} if such an

Modified: branches/1.15/man/cca.object.Rd
===================================================================
--- branches/1.15/man/cca.object.Rd	2009-06-12 05:54:04 UTC (rev 869)
+++ branches/1.15/man/cca.object.Rd	2009-06-12 10:39:07 UTC (rev 870)
@@ -76,6 +76,10 @@
      \code{CCA} components. Only in \code{CCA}.}
     \item{\code{tot.chi}}{Total inertia or the sum of all eigenvalues of the
       component.}
+    \item{\code{imaginary.chi}, \code{imaginary.rank}}{The sum and
+     rank (number) of negative eigenvalues in
+     \code{\link{capscale}}. Only in \code{CA} and only if negative
+     eigenvalues were found in \code{\link{capscale}}.}
     \item{\code{u}}{(Weighted) orthonormal site scores.  Please note that
       scaled scores are not stored in the \code{cca} object, but they
       are made when the object is accessed with functions like



More information about the Vegan-commits mailing list