[Analogue-commits] r320 - in pkg: . R inst man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu May 9 22:29:06 CEST 2013


Author: gsimpson
Date: 2013-05-09 22:29:06 +0200 (Thu, 09 May 2013)
New Revision: 320

Added:
   pkg/man/scores.prcurve.Rd
Modified:
   pkg/NAMESPACE
   pkg/R/predict.wa.R
   pkg/R/scores.prcurve.R
   pkg/inst/ChangeLog
Log:
adds scores.prcurve and a bug fix to predict.wa

Modified: pkg/NAMESPACE
===================================================================
--- pkg/NAMESPACE	2013-04-08 04:48:18 UTC (rev 319)
+++ pkg/NAMESPACE	2013-05-09 20:29:06 UTC (rev 320)
@@ -47,6 +47,7 @@
        dissimilarities,
        distance,
        distance3,
+       #distanceX,
        fuse,
        getK,
        gradientDist,

Modified: pkg/R/predict.wa.R
===================================================================
--- pkg/R/predict.wa.R	2013-04-08 04:48:18 UTC (rev 319)
+++ pkg/R/predict.wa.R	2013-05-09 20:29:06 UTC (rev 320)
@@ -33,6 +33,10 @@
             pred <- WApred(newdata[,want], object$wa.optima[want])
         }
         pred <- deshrinkPred(pred, coef(object), type = Dtype)
+        ## pred can end up being a 1 col matrix
+        ## FIXME: really should check why, but for now, drop
+        ## empty dimension
+        pred <- drop(pred)
     } else {
         ## CV wanted
         if(identical(CV, "LOO")) {

Modified: pkg/R/scores.prcurve.R
===================================================================
--- pkg/R/scores.prcurve.R	2013-04-08 04:48:18 UTC (rev 319)
+++ pkg/R/scores.prcurve.R	2013-05-09 20:29:06 UTC (rev 320)
@@ -1,4 +1,13 @@
 ## `scores` extractor function for prcurve class
-`scores.prcurve` <- function(x, ...) {
-  matrix(x$lambda, ncol = 1)
+`scores.prcurve` <- function(x, display = c("curve","dimensions"), ...) {
+  display <- match.arg(display)
+  ## return position along the curve?
+  if (isTRUE(all.equal(display, "curve"))) {
+    ret <- matrix(x$lambda, ncol = 1)
+  }
+  ## return coordinates of curve in each dimension
+  if (isTRUE(all.equal(display, "dimensions"))) {
+    ret <- x$s
+  }
+  ret
 }

Modified: pkg/inst/ChangeLog
===================================================================
--- pkg/inst/ChangeLog	2013-04-08 04:48:18 UTC (rev 319)
+++ pkg/inst/ChangeLog	2013-05-09 20:29:06 UTC (rev 320)
@@ -18,7 +18,8 @@
 	The `fitted` method has changed slightly. The `type` argument
 	has been renamed `which`.
 
-	* scores: new method for objects of class "timetrack".
+	* scores: new methods for objects of class "timetrack" and
+	class "prcurve".
 
 	* analog: gains a method for objects of class "distance".
 
@@ -36,6 +37,10 @@
 	that the next version of analogue (0.12-x) will have this version
 	of the code replace the old mainly R-based distance().
 
+	* predict.wa: deshrinking step sometimes produced a 1 column
+	matrix, which would result in an error. This empty dimension is
+	now dropped.
+
 Version 0.11-1
 
 	* scores.prcurve: new function to extract "axis" scores for

Added: pkg/man/scores.prcurve.Rd
===================================================================
--- pkg/man/scores.prcurve.Rd	                        (rev 0)
+++ pkg/man/scores.prcurve.Rd	2013-05-09 20:29:06 UTC (rev 320)
@@ -0,0 +1,68 @@
+\name{scores.prcurve}
+\alias{scores.prcurve}
+
+\title{\code{\link[vegan]{scores}} method for principal curve objects of
+  class \code{"prcurve"}.}
+\description{
+  A \code{\link[vegan]{scores}} method to extract the position on the
+  curve to which each observation projects (\code{display = "curve"}) or
+  the coordinates of the curve in the dimensions of the input data
+  (\code{display = "dimensions"}).
+}
+\usage{
+\method{scores}{prcurve}(x, display = c("curve", "dimensions"), ...)
+}
+
+\arguments{
+  \item{x}{an object of class \code{"prcurve"}, usually from a call to
+    \code{\link{prcurve}}}.
+  \item{display}{character; which type of scores to
+    extract. \code{display = "curve"} returns the position along the curve
+    onto which each observation projects; this can be used like a PCA axis
+    score. \code{display = "dimensions"} returns the coordinates of the
+    curve in the dimensions of the original data.}
+  \item{\dots}{Arguments passed to other methods. Not used.}
+}
+%\details{
+%%  ~~ If necessary, more details than the description above ~~
+%}
+\value{
+  If \code{display = "curve"} a 1-column matrix is returned with a row
+  for each observation in the input data. If \code{display =
+  "dimensions"}, a matrix of coordinates for the principal curve is
+  returned. The dimensions of this matrix relate to the dimensions of
+  the input data; if there were \eqn{n} samples (rows) and \eqn{m}
+  variables {columns} then the matrix returned by \code{scores.prcurve}
+  will have \eqn{n} rows and \eqn{m} columns.
+}
+\author{Gavin L. Simpson}
+
+%% ~Make other sections like Warning with \section{Warning }{....} ~
+
+\seealso{
+  \code{\link{prcurve}} for fitting principal curves to data.
+}
+\examples{
+## Load the Abernethy Forest data set
+data(abernethy)
+
+## Remove the Depth and Age variables
+abernethy2 <- abernethy[, -(37:38)]
+
+## Fit the principal curve using varying complexity of smoothers
+## for each species
+aber.pc <- prcurve(abernethy2, method = "ca", trace = TRUE,
+                   vary = TRUE, penalty = 1.4)
+
+## Extract position on the curve
+pos <- scores(aber.pc, display = "curve")
+head(pos)
+
+## Extract the coordinates of the curve
+coord <- scores(aber.pc, display = "dimensions")
+dim(coord)
+all.equal(dim(coord), dim(abernethy2))
+}
+% Add one or more standard keywords, see file 'KEYWORDS' in the
+% R documentation directory.
+\keyword{ methods }



More information about the Analogue-commits mailing list