[Vegan-commits] r1541 - in pkg/vegan: R inst
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Mar 15 20:35:01 CET 2011
Author: jarioksa
Date: 2011-03-15 20:35:00 +0100 (Tue, 15 Mar 2011)
New Revision: 1541
Modified:
pkg/vegan/R/metaMDSiter.R
pkg/vegan/inst/ChangeLog
Log:
'previous.best' more flexible in metaMDS()
Modified: pkg/vegan/R/metaMDSiter.R
===================================================================
--- pkg/vegan/R/metaMDSiter.R 2011-03-14 08:11:34 UTC (rev 1540)
+++ pkg/vegan/R/metaMDSiter.R 2011-03-15 19:35:00 UTC (rev 1541)
@@ -10,11 +10,38 @@
SOL <- FALSE
converged <- FALSE
isotrace <- max(0, trace - 1)
+ ## Previous best or initial configuration
if (!missing(previous.best) && !is.null(previous.best)) {
- s0 <- previous.best
- if (trace)
- cat("Starting from a previous solution\n")
- }
+ ## check if previous.best is from metaMDS or isoMDS
+ if (inherits(previous.best, "metaMDS") ||
+ is.list(previous.best) &&
+ all(c("points", "stress") %in% names(previous.best))) {
+ ## real "previous best"
+ if (NCOL(previous.best$points) == k) {
+ s0 <- previous.best
+ if (trace)
+ cat("Starting from a previous solution\n")
+ } else {
+ init <- previous.best$points
+ nc <- NCOL(init)
+ if (nc > k)
+ init <- init[, 1:k, drop = FALSE]
+ else # nc < k
+ for (i in 1:(k-nc))
+ init <- cbind(init, runif(NROW(init), -0.1, 0.1))
+ # evaluate isoMDS with stress
+ s0 <- isoMDS(dist, init, k = k, maxit = 0)
+ if (trace)
+ cat(gettextf("Starting from %d-dimensional solution\n", nc))
+ }
+ } else if (is.matrix(previous.best) || is.data.frame(previous.best)) {
+ s0 <- isoMDS(dist, previous.best, k = k, maxit = 0)
+ if (trace)
+ cat("Starting from supplied configuration\n")
+ } else { # an error!
+ stop("'previous.best' of unknown kind")
+ }
+ } # No previous best:
else s0 <- isoMDS(dist, k = k, trace = isotrace)
if (trace)
cat("Run 0 stress", s0$stress, "\n")
@@ -48,10 +75,12 @@
}
flush.console()
}
- if (!missing(previous.best) && !is.null(previous.best$tries))
+ if (!missing(previous.best) && inherits(previous.best, "metaMDS")) {
tries <- tries + previous.best$tries
+ }
out <- list(points = s0$points, dims = k, stress = s0$stress,
- data = attr(dist, "commname"), distance = attr(dist,
- "method"), converged = converged, tries = tries)
+ data = attr(dist, "commname"),
+ distance = attr(dist, "method"), converged = converged,
+ tries = tries)
out
}
Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog 2011-03-14 08:11:34 UTC (rev 1540)
+++ pkg/vegan/inst/ChangeLog 2011-03-15 19:35:00 UTC (rev 1541)
@@ -27,6 +27,13 @@
1..N for first 'vec', then 2..N for the second 'vec', but the
later 'vec's could be correlated with previous axes.
+ * metaMDS: 'previous.best' can now be a user-supplied
+ configuration, or a result of isoMDS(). If 'previous.best' is an
+ isoMDS() or a metaMDS() result, it can have different number of
+ dimensions than the current 'k': extra dimensions are dropped off,
+ or noisy extra dimensions are added as needed. This may help in
+ running metaMDS() with a range of 'k'. Not yet documented.
+
Version 1.18-24 (closed March 10, 2011)
* cca: will return NULL item for CCA only if constraints were not
More information about the Vegan-commits
mailing list