[Vegan-commits] r1571 - in pkg/vegan: R inst man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Apr 5 19:52:26 CEST 2011
Author: jarioksa
Date: 2011-04-05 19:52:26 +0200 (Tue, 05 Apr 2011)
New Revision: 1571
Modified:
pkg/vegan/R/metaMDSiter.R
pkg/vegan/R/print.metaMDS.R
pkg/vegan/inst/ChangeLog
pkg/vegan/man/goodness.metaMDS.Rd
pkg/vegan/man/metaMDS.Rd
Log:
metaMDS uses monoMDS as its default engine
Modified: pkg/vegan/R/metaMDSiter.R
===================================================================
--- pkg/vegan/R/metaMDSiter.R 2011-04-04 14:03:52 UTC (rev 1570)
+++ pkg/vegan/R/metaMDSiter.R 2011-04-05 17:52:26 UTC (rev 1571)
@@ -1,10 +1,13 @@
`metaMDSiter` <-
function (dist, k = 2, trymax = 20, trace = 1, plot = FALSE,
- previous.best, ...)
+ previous.best, engine = "monoMDS", ...)
{
- if (!require(MASS))
- stop("Needs package MASS (function isoMDS): not found")
+ engine <- match.arg(engine, c("monoMDS", "isoMDS"))
+ if (engine == "isoMDS")
+ require(MASS) || stop("Needs package MASS (function isoMDS)")
EPS <- 0.05
+ if (engine == "monoMDS")
+ EPS <- EPS/100 # monoMDS stress (0,1), isoMDS (0,100)
RESLIM <- 0.01
RMSELIM <- 0.005
SOL <- FALSE
@@ -30,7 +33,10 @@
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)
+ s0 <- switch(engine,
+ "monoMDS" = monoMDS(dist, init, k = k, maxit = 0,
+ ...),
+ "isoMDS" = isoMDS(dist, init, k = k, maxit = 0))
# zero 'tries': this was a new start
if (inherits(previous.best, "metaMDS"))
previous.best$tries <- 0
@@ -38,21 +44,29 @@
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)
+ s0 <- switch(engine,
+ "monoMDS" = monoMDS(dist, previous.best, k=k, maxit = 0),
+ "isoMDS" = 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)
+ else
+ s0 <- switch(engine,
+ "monoMDS" = monoMDS(dist, k = k, ...),
+ "isoMDS" = isoMDS(dist, k = k, trace = isotrace))
if (trace)
cat("Run 0 stress", s0$stress, "\n")
tries <- 0
while(tries < trymax) {
tries <- tries + 1
- stry <- isoMDS(dist, initMDS(dist, k = k), k = k, maxit = 200,
- tol = 1e-07, trace = isotrace)
+ stry <- switch(engine,
+ "monoMDS" = monoMDS(dist, k = k, maxit = 200, ...),
+ "isoMDS" = isoMDS(dist, initMDS(dist, k = k), k = k,
+ maxit = 200, tol = 1e-07, trace = isotrace))
if (trace) {
cat("Run", tries, "stress", stry$stress, "\n")
}
@@ -84,6 +98,6 @@
out <- list(points = s0$points, dims = k, stress = s0$stress,
data = attr(dist, "commname"),
distance = attr(dist, "method"), converged = converged,
- tries = tries)
+ tries = tries, engine = engine)
out
}
Modified: pkg/vegan/R/print.metaMDS.R
===================================================================
--- pkg/vegan/R/print.metaMDS.R 2011-04-04 14:03:52 UTC (rev 1570)
+++ pkg/vegan/R/print.metaMDS.R 2011-04-05 17:52:26 UTC (rev 1571)
@@ -3,7 +3,11 @@
{
cat("\nCall:\n")
cat(deparse(x$call), "\n\n")
- cat("Nonmetric Multidimensional Scaling using isoMDS (MASS package)\n\n")
+ cat("Nonmetric Multidimensional Scaling using ")
+ if (x$engine == "monoMDS")
+ cat("monoMDS\n\n")
+ else if (x$engine == "isoMDS")
+ cat("isoMDS (MASS package)\n\n")
cat("Data: ", x$data, "\n")
cat("Distance:", x$distance, "\n\n")
cat("Dimensions:", x$dims, "\n")
Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog 2011-04-04 14:03:52 UTC (rev 1570)
+++ pkg/vegan/inst/ChangeLog 2011-04-05 17:52:26 UTC (rev 1571)
@@ -18,6 +18,11 @@
replace isoMDS() of the MASS package as the main NMDS engine in
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 (stressplot, goodness fail
+ at least).
+
* 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-04 14:03:52 UTC (rev 1570)
+++ pkg/vegan/man/goodness.metaMDS.Rd 2011-04-05 17:52:26 UTC (rev 1571)
@@ -61,7 +61,7 @@
\code{\link[MASS]{Shepard}}. }
\examples{
data(varespec)
-mod <- metaMDS(varespec)
+mod <- metaMDS(varespec, engine = "isoMDS")
stressplot(mod)
gof <- goodness(mod)
gof
Modified: pkg/vegan/man/metaMDS.Rd
===================================================================
--- pkg/vegan/man/metaMDS.Rd 2011-04-04 14:03:52 UTC (rev 1570)
+++ pkg/vegan/man/metaMDS.Rd 2011-04-05 17:52:26 UTC (rev 1571)
@@ -38,7 +38,7 @@
metaMDSdist(comm, distance = "bray", autotransform = TRUE, noshare = 0.1,
trace = 1, commname, zerodist = "fail", distfun = vegdist, ...)
metaMDSiter(dist, k = 2, trymax = 20, trace = 1, plot = FALSE, previous.best,
- ...)
+ engine = "monoMDS", ...)
initMDS(x, k=2)
postMDS(X, dist, pc=TRUE, center=TRUE, halfchange, threshold=0.8,
nthreshold=10, plot=FALSE, ...)
@@ -97,6 +97,10 @@
\code{dist} object and accepting argument \code{method} can be used
(but some extra arguments may cause name conflicts).}
\item{dist}{Dissimilarity matrix used in multidimensional scaling. }
+ \item{engine}{The function used for non-metric MDS. The default is to
+ use the \code{\link{monoMDS}} function in \pkg{vegan}, but for
+ backward compatibility it is also possible to use \code{\link{isoMDS}}
+ of \pkg{MASS}.}
\item{pc}{Rotate to principal components. }
\item{center}{Centre the configuration. }
\item{halfchange}{Scale axes to half-change units. This defaults
@@ -111,14 +115,15 @@
\item{na.rm}{Remove missing values from continuous variable \code{vec}.}
\item{...}{Other parameters passed to functions.}
}
-\details{
- Non-metric Multidimensional Scaling (NMDS) is commonly regarded as the
- most robust unconstrained ordination method in community ecology (Minchin
- 1987). Functions \code{initMDS} and \code{postMDS} together with some
- other functions are intended to
- help run NMDS wit \code{\link[MASS]{isoMDS}} like recommended by
- Minchin (1987). Function \code{metaMDS} combines all recommendations
- into one command for a shotgun style analysis. The complete steps in
+
+\details{ Non-metric Multidimensional Scaling (NMDS) is commonly
+ regarded as the most robust unconstrained ordination method in
+ community ecology (Minchin 1987). Functions \code{initMDS} and
+ \code{postMDS} together with some other functions are intended to
+ help run NMDS with \code{\link{monoMDS}} (or optinally with
+ \code{\link[MASS]{isoMDS}}) like recommended by Minchin (1987).
+ Function \code{metaMDS} combines all recommendations into one
+ command for a shotgun style analysis. The complete steps in
\code{metaMDS} are:
\enumerate{
\item Transformation: If the data values are larger than common
@@ -152,14 +157,14 @@
\item NMDS with random starts: NMDS easily gets trapped into local
optima, and you must start NMDS several times from random start to
- be confident that you have found the global solution. The default in
- \code{\link[MASS]{isoMDS}} is to start from
+ be confident that you have found the global solution. An often-used
+ default is to start from
metric scaling (with \code{\link{cmdscale}}) which typically is
close to a local optimum. The strategy in \code{metaMDS} is to first
- run a default \code{\link[MASS]{isoMDS}}, or use the
+ run NMDS starting with the metric scaling, or use the
\code{previous.best} solution if supplied, and take
its solution as the standard (\code{Run 0}). Then \code{metaMDS}
- starts \code{\link[MASS]{isoMDS}} from several
+ starts NMDS from several
random starts (maximum number is given by \code{trymax}). If a
solution is better (has a lower stress) than the previous standard,
it is taken as the new standard. If the solution is better or close
@@ -238,23 +243,22 @@
\author{ Jari Oksanen }
-\note{
- Function \code{metaMDS} is a simple wrapper for
- \code{\link[MASS]{isoMDS}} and some support functions.
- You can call these support functions separately for better control
- of results. Data transformation, dissimilarities and possible
- \code{\link{stepacross}} are made in function \code{metaMDSdist}
- which returns a dissimilarity result. Iterative search (with starting
- values from \code{initMDS}) is made in \code{metaMDSiter}.
- Processing of result configuration is done in \code{postMDS}, and
- species scores added by \code{\link{wascores}}.
- If you want
- to be more certain of reaching a global solution, you can compare
- results from several independent runs. You can also continue analysis
- from previous results or from your own configuration. Function does
- not save the used dissimilarity matrix, but \code{metaMDSredist}
- tries to reconstruct the used dissimilarities with original data
- transformation and possible \code{\link{stepacross}}.
+\note{ Function \code{metaMDS} is a simple wrapper for an NMDS engine
+ (either \code{\link{monoMDS}} or \code{\link[MASS]{isoMDS}}) and
+ some support functions. You can call these support functions
+ separately for better control of results. Data transformation,
+ dissimilarities and possible \code{\link{stepacross}} are made in
+ function \code{metaMDSdist} which returns a dissimilarity
+ result. Iterative search (with starting values from \code{initMDS})
+ is made in \code{metaMDSiter}. Processing of result configuration
+ is done in \code{postMDS}, and species scores added by
+ \code{\link{wascores}}. If you want to be more certain of reaching
+ a global solution, you can compare results from several independent
+ runs. You can also continue analysis from previous results or from
+ your own configuration. Function may not save the used
+ dissimilarity matrix, but \code{metaMDSredist} tries to reconstruct
+ the used dissimilarities with original data transformation and
+ possible \code{\link{stepacross}}.
The \code{metaMDS} function was designed to be used with community
data. If you have other type of data, you should probably set some
@@ -264,14 +268,19 @@
to \code{FALSE} with a warning.
}
-\section{Warning}{
+\section{Warning}{ \code{metaMDS} used \code{\link[MASS]{isoMDS}} as
+ its NMDS engine till version 1.18-28, when this was replaced with
+ the \code{\link{monoMDS}} function. You can set argument
+ \code{engine} to select the old engine.
+
The calculation of \code{\link{wascores}} for species was changed in
\pkg{vegan} version 1.12-6. They are now based on the community data
transformed similarly as in the ordination. Previously the species
scores always were based on the original data. You can re-establish
the old behaviour with argument \code{old.wa = TRUE}.
}
-\seealso{\code{\link[MASS]{isoMDS}}, \code{\link{decostand}},
+\seealso{\code{\link{monoMDS}} (and \code{\link[MASS]{isoMDS}}),
+ \code{\link{decostand}},
\code{\link{wisconsin}},
\code{\link{vegdist}}, \code{\link{rankindex}}, \code{\link{stepacross}},
\code{\link{procrustes}}, \code{\link{wascores}},
More information about the Vegan-commits
mailing list