[Vegan-commits] r2381 - in branches/2.0: . R inst man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Jan 20 17:22:23 CET 2013


Author: jarioksa
Date: 2013-01-20 17:22:22 +0100 (Sun, 20 Jan 2013)
New Revision: 2381

Added:
   branches/2.0/R/print.wcmdscale.R
Modified:
   branches/2.0/NAMESPACE
   branches/2.0/R/wcmdscale.R
   branches/2.0/inst/ChangeLog
   branches/2.0/man/wcmdscale.Rd
Log:
merge r2358: print, plot & scores for wcmdscale

Modified: branches/2.0/NAMESPACE
===================================================================
--- branches/2.0/NAMESPACE	2013-01-16 07:51:58 UTC (rev 2380)
+++ branches/2.0/NAMESPACE	2013-01-20 16:22:22 UTC (rev 2381)
@@ -274,6 +274,7 @@
 S3method(plot, varpart)
 S3method(plot, varpart234)
 S3method(plot, vegandensity)
+S3method(plot, wcmdscale)
 # points: graphics
 S3method(points, cca)
 S3method(points, decorana)
@@ -352,6 +353,7 @@
 S3method(print, varpart)
 S3method(print, varpart234)
 S3method(print, vectorfit)
+S3method(print, wcmdscale)
 # profile: stats
 # see note on 'confint'
 S3method(profile, MOStest)
@@ -382,6 +384,7 @@
 S3method(scores, orditkplot)
 S3method(scores, pcnm)
 S3method(scores, rda)
+S3method(scores, wcmdscale)
 # screeplot: stats
 S3method(screeplot, cca)
 S3method(screeplot, decorana)

Copied: branches/2.0/R/print.wcmdscale.R (from rev 2358, pkg/vegan/R/print.wcmdscale.R)
===================================================================
--- branches/2.0/R/print.wcmdscale.R	                        (rev 0)
+++ branches/2.0/R/print.wcmdscale.R	2013-01-20 16:22:22 UTC (rev 2381)
@@ -0,0 +1,61 @@
+### support functions for wcmdscale results: print, scores and plot.
+
+`print.wcmdscale` <-
+    function(x, digits = max(3, getOption("digits") - 3), ...)
+{
+    writeLines(strwrap(pasteCall(x$call)))
+    cat("\n")
+    ## tabulate total inertia and ranks
+    totev <- sum(x$eig)
+    negax <- x$eig < 0
+    if (any(negax)) {
+        ranks <- c(NA, sum(!negax), sum(negax))
+        negax <- x$eig < 0
+        realev <- sum(x$eig[!negax])
+        imev <- sum(x$eig[negax])
+        evs <- c("Total" = totev, "Real" = realev, "Imaginary" = imev)
+    } else {
+        ranks <- length(x$eig)
+        evs <- c("Total" = totev)
+    }
+    tbl <- cbind("Inertia" = evs, "Rank" = ranks)
+    printCoefmat(tbl, digits = digits, na.print = "")
+    cat("\nResults have", NROW(x$points), "points,", NCOL(x$points), "axes\n")
+    ## print eigenvalues, but truncate very long lists
+    PRINLIM <- 120
+    neig <- length(x$eig)
+    cat("\nEigenvalues:\n")
+    print(zapsmall(x$eig[1 : min(neig, PRINLIM)], digits = digits, ...))
+    if (neig > PRINLIM)
+        cat("(Showed only", PRINLIM, "of all", neig, "eigenvalues)\n")
+    wvar <- var(x$weights)
+    wlen <- length(x$weights)
+    cat("\nWeights:")
+    if (wvar < 1e-6)
+        cat(" Constant\n")
+    else {
+        cat("\n")
+        print(zapsmall(x$weights[1 : min(wlen, PRINLIM)], digits = digits, ...))
+        if (wlen > PRINLIM)
+            cat("(Showed only", PRINLIM, "of all", wlen, "weights)\n")
+    }
+    cat("\n")
+    invisible(x)
+}
+
+`scores.wcmdscale` <-
+    function(x, choices = NA, ...)
+{
+    if (any(is.na(choices)))
+        x$points
+    else {
+        choices <- choices[choices <= NCOL(x$points)]
+        x$points[, choices, drop = FALSE]
+    }
+}
+
+`plot.wcmdscale` <-
+    function(x, choices = c(1,2), type = "t", ...)
+{
+    ordiplot(x, display = "sites", choices = choices, type = type, ...)
+}

Modified: branches/2.0/R/wcmdscale.R
===================================================================
--- branches/2.0/R/wcmdscale.R	2013-01-16 07:51:58 UTC (rev 2380)
+++ branches/2.0/R/wcmdscale.R	2013-01-20 16:22:22 UTC (rev 2381)
@@ -48,9 +48,10 @@
     GOF <- c(sum(ev)/sum(abs(e$values)),
              sum(ev)/sum(e$values[e$values > 0]))
     if (eig || x.ret || add) {
+        colnames(points) <- paste("Dim", seq_len(NCOL(points)), sep="") 
         out <- list(points = points, eig = if (eig) e$values,
                     x = if (x.ret) m, ac = NA, GOF = GOF, weights = w,
-                    negaxes = negaxes)
+                    negaxes = negaxes, call = match.call())
         class(out) <- "wcmdscale"
     }
     else out <- points

Modified: branches/2.0/inst/ChangeLog
===================================================================
--- branches/2.0/inst/ChangeLog	2013-01-16 07:51:58 UTC (rev 2380)
+++ branches/2.0/inst/ChangeLog	2013-01-20 16:22:22 UTC (rev 2381)
@@ -4,12 +4,14 @@
 
 Version 2.0-6 (opened October 8, 2012)
 
-	* merge 2374: orditorp gains argument select
+	* merge 2374,6,7: orditorp gains argument select
 	* merge 2372: ordilabel uses ordiArgAbsorber when plotting
 	* merge 2369: clamtest fix and border cases.
 	* merge 2367: rectify mantel, summary.anosim print.
 	* merge 2362: doc on r2357 for capscale.
-	* merge 2361: adjust imaginary axes similarly as real eigenvalue. 
+	* merge 2361: adjust imaginary axes similarly as real eigenvalue.
+	* merge 2358: print etc. for wcmdscale (no stressplot parts of
+	2358). 
 	* merge 2357: print additive constant in capscale.
 	* merge 2350: capscale species score scaling bug fix.
 	* merge 2349: multipart print bug fix.

Modified: branches/2.0/man/wcmdscale.Rd
===================================================================
--- branches/2.0/man/wcmdscale.Rd	2013-01-16 07:51:58 UTC (rev 2380)
+++ branches/2.0/man/wcmdscale.Rd	2013-01-20 16:22:22 UTC (rev 2381)
@@ -6,9 +6,15 @@
 
 \name{wcmdscale}
 \alias{wcmdscale}
+\alias{print.wcmdscale}
+\alias{scores.wcmdscale}
+\alias{plot.wcmdscale}
+
 \title{Weighted Classical (Metric) Multidimensional Scaling}
 \usage{
 wcmdscale(d, k, eig = FALSE, add = FALSE, x.ret = FALSE, w)
+\method{plot}{wcmdscale}(x, choices = c(1, 2), type = "t", ...)
+\method{scores}{wcmdscale}(x, choices = NA, ...) 
 }
 \description{
   Weighted classical multidimensional scaling, 
@@ -27,6 +33,13 @@
   \item{x.ret}{indicates whether the doubly centred symmetric distance
     matrix should be returned.}
   \item{w}{Weights of points.}
+  \item{x}{The \code{wcmdscale} result object when the function was
+    called with options \code{eig = TRUE} or \code{x.ret = TRUE} (See
+    Details).}
+  \item{choices}{Axes to be returned; \code{NA} returns all real axes.}
+  \item{type}{Type of graph which may be \code{"t"}ext, \code{"p"}oints
+    or \code{"n"}one.}
+  \item{\dots}{Other arguments passed to graphical functions.}
 }
 \details{
   Function \code{wcmdscale} is based on function
@@ -34,8 +47,14 @@
   point weights. Points with high weights will have a stronger
   influence on the result than those with low weights. Setting equal
   weights \code{w = 1} will give ordinary multidimensional scaling.
-}
 
+  With default options, the function returns only a matrix of scores
+  scaled by eigenvalues for all real axes. If the function is called
+  with \code{eig = TRUE} or \code{x.ret = TRUE}, the function returns an
+  object of class \code{"wcmdscale"} with \code{print}, \code{plot},
+  \code{scores}, \code{\link{eigenvals}} and \code{\link{stressplot}}
+  methods, and described in section Value.  }
+
 \value{ If \code{eig = FALSE} and \code{x.ret = FALSE} (default), a
   matrix with \code{k} columns whose rows give the coordinates of the
   points chosen to represent the dissimilarities.  Otherwise, an
@@ -56,7 +75,8 @@
      scaled by the absolute eigenvalues similarly as
      \code{points}. This is \code{NULL} if there are no negative
      eigenvalues or \code{k} was specified, and would not include
-     negative eigenvalues.}  
+     negative eigenvalues.}
+  \item{call}{Function call.}
 }
 
 \references{
@@ -69,10 +89,11 @@
   \emph{Multivariate Analysis}, London: Academic Press.
 }
 
-\seealso{ \code{\link{cmdscale}}.  Also \code{\link{monoMDS}}, and
+\seealso{The function is modelled after \code{\link{cmdscale}}, but adds
+  weights (hence name) and handles negative eigenvalues differently.
+  Other multidimensional scaling methods are \code{\link{monoMDS}}, and
   \code{\link[MASS]{isoMDS}} and \code{\link[MASS]{sammon}} in package
-  \pkg{MASS}.  
-}
+  \pkg{MASS}.  }
 
 \examples{
 ## Correspondence analysis as a weighted principal coordinates



More information about the Vegan-commits mailing list