[Vegan-commits] r1768 - in pkg/vegan: . R inst man tests/Examples

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Aug 28 19:15:06 CEST 2011


Author: jarioksa
Date: 2011-08-28 19:15:05 +0200 (Sun, 28 Aug 2011)
New Revision: 1768

Added:
   pkg/vegan/R/MDSrotate.R
   pkg/vegan/R/vegan-deprecated.R
   pkg/vegan/man/MDSrotate.Rd
   pkg/vegan/man/vegan-deprecated.Rd
Removed:
   pkg/vegan/R/metaMDSrotate.R
Modified:
   pkg/vegan/DESCRIPTION
   pkg/vegan/NAMESPACE
   pkg/vegan/inst/ChangeLog
   pkg/vegan/inst/NEWS.Rd
   pkg/vegan/man/metaMDS.Rd
   pkg/vegan/tests/Examples/vegan-Ex.Rout.save
Log:
rename metaMDSrotate to MDSrotate

Modified: pkg/vegan/DESCRIPTION
===================================================================
--- pkg/vegan/DESCRIPTION	2011-08-28 15:47:50 UTC (rev 1767)
+++ pkg/vegan/DESCRIPTION	2011-08-28 17:15:05 UTC (rev 1768)
@@ -1,7 +1,7 @@
 Package: vegan
 Title: Community Ecology Package
-Version: 1.92-1
-Date: August 23, 2011
+Version: 1.92-2
+Date: August 28, 2011
 Author: Jari Oksanen, F. Guillaume Blanchet, Roeland Kindt, Pierre Legendre, 
    Peter R. Minchin, R. B. O'Hara, Gavin L. Simpson, Peter Solymos, 
    M. Henry H. Stevens, Helene Wagner  

Modified: pkg/vegan/NAMESPACE
===================================================================
--- pkg/vegan/NAMESPACE	2011-08-28 15:47:50 UTC (rev 1767)
+++ pkg/vegan/NAMESPACE	2011-08-28 17:15:05 UTC (rev 1768)
@@ -12,7 +12,7 @@
 factorfit, fisherfit, fitspecaccum, goodness, hiersimu, humpfit,
 indpower, inertcomp, initMDS, intersetcor, isomapdist, isomap,
 linestack, mantel, meandist, metaMDSdist, metaMDSiter, metaMDSredist,
-metaMDSrotate, metaMDS, monoMDS, mrpp, msoplot, mso, multipart,
+MDSrotate, metaMDS, monoMDS, mrpp, msoplot, mso, multipart,
 nestedchecker, nesteddisc, nestedn0, nestednodf, nestedtemp, oecosimu,
 ordiR2step, ordiarrows, ordicloud, ordicluster,
 ordiellipse, ordigrid, ordihull, ordilabel, ordiplot3d,
@@ -32,6 +32,8 @@
 export(pasteCall)
 ## export anova.cca for 'BiodiversityR': this should be fixed there
 export(anova.cca)
+## Export as.mcmc for coda
+export(as.mcmc.oecosimu, as.mcmc.permat)
 
 ## export regular functions with dot names
 
@@ -44,10 +46,9 @@
 ## Export panel functions
 export(panel.ordi, panel.ordi3d, prepanel.ordi3d)
 
+## Export .Depracated functions (to be removed later)
+export(metaMDSrotate)
 
-## Export as.mcmc for coda
-export(as.mcmc.oecosimu, as.mcmc.permat)
-
 ## do NOT export the following internal functions
 
 ## export(ade2vegancca, orderingKM, ordiArgAbsorber, ordiArrowMul,

Copied: pkg/vegan/R/MDSrotate.R (from rev 1767, pkg/vegan/R/metaMDSrotate.R)
===================================================================
--- pkg/vegan/R/MDSrotate.R	                        (rev 0)
+++ pkg/vegan/R/MDSrotate.R	2011-08-28 17:15:05 UTC (rev 1768)
@@ -0,0 +1,64 @@
+### Rotates metaMDS or monoMDS result so that axis one is parallel to
+### vector 'x'.
+`MDSrotate` <-
+    function(object, vec, na.rm = FALSE, ...) 
+{
+    workswith <- c("metaMDS", "monoMDS")
+    if (!inherits(object, workswith))
+        stop(gettextf("function works only with the results of: %s",
+                      paste(workswith, collapse = ", ")))
+    x <- object$points
+    if (is.null(object$species))
+        sp <- NA
+    else
+        sp <- object$species
+    N <- NCOL(x)
+    if (N < 2)
+        stop(gettextf("needs at least 2 dimensions"))
+    vec <- drop(vec)
+    if (length(dim(vec)) > 1)
+        stop(gettextf("function works only with univariate 'vec'"))
+    if (!is.numeric(vec))
+        stop(gettextf("'vec' must be numeric"))
+    ## vectorfit finds the direction cosine. We rotate first axis to
+    ## 'vec' which means that we make other axes orthogonal to 'vec'
+    ## one by one
+    if (na.rm)
+        keep <- !is.na(vec)
+    else
+        keep <- !logical(length(vec))
+    ## scores must be orthogonal for the next loop to work
+    if (N > 2) {
+        pc <- prcomp(x[keep,])
+        x <- x %*% pc$rotation
+        if (!all(is.na(sp)))
+            sp <- sp %*% pc$rotation
+    }
+    ## Rotation loop
+    for (k in 2:N) {
+        rot <- vectorfit(x[keep, c(1,k)], vec[keep], permutations=0)$arrows
+        rot <- drop(rot)
+        ## counterclockwise rotation matrix:
+        ## [cos theta   -sin theta]
+        ## [sin theta    cos theta]
+        rot <- rbind(rot, rev(rot))
+        rot[1,2] <- -rot[1,2]
+        ## Rotation of points and species scores
+        x[, c(1,k)] <- x[, c(1,k)] %*% rot
+        if (!all(is.na(sp)))
+            sp[, c(1,k)] <- sp[, c(1,k)] %*% rot
+    }
+    ## Rotate 2..N axes to PC
+    if (N > 2 && attr(object$points, "pc")) {
+        pc <- prcomp(x[,-1])
+        x[,-1] <- pc$x
+        if (!all(is.na(sp)))
+            sp[,-1] <- sp[,-1] %*% pc$rotation
+    }
+    ## '[] <-' retains attributes
+    object$points[] <- x
+    object$species[] <- sp
+    attr(object$points, "pc") <- FALSE
+    object
+}
+

Deleted: pkg/vegan/R/metaMDSrotate.R
===================================================================
--- pkg/vegan/R/metaMDSrotate.R	2011-08-28 15:47:50 UTC (rev 1767)
+++ pkg/vegan/R/metaMDSrotate.R	2011-08-28 17:15:05 UTC (rev 1768)
@@ -1,63 +0,0 @@
-### Rotates metaMDS result so that axis one is parallel to vector 'x'
-`metaMDSrotate` <-
-    function(object, vec, na.rm = FALSE, ...) 
-{
-    workswith <- c("metaMDS", "monoMDS")
-    if (!inherits(object, workswith))
-        stop(gettextf("function works only with the results of: %s",
-                      paste(workswith, collapse = ", ")))
-    x <- object$points
-    if (is.null(object$species))
-        sp <- NA
-    else
-        sp <- object$species
-    N <- NCOL(x)
-    if (N < 2)
-        stop(gettextf("needs at least 2 dimensions"))
-    vec <- drop(vec)
-    if (length(dim(vec)) > 1)
-        stop(gettextf("function works only with univariate 'vec'"))
-    if (!is.numeric(vec))
-        stop(gettextf("'vec' must be numeric"))
-    ## vectorfit finds the direction cosine. We rotate first axis to
-    ## 'vec' which means that we make other axes orthogonal to 'vec'
-    ## one by one
-    if (na.rm)
-        keep <- !is.na(vec)
-    else
-        keep <- !logical(length(vec))
-    ## scores must be orthogonal for the next loop to work
-    if (N > 2) {
-        pc <- prcomp(x[keep,])
-        x <- x %*% pc$rotation
-        if (!all(is.na(sp)))
-            sp <- sp %*% pc$rotation
-    }
-    ## Rotation loop
-    for (k in 2:N) {
-        rot <- vectorfit(x[keep, c(1,k)], vec[keep], permutations=0)$arrows
-        rot <- drop(rot)
-        ## counterclockwise rotation matrix:
-        ## [cos theta   -sin theta]
-        ## [sin theta    cos theta]
-        rot <- rbind(rot, rev(rot))
-        rot[1,2] <- -rot[1,2]
-        ## Rotation of points and species scores
-        x[, c(1,k)] <- x[, c(1,k)] %*% rot
-        if (!all(is.na(sp)))
-            sp[, c(1,k)] <- sp[, c(1,k)] %*% rot
-    }
-    ## Rotate 2..N axes to PC
-    if (N > 2 && attr(object$points, "pc")) {
-        pc <- prcomp(x[,-1])
-        x[,-1] <- pc$x
-        if (!all(is.na(sp)))
-            sp[,-1] <- sp[,-1] %*% pc$rotation
-    }
-    ## '[] <-' retains attributes
-    object$points[] <- x
-    object$species[] <- sp
-    attr(object$points, "pc") <- FALSE
-    object
-}
-

Added: pkg/vegan/R/vegan-deprecated.R
===================================================================
--- pkg/vegan/R/vegan-deprecated.R	                        (rev 0)
+++ pkg/vegan/R/vegan-deprecated.R	2011-08-28 17:15:05 UTC (rev 1768)
@@ -0,0 +1,6 @@
+`metaMDSrotate` <-
+    function(object, vec, na.rm = FALSE, ...)
+{
+    .Deprecated(new="MDSrotate", "vegan")
+    MDSrotate(object = object, vec = vec, na.rm = na.rm, ...)
+}

Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog	2011-08-28 15:47:50 UTC (rev 1767)
+++ pkg/vegan/inst/ChangeLog	2011-08-28 17:15:05 UTC (rev 1768)
@@ -2,8 +2,13 @@
 
 VEGAN DEVEL VERSIONS at http://r-forge.r-project.org/
 
-Version 1.92-1 (opened August 23, 2011)
+Version 1.92-2 (opened August 28, 2011)
 
+	* MDSrotate: metaMDSrotate() was renamed to MDSrotate(), and
+	metaMDSrotate() was .Deprecated. 
+	
+Version 1.92-1 (closed August 28, 2011)
+
 	* adonis, betadisper, mrpp: check that dissimilarities are
 	non-negative (small negative values are tolerated). The test was
 	not added to meandist: there may be legitimate usages for
@@ -18,7 +23,7 @@
 	correct).
 
 	* metaMDSrotate: can rotate monoMDS() results.
-	
+
 	* monoMDS: gained argument 'pc' (defaults TRUE) to rotate the
 	final scores to principal components.
 

Modified: pkg/vegan/inst/NEWS.Rd
===================================================================
--- pkg/vegan/inst/NEWS.Rd	2011-08-28 15:47:50 UTC (rev 1767)
+++ pkg/vegan/inst/NEWS.Rd	2011-08-28 17:15:05 UTC (rev 1768)
@@ -43,7 +43,12 @@
       addition to global NMDS, \code{monoMDS} can perform local and
       hybrid NMDS and metric MDS.  It can also handle missing and zero
       dissimilarities.  Moreover, \code{monoMDS} is faster than
-      previous alternatives.
+      previous alternatives. 
+
+      \item \code{MDSrotate} a new function to replace
+      \code{metaMDSrotate}. This function can rotate both
+      \code{metaMDS} and \code{monoMDS} results so that the first axis
+      is parallel to an environmental vector.
       
       \item \code{fitspecaccum} to fit non-linear regression models to
       the species accumulation results from \code{specaccum}. The
@@ -89,6 +94,16 @@
 
     }
   } % end NEW FEATURES
+
+  \subsection{DEPRECATED}{
+    \itemize{
+
+      \item \code{metaMDSrotate} was replaced with \code{MDSrotate}
+      that can also handle the results of \code{monoMDS}.
+
+    }  
+    
+  } % end DEPRECATED
   
   \subsection{ANALYSES}{
     \itemize{

Added: pkg/vegan/man/MDSrotate.Rd
===================================================================
--- pkg/vegan/man/MDSrotate.Rd	                        (rev 0)
+++ pkg/vegan/man/MDSrotate.Rd	2011-08-28 17:15:05 UTC (rev 1768)
@@ -0,0 +1,66 @@
+\name{MDSrotate}
+\alias{MDSrotate}
+
+\title{
+  Rotate First MDS Dimension Parallel to an External Variable
+}
+
+\description{ Function rotates a multidimensional scaling result so
+  that its first dimension is parallel to an external (environmental
+  variable). The function can handle the results from
+  \code{\link{metaMDS}} or \code{\link{monoMDS}} functions.  }
+
+\usage{
+MDSrotate(object, vec, na.rm = FALSE, ...)
+}
+
+\arguments{
+ 
+ \item{object}{ A result object from \code{\link{metaMDS}} or
+    \code{\link{monoMDS}}.}
+
+  \item{vec}{ A continuous environmental variable (vector of the same
+    length as the number of points).}
+
+  \item{na.rm}{ Remove missing values from the continuous variable
+    \code{vec}.}
+
+  \item{\dots}{ Other arguments (ignored). }
+
+}
+
+\details{ The orientation and rotation are undefined in
+  multidimensional scaling.  Functions \code{\link{metaMDS}} and
+  \code{\link{metaMDS}} can rotate their solutions to principal
+  components so that the dispersion of the points is highest on the
+  first dimension. Sometimes a different rotation is more intuitive,
+  and \code{MDSrotate} allows rotation of the result so that the first
+  axis is parallel to a given external variable.  
+}
+
+\value{ Function returns the original ordination result, but with
+  rotated scores (both site and species if available), and the
+  \code{pc} attribute of scores set to \code{FALSE}.  
+}
+
+
+\author{
+  Jari Oksanen
+}
+
+\seealso{
+  \code{\link{metaMDS}}, \code{\link{monoMDS}}.
+}
+\examples{
+data(varespec)
+data(varechem)
+mod <- monoMDS(vegdist(varespec))
+mod <- with(varechem, MDSrotate(mod, pH))
+plot(mod)
+ef <- envfit(mod ~ pH, varechem)
+plot(ef)
+ordisurf(mod ~ pH, varechem, knots = 1, add = TRUE)
+}
+
+\keyword{multivariate}
+

Modified: pkg/vegan/man/metaMDS.Rd
===================================================================
--- pkg/vegan/man/metaMDS.Rd	2011-08-28 15:47:50 UTC (rev 1767)
+++ pkg/vegan/man/metaMDS.Rd	2011-08-28 17:15:05 UTC (rev 1768)
@@ -10,7 +10,6 @@
 \alias{points.metaMDS}
 \alias{text.metaMDS}
 \alias{scores.metaMDS}
-\alias{metaMDSrotate}
 
 \title{Nonmetric Multidimensional Scaling with Stable Solution from
   Random Starts, Axis Scaling and Species Scores}
@@ -46,7 +45,6 @@
 postMDS(X, dist, pc=TRUE, center=TRUE, halfchange, threshold=0.8,
     nthreshold=10, plot=FALSE, ...)
 metaMDSredist(object, ...)
-metaMDSrotate(object, vec, na.rm = FALSE, ...)
 }
 
 \arguments{
@@ -130,15 +128,12 @@
  \item{threshold}{Largest dissimilarity used in half-change scaling. }
  \item{nthreshold}{ Minimum number of points in half-change scaling. }
  \item{object}{A result object from \code{metaMDS}.}
- \item{vec}{A continuous site variable (vector).}
- \item{na.rm}{Remove missing values from continuous variable \code{vec}.}
- 
-  \item{\dots}{Other parameters passed to functions. Function
-    \code{metaMDS} passes all arguments to its component functions
-    \code{metaMDSdist}, \code{metaMDSiter}, \code{postMDS}, and to
-    \code{distfun} and \code{engine}.}  
-}
 
+ \item{\dots}{Other parameters passed to functions. Function
+   \code{metaMDS} passes all arguments to its component functions
+   \code{metaMDSdist}, \code{metaMDSiter}, \code{postMDS}, and to
+   \code{distfun} and \code{engine}.}  }
+
 \details{ Non-metric Multidimensional Scaling (NMDS) is commonly
   regarded as the most robust unconstrained ordination method in
   community ecology (Minchin 1987).  Function \code{metaMDS} is a
@@ -226,7 +221,7 @@
     orientation of axes in NMDS: Centring moves the origin to the
     average of the axes; Principal components rotate the configuration
     so that the variance of points is maximized on first dimension
-    (with function \code{metaMDSrotate} you can alternatively rotate
+    (with function \code{\link{MDSrotate}} you can alternatively rotate
     the configuration so that the first axis is parallel to an
     environmental variable); Half-change scaling scales the
     configuration so that one unit means halving of community
@@ -320,7 +315,7 @@
   \code{\link{decostand}},
   \code{\link{wisconsin}}, 
   \code{\link{vegdist}}, \code{\link{rankindex}}, \code{\link{stepacross}}, 
-  \code{\link{procrustes}}, \code{\link{wascores}},
+  \code{\link{procrustes}}, \code{\link{wascores}}, \code{\link{MDSrotate}},
   \code{\link{ordiplot}}.
 }
 

Added: pkg/vegan/man/vegan-deprecated.Rd
===================================================================
--- pkg/vegan/man/vegan-deprecated.Rd	                        (rev 0)
+++ pkg/vegan/man/vegan-deprecated.Rd	2011-08-28 17:15:05 UTC (rev 1768)
@@ -0,0 +1,37 @@
+\name{vegan-deprecated}
+\alias{metaMDSrotate}
+
+\alias{vegan-deprecated}
+%------ NOTE:  ../R/vegan-deprecated.R   must be synchronized with this!
+\title{Deprecated Functions in vegan package}
+%------ PLEASE: one \alias{.} for EACH ! (+ one \usage{} & \arguments{} for all)
+\description{
+  These functions are provided for compatibility with older versions of
+  \pkg{vegan} only, and may be defunct as soon as the next release.
+}
+\usage{
+metaMDSrotate(object, vec, na.rm = FALSE, ...)
+}
+
+\arguments{
+ \item{object}{A result object from \code{metaMDS}.}
+ \item{vec}{A continuous site variable (vector).}
+ \item{na.rm}{Remove missing values from continuous variable \code{vec}.}
+  \item{\dots}{Other parameters passed to functions.}
+}
+
+\details{
+  %-- Either:
+  %There are currently no deprecated functions in this package.
+  %-- Or:
+  %% explain *why* it's deprecated, and \code{\link{..}} to new
+  
+  Function \code{metaMDSrotate} is replaced with
+  \code{\link{MDSrotate}} which can handle \code{\link{monoMDS}}
+  results in addition to \code{\link{metaMDS}}.
+
+}
+\seealso{
+  \code{\link{Deprecated}}
+}
+\keyword{misc}

Modified: pkg/vegan/tests/Examples/vegan-Ex.Rout.save
===================================================================
--- pkg/vegan/tests/Examples/vegan-Ex.Rout.save	2011-08-28 15:47:50 UTC (rev 1767)
+++ pkg/vegan/tests/Examples/vegan-Ex.Rout.save	2011-08-28 17:15:05 UTC (rev 1768)
@@ -23,7 +23,7 @@
 > options(warn = 1)
 > library('vegan')
 Loading required package: permute
-This is vegan 1.92-1
+This is vegan 1.92-2
 > 
 > assign(".oldSearch", search(), pos = 'CheckExEnv')
 > cleanEx()
@@ -133,6 +133,45 @@
 > 
 > 
 > cleanEx()
+> nameEx("MDSrotate")
+> ### * MDSrotate
+> 
+> flush(stderr()); flush(stdout())
+> 
+> ### Name: MDSrotate
+> ### Title: Rotate First MDS Dimension Parallel to an External Variable
+> ### Aliases: MDSrotate
+> ### Keywords: multivariate
+> 
+> ### ** Examples
+> 
+> data(varespec)
+> data(varechem)
+> mod <- monoMDS(vegdist(varespec))
+> mod <- with(varechem, MDSrotate(mod, pH))
+> plot(mod)
+> ef <- envfit(mod ~ pH, varechem)
+> plot(ef)
+> ordisurf(mod ~ pH, varechem, knots = 1, add = TRUE)
+Loading required package: mgcv
+This is mgcv 1.7-6. For overview type 'help("mgcv-package")'.
+
+Family: gaussian 
+Link function: identity 
+
+Formula:
+y ~ poly(x1, 1) + poly(x2, 1)
+<environment: 0x102383db8>
+Total model degrees of freedom 3 
+
+GCV score: 0.0427924
+> 
+> 
+> 
+> cleanEx()
+
+detaching ‘package:mgcv’
+
 > nameEx("MOStest")
 > ### * MOStest
 > 
@@ -3394,7 +3433,7 @@
 > ### Title: Nonmetric Multidimensional Scaling with Stable Solution from
 > ###   Random Starts, Axis Scaling and Species Scores
 > ### Aliases: metaMDS metaMDSdist metaMDSiter metaMDSredist initMDS postMDS
-> ###   plot.metaMDS points.metaMDS text.metaMDS scores.metaMDS metaMDSrotate
+> ###   plot.metaMDS points.metaMDS text.metaMDS scores.metaMDS
 > ### Keywords: multivariate
 > 
 > ### ** Examples
@@ -4688,7 +4727,7 @@
 
 Formula:
 y ~ s(x1, x2, k = knots)
-<environment: 0x10399f0d8>
+<environment: 0x10684e8a0>
 
 Estimated degrees of freedom:
 6.4351  total = 7.435071 
@@ -4704,7 +4743,7 @@
 
 Formula:
 y ~ s(x1, x2, k = knots)
-<environment: 0x104fecd18>
+<environment: 0x1067b0430>
 
 Estimated degrees of freedom:
 6.1039  total = 7.103853 
@@ -4860,7 +4899,7 @@
 
 Formula:
 y ~ s(x1, x2, k = knots)
-<environment: 0x106763ed0>
+<environment: 0x106c4c3f8>
 
 Estimated degrees of freedom:
 8.9275  total = 9.927492 
@@ -4873,7 +4912,7 @@
 
 Formula:
 y ~ s(x1, x2, k = knots)
-<environment: 0x1066d1940>
+<environment: 0x1069610b0>
 
 Estimated degrees of freedom:
 7.7529  total = 8.75294 
@@ -4886,7 +4925,7 @@
 
 Formula:
 y ~ s(x1, x2, k = knots)
-<environment: 0x106ba20b0>
+<environment: 0x106ba78b0>
 
 Estimated degrees of freedom:
 8.8962  total = 9.89616 
@@ -7109,7 +7148,7 @@
 
 Formula:
 y ~ s(x1, x2, k = knots)
-<environment: 0x107530ce0>
+<environment: 0x106ea3c78>
 
 Estimated degrees of freedom:
 2  total = 3 
@@ -7574,7 +7613,7 @@
 > ### * <FOOTER>
 > ###
 > cat("Time elapsed: ", proc.time() - get("ptime", pos = 'CheckExEnv'),"\n")
-Time elapsed:  103.993 1.147 107.236 0 0 
+Time elapsed:  148.95 1.66 152.883 0 0 
 > grDevices::dev.off()
 null device 
           1 



More information about the Vegan-commits mailing list