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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Jun 12 01:10:18 CEST 2009


Author: jarioksa
Date: 2009-06-12 01:10:17 +0200 (Fri, 12 Jun 2009)
New Revision: 866

Modified:
   pkg/vegan/R/capscale.R
   pkg/vegan/R/print.capscale.R
   pkg/vegan/R/print.cca.R
   pkg/vegan/man/capscale.Rd
Log:
capscale: improved handling of negative eigenvalues; should work with open-ended indices, too

Modified: pkg/vegan/R/capscale.R
===================================================================
--- pkg/vegan/R/capscale.R	2009-06-11 16:27:09 UTC (rev 865)
+++ pkg/vegan/R/capscale.R	2009-06-11 23:10:17 UTC (rev 866)
@@ -60,15 +60,16 @@
     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
+    else
+        X$eig <- adjust * X$eig
     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 +84,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: pkg/vegan/R/print.capscale.R
===================================================================
--- pkg/vegan/R/print.capscale.R	2009-06-11 16:27:09 UTC (rev 865)
+++ pkg/vegan/R/print.capscale.R	2009-06-11 23:10:17 UTC (rev 866)
@@ -2,8 +2,6 @@
     function(x, ...)
 {
     NextMethod("print", x, ...)
-    if (any(x$CA$eig < 0))
-        cat("NB. Some eigenvalues are negative\n\n")
     if (!is.null(x$metaMDSdist))
         cat("metaMDSdist transformed data:", x$metaMDSdist, "\n\n") 
 }

Modified: pkg/vegan/R/print.cca.R
===================================================================
--- pkg/vegan/R/print.cca.R	2009-06-11 16:27:09 UTC (rev 865)
+++ pkg/vegan/R/print.cca.R	2009-06-11 23:10:17 UTC (rev 866)
@@ -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: pkg/vegan/man/capscale.Rd
===================================================================
--- pkg/vegan/man/capscale.Rd	2009-06-11 16:27:09 UTC (rev 865)
+++ pkg/vegan/man/capscale.Rd	2009-06-11 23:10:17 UTC (rev 866)
@@ -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



More information about the Vegan-commits mailing list