From noreply at r-forge.r-project.org Thu May 9 22:29:06 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 9 May 2013 22:29:06 +0200 (CEST) Subject: [Analogue-commits] r320 - in pkg: . R inst man Message-ID: <20130509202906.A6F7D185162@r-forge.r-project.org> 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 } From noreply at r-forge.r-project.org Fri May 10 21:06:15 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 10 May 2013 21:06:15 +0200 (CEST) Subject: [Analogue-commits] r321 - pkg/R Message-ID: <20130510190615.DB7FC1854E4@r-forge.r-project.org> Author: gsimpson Date: 2013-05-10 21:06:15 +0200 (Fri, 10 May 2013) New Revision: 321 Modified: pkg/R/prcurve.R Log: add variables names to the smooths component Modified: pkg/R/prcurve.R =================================================================== --- pkg/R/prcurve.R 2013-05-09 20:29:06 UTC (rev 320) +++ pkg/R/prcurve.R 2013-05-10 19:06:15 UTC (rev 321) @@ -167,6 +167,7 @@ config$complexity <- complexity ## config$fitFUN <- fitFUN config$smooths <- smooths + names(config$smooths) <- colnames(X) config$call <- match.call() class(config) <- c("prcurve") return(config) From noreply at r-forge.r-project.org Mon May 13 06:55:07 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 13 May 2013 06:55:07 +0200 (CEST) Subject: [Analogue-commits] r322 - pkg/man Message-ID: <20130513045507.7B6DE184E39@r-forge.r-project.org> Author: gsimpson Date: 2013-05-13 06:55:07 +0200 (Mon, 13 May 2013) New Revision: 322 Added: pkg/man/scores.prcurve.Rd Removed: pkg/man/scores.prcurve.Rd Log: fix typo in arguments Deleted: pkg/man/scores.prcurve.Rd =================================================================== --- pkg/man/scores.prcurve.Rd 2013-05-10 19:06:15 UTC (rev 321) +++ pkg/man/scores.prcurve.Rd 2013-05-13 04:55:07 UTC (rev 322) @@ -1,68 +0,0 @@ -\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 } Added: pkg/man/scores.prcurve.Rd =================================================================== --- pkg/man/scores.prcurve.Rd (rev 0) +++ pkg/man/scores.prcurve.Rd 2013-05-13 04:55:07 UTC (rev 322) @@ -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 } From noreply at r-forge.r-project.org Mon May 13 06:56:03 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 13 May 2013 06:56:03 +0200 (CEST) Subject: [Analogue-commits] r323 - in pkg: . R inst man Message-ID: <20130513045603.E91BD185009@r-forge.r-project.org> Author: gsimpson Date: 2013-05-13 06:56:03 +0200 (Mon, 13 May 2013) New Revision: 323 Modified: pkg/DESCRIPTION pkg/R/chooseTaxa.R pkg/inst/ChangeLog pkg/man/chooseTaxa.Rd Log: add 'value' argument Modified: pkg/DESCRIPTION =================================================================== --- pkg/DESCRIPTION 2013-05-13 04:55:07 UTC (rev 322) +++ pkg/DESCRIPTION 2013-05-13 04:56:03 UTC (rev 323) @@ -1,7 +1,7 @@ Package: analogue Type: Package Title: Analogue and weighted averaging methods for palaeoecology -Version: 0.11-2 +Version: 0.11-3 Date: $Date$ Depends: R (>= 2.15.0), vegan (>= 1.17-12), princurve, lattice Imports: mgcv, MASS, stats, graphics, grid Modified: pkg/R/chooseTaxa.R =================================================================== --- pkg/R/chooseTaxa.R 2013-05-13 04:55:07 UTC (rev 322) +++ pkg/R/chooseTaxa.R 2013-05-13 04:56:03 UTC (rev 323) @@ -3,7 +3,8 @@ } chooseTaxa.default <- function(object, n.occ = 1, max.abun = 0, - type = c("AND","OR"), ...) { + type = c("AND","OR"), value = TRUE, + ...) { if(missing(type)) type <- "AND" type <- match.arg(type) @@ -14,10 +15,14 @@ } else { occ.want | abun.want } - rname <- rownames(object) - cname <- colnames(object) - object <- object[, want] - rownames(object) <- rname - colnames(object) <- cname[want] - return(object) + if(value) { + rname <- rownames(object) + cname <- colnames(object) + object <- object[, want] + rownames(object) <- rname + colnames(object) <- cname[want] + } else { + object <- want + } + object } Modified: pkg/inst/ChangeLog =================================================================== --- pkg/inst/ChangeLog 2013-05-13 04:55:07 UTC (rev 322) +++ pkg/inst/ChangeLog 2013-05-13 04:56:03 UTC (rev 323) @@ -1,5 +1,11 @@ analogue Change Log +Version 0.11-3 + + * chooseTaxa: new argument `value` controls whether the data for + the selected species or a logical vector indicating which columns + (species) met the selection criteria. + Version 0.11-2 * timetrack: plot method now allows plotting of "lc" or "wa" Modified: pkg/man/chooseTaxa.Rd =================================================================== --- pkg/man/chooseTaxa.Rd 2013-05-13 04:55:07 UTC (rev 322) +++ pkg/man/chooseTaxa.Rd 2013-05-13 04:56:03 UTC (rev 323) @@ -2,7 +2,7 @@ \alias{chooseTaxa} \alias{chooseTaxa.default} \title{Select taxa (variables) on basis of maximum abundance attained - and number of occurrences} + and number of occurrences.} \description{ Select taxa (variables) from an object on the basis of one or both of maximum abundance and number of occurrences greater than user-specified @@ -13,7 +13,7 @@ chooseTaxa(object, \dots) \method{chooseTaxa}{default}(object, n.occ = 1, max.abun = 0, - type = c("AND","OR"), \dots) + type = c("AND","OR"), value = TRUE, \dots) } %- maybe also 'usage' for other objects documented here. \arguments{ @@ -34,13 +34,18 @@ \item{type}{character; one of \code{"AND"} or \code{"OR"}, controlling how the criteria \code{n.occ} and \code{max.abun} are combined to generate a subset of the variables in \code{object}.} + \item{value}{logical; should the data for the selected taxa be + returned? If \code{TRUE}, the default, the data for the chosen taxa + are returned. If \code{FALSE}, a logical vector is returned, + indicating which taxa met the selection criteria.} \item{\dots}{arguments passed on to subsequent methods.} } %\details{ %} \value{ - Returns the supplied data frame or matrix with a subset of columns - (taxa) that meet the criteria chosen. + If \code{value = TRUE}, returns the supplied data frame or matrix + with a subset of columns (taxa) that meet the criteria chosen. If + \code{value = FALSE}, a logical vector is returned. } %\references{ %} @@ -52,6 +57,9 @@ IK2 <- chooseTaxa(ImbrieKipp, n.occ = 5) dim(ImbrieKipp) dim(IK2) + +## return a logical vector to select species/columns +chooseTaxa(ImbrieKipp, n.occ = 5, value = FALSE) } \keyword{methods} \keyword{multivariate} From noreply at r-forge.r-project.org Mon May 13 07:02:02 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 13 May 2013 07:02:02 +0200 (CEST) Subject: [Analogue-commits] r324 - pkg/R Message-ID: <20130513050202.33999185009@r-forge.r-project.org> Author: gsimpson Date: 2013-05-13 07:02:01 +0200 (Mon, 13 May 2013) New Revision: 324 Modified: pkg/R/scores.prcurve.R Log: preserve the names on 'lambda' when returning it as a matrix Modified: pkg/R/scores.prcurve.R =================================================================== --- pkg/R/scores.prcurve.R 2013-05-13 04:56:03 UTC (rev 323) +++ pkg/R/scores.prcurve.R 2013-05-13 05:02:01 UTC (rev 324) @@ -4,6 +4,8 @@ ## return position along the curve? if (isTRUE(all.equal(display, "curve"))) { ret <- matrix(x$lambda, ncol = 1) + rownames(ret) <- names(x$lambda) + colnames(ret) <- "PrC" } ## return coordinates of curve in each dimension if (isTRUE(all.equal(display, "dimensions"))) { From noreply at r-forge.r-project.org Mon May 13 07:02:27 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 13 May 2013 07:02:27 +0200 (CEST) Subject: [Analogue-commits] r325 - pkg/inst Message-ID: <20130513050227.E40DA185009@r-forge.r-project.org> Author: gsimpson Date: 2013-05-13 07:02:27 +0200 (Mon, 13 May 2013) New Revision: 325 Modified: pkg/inst/ChangeLog Log: preserve the names on 'lambda' when returning it as a matrix Modified: pkg/inst/ChangeLog =================================================================== --- pkg/inst/ChangeLog 2013-05-13 05:02:01 UTC (rev 324) +++ pkg/inst/ChangeLog 2013-05-13 05:02:27 UTC (rev 325) @@ -6,6 +6,9 @@ the selected species or a logical vector indicating which columns (species) met the selection criteria. + * scores.prcurve: now preserves the rownames on the `lambda` + component. + Version 0.11-2 * timetrack: plot method now allows plotting of "lc" or "wa" From noreply at r-forge.r-project.org Mon May 13 07:06:45 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 13 May 2013 07:06:45 +0200 (CEST) Subject: [Analogue-commits] r326 - in pkg: R inst Message-ID: <20130513050645.1CF2B185009@r-forge.r-project.org> Author: gsimpson Date: 2013-05-13 07:06:44 +0200 (Mon, 13 May 2013) New Revision: 326 Added: pkg/R/sppResponse.R pkg/R/sppResponse.prcurve.R Modified: pkg/inst/ChangeLog Log: add sppResponse Added: pkg/R/sppResponse.R =================================================================== --- pkg/R/sppResponse.R (rev 0) +++ pkg/R/sppResponse.R 2013-05-13 05:06:44 UTC (rev 326) @@ -0,0 +1,3 @@ +`sppResponse` <- function(x, ...) { + UseMethod("sppResponse") +} Added: pkg/R/sppResponse.prcurve.R =================================================================== --- pkg/R/sppResponse.prcurve.R (rev 0) +++ pkg/R/sppResponse.prcurve.R 2013-05-13 05:06:44 UTC (rev 326) @@ -0,0 +1,13 @@ +`sppResponse.prcurve` <- function(x, n = 100, ...) { + Pred <- function(x, n) { + rn <- range(x$lambda) + newx <- seq(from = rn[1], to = rn[2], length = n) + fitted.values <- predict(x$model, x = newx) + observed <- x[c("lambda","x")] + names(fitted.values) <- names(observed) <- c("gradient","response") + list(observed = observed, fitted.values = fitted.values) + } + out <- lapply(x$smooths, Pred, n = n) + class(out) <- "sppResponse" + out +} Modified: pkg/inst/ChangeLog =================================================================== --- pkg/inst/ChangeLog 2013-05-13 05:02:27 UTC (rev 325) +++ pkg/inst/ChangeLog 2013-05-13 05:06:44 UTC (rev 326) @@ -9,6 +9,10 @@ * scores.prcurve: now preserves the rownames on the `lambda` component. + * sppResponse: new generic function for species responses along + gradients. A method is provided for objects of class "prcurve" + is the only available method currently. + Version 0.11-2 * timetrack: plot method now allows plotting of "lc" or "wa" From noreply at r-forge.r-project.org Mon May 13 07:11:39 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 13 May 2013 07:11:39 +0200 (CEST) Subject: [Analogue-commits] r327 - in pkg: R inst Message-ID: <20130513051139.CB28218538E@r-forge.r-project.org> Author: gsimpson Date: 2013-05-13 07:11:39 +0200 (Mon, 13 May 2013) New Revision: 327 Added: pkg/R/plot.sppResponse.R Modified: pkg/inst/ChangeLog Log: add plot method for sppResponse Added: pkg/R/plot.sppResponse.R =================================================================== --- pkg/R/plot.sppResponse.R (rev 0) +++ pkg/R/plot.sppResponse.R 2013-05-13 05:11:39 UTC (rev 327) @@ -0,0 +1,29 @@ +`plot.sppResponse` <- function(x, which = seq_along(x), + display = c("observed","fitted"), + xlab = "Gradient", + ylab = "Abundance", + main = NULL, + lcol = "red", + lwd = 2, + ...) { + display <- match.arg(display) + + noMain <- is.null(main) + if (noMain) { + nams <- names(x) + } + + for (i in which) { + ox <- x[[i]]$observed$gradient + oy <- x[[i]]$observed$response + fx <- x[[i]]$fitted.values$gradient + fy <- x[[i]]$fitted.values$response + xlim <- range(ox, fx) + ylim <- range(oy, fy) + if (noMain) + main <- nams[i] + plot(ox, oy, xlim = xlim, ylim = ylim, ylab = ylab, xlab = xlab, + main = main, ...) + lines(fx, fy, col = lcol, lwd = lwd, ...) + } +} Modified: pkg/inst/ChangeLog =================================================================== --- pkg/inst/ChangeLog 2013-05-13 05:06:44 UTC (rev 326) +++ pkg/inst/ChangeLog 2013-05-13 05:11:39 UTC (rev 327) @@ -11,7 +11,8 @@ * sppResponse: new generic function for species responses along gradients. A method is provided for objects of class "prcurve" - is the only available method currently. + is the only available method currently. A `plot()` method for + `sppResponse()` objects is also provided. Version 0.11-2 From noreply at r-forge.r-project.org Mon May 13 07:39:07 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 13 May 2013 07:39:07 +0200 (CEST) Subject: [Analogue-commits] r328 - pkg/man Message-ID: <20130513053907.DAD2F185378@r-forge.r-project.org> Author: gsimpson Date: 2013-05-13 07:39:07 +0200 (Mon, 13 May 2013) New Revision: 328 Added: pkg/man/sppResponse.prcurve.Rd Log: document sppResponse Added: pkg/man/sppResponse.prcurve.Rd =================================================================== --- pkg/man/sppResponse.prcurve.Rd (rev 0) +++ pkg/man/sppResponse.prcurve.Rd 2013-05-13 05:39:07 UTC (rev 328) @@ -0,0 +1,62 @@ +\name{sppResponse} +\alias{sppResponse} +\alias{sppResponse.prcurve} + +\title{Species responses along gradients.} +\description{The fitted responses of species along gradients are + estimated or extracted from appropriate objects.} +\usage{ +sppResponse(x, ...) + +\method{sppResponse}{prcurve}(x, n = 100, ...) +} +\arguments{ + \item{x}{an R object.} + \item{n}{numeric; the number of locations on the gradient to evaluate + the response curve.} + \item{\dots}{additional arguments passed to other methods.} +} +\details{ + \code{sppResponse} estimates species responses along indicated + gradients. + + There is currently no \code{"default"} method and the only specified + method supplied is for objects fitted by \code{\link{prcurve}}. This + method extracts the fitted responses of species along the principal + curve and is a useful diagnostic for identifying overly-complex + curves. +} +\value{ + A list is returned with components \code{observed} and + \code{fitted.values} containing the observed and fitted values of the + species response and gradient respectively. Each is a list with two + components, \code{gradient} and \code{response}, containing the + gradient and response values. +} +\author{Gavin L. Simpson} + +%% ~Make other sections like Warning with \section{Warning }{....} ~ + +\seealso{ + \code{\link{prcurve}} for one function that can be used with + \code{sppResponse}. A \code{\link{plot}} method is available; see + \code{plot.sppResponse} for details. +} +\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 the fitted species response curves +resp <- sppResponse(aber.pc) +} +% Add one or more standard keywords, see file 'KEYWORDS' in the +% R documentation directory. +\keyword{ methods } From noreply at r-forge.r-project.org Mon May 13 07:39:44 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 13 May 2013 07:39:44 +0200 (CEST) Subject: [Analogue-commits] r329 - pkg Message-ID: <20130513053944.17369185378@r-forge.r-project.org> Author: gsimpson Date: 2013-05-13 07:39:43 +0200 (Mon, 13 May 2013) New Revision: 329 Modified: pkg/NAMESPACE Log: updated for sppResponse and plot.sppResponse Modified: pkg/NAMESPACE =================================================================== --- pkg/NAMESPACE 2013-05-13 05:39:07 UTC (rev 328) +++ pkg/NAMESPACE 2013-05-13 05:39:43 UTC (rev 329) @@ -47,7 +47,7 @@ dissimilarities, distance, distance3, - #distanceX, + distanceX, fuse, getK, gradientDist, @@ -68,6 +68,7 @@ splitSample, roc, smoothSpline, + sppResponse, Stratiplot, stdError, timetrack, @@ -141,6 +142,7 @@ S3method(roc, mat) S3method(scores, prcurve) S3method(scores, timetrack) +S3method(sppResponse, prcurve) S3method(stdError, mat) S3method(stdError, predict.mat) S3method("setK<-", default) @@ -189,6 +191,7 @@ S3method(plot, prcurve) S3method(plot, residLen) S3method(plot, roc) +S3method(plot, sppResponse) S3method(plot, timetrack) S3method(plot, wa) S3method(plot, weightedCor) From noreply at r-forge.r-project.org Wed May 22 16:53:00 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 22 May 2013 16:53:00 +0200 (CEST) Subject: [Analogue-commits] r330 - in pkg: . R inst man Message-ID: <20130522145301.0A1BD1848F5@r-forge.r-project.org> Author: gsimpson Date: 2013-05-22 16:53:00 +0200 (Wed, 22 May 2013) New Revision: 330 Added: pkg/R/dotplot.rankDC.R pkg/R/plot.rankDC.R pkg/R/rankDC.R pkg/man/rankDC.Rd Modified: pkg/NAMESPACE pkg/inst/ChangeLog Log: adds rankDC and plot methods Modified: pkg/NAMESPACE =================================================================== --- pkg/NAMESPACE 2013-05-13 05:39:43 UTC (rev 329) +++ pkg/NAMESPACE 2013-05-22 14:53:00 UTC (rev 330) @@ -13,7 +13,7 @@ ## -- need here *only* those funs that we define S3 methods for ## not the functions from lattice we use as they are covered ## by Depends: lattice in DESCRIPTION -importFrom(lattice, densityplot, histogram) +importFrom(lattice, densityplot, dotplot, histogram) ## stats import(stats) ## utils @@ -66,6 +66,7 @@ residLen, RMSEP, splitSample, + rankDC, roc, smoothSpline, sppResponse, @@ -177,18 +178,20 @@ S3method(caterpillarPlot, default) S3method(caterpillarPlot, data.frame) S3method(caterpillarPlot, wa) +S3method(dotplot, rankDC) S3method(plot, minDC) S3method(plot, bayesF) S3method(plot, cma) S3method(plot, dissimilarities) S3method(plot, gradientDist) S3method(lines, gradientDist) -S3method(lines, prcurve) S3method(points, gradientDist) S3method(plot, logitreg) S3method(plot, mat) S3method(plot, mcarlo) S3method(plot, prcurve) +S3method(lines, prcurve) +S3method(plot, rankDC) S3method(plot, residLen) S3method(plot, roc) S3method(plot, sppResponse) @@ -222,6 +225,7 @@ S3method(print, prcurve) S3method(print, predict.mat) S3method(print, predict.wa) +S3method(print, rankDC) S3method(print, residLen) S3method(print, residuals.bootstrap.mat) S3method(print, residuals.mat) Added: pkg/R/dotplot.rankDC.R =================================================================== --- pkg/R/dotplot.rankDC.R (rev 0) +++ pkg/R/dotplot.rankDC.R 2013-05-22 14:53:00 UTC (rev 330) @@ -0,0 +1,6 @@ +dotplot.rankDC <- function(x, data = NULL, sort = TRUE, decreasing = FALSE, + xlab = "Rank correlation", ...) { + if(sort) + x <- sort(x, decreasing = decreasing) + dotplot(~ x, xlab = xlab, ...) +} Added: pkg/R/plot.rankDC.R =================================================================== --- pkg/R/plot.rankDC.R (rev 0) +++ pkg/R/plot.rankDC.R 2013-05-22 14:53:00 UTC (rev 330) @@ -0,0 +1,10 @@ +plot.rankDC <- function(x, sort = TRUE, decreasing = FALSE, + xlab = "Rank correlation", color = "blue", + pch = 21, bg = "blue", lcolor = "grey", + lty = "solid", ...) { + if(sort) + x <- sort(x, decreasing = decreasing) + dotchart(x, xlab = xlab, + color = color, pch = pch, bg = bg, lcolor = lcolor, + lty = lty, ...) +} Added: pkg/R/rankDC.R =================================================================== --- pkg/R/rankDC.R (rev 0) +++ pkg/R/rankDC.R 2013-05-22 14:53:00 UTC (rev 330) @@ -0,0 +1,29 @@ +## rank correlation betwen distance on gradient (`g`) and distance +## in response space (`y`) +## Similar to rankindex() in vegan but for analogue +rankDC <- function(g, y, + dc = c("chord", "bray", "euclidean", "chi.square", "gower"), + method = "spearman") { + g <- as.data.frame(g) + if (any(sapply(g, is.factor))) { + message("'g' included factors: used Gower's distance") + span <- distance(g, method = "mixed") + } else { + span <- distance(g, method = "euclidean") + } + span <- as.dist(span) + y <- as.matrix(y) + res <- numeric(length(dc)) + names(res) <- dc + for (i in dc) { + Y <- as.dist(distance(y, method = i)) + res[i] <- cor(span, Y, method = method) + } + class(res) <- "rankDC" + res +} + +print.rankDC <- function(x, ...) { + attr(x, "class") <- NULL + print.default(x) +} Modified: pkg/inst/ChangeLog =================================================================== --- pkg/inst/ChangeLog 2013-05-13 05:39:43 UTC (rev 329) +++ pkg/inst/ChangeLog 2013-05-22 14:53:00 UTC (rev 330) @@ -14,6 +14,11 @@ is the only available method currently. A `plot()` method for `sppResponse()` objects is also provided. + * rankDC: new function to compute the rank correlation between + gradient distances (e.g. environmental variables) and distances + in species composition. Has both base and Lattice graphics plot + methods (the latter via `dotplot()`). + Version 0.11-2 * timetrack: plot method now allows plotting of "lc" or "wa" Added: pkg/man/rankDC.Rd =================================================================== --- pkg/man/rankDC.Rd (rev 0) +++ pkg/man/rankDC.Rd 2013-05-22 14:53:00 UTC (rev 330) @@ -0,0 +1,76 @@ +\name{rankDC} +\alias{rankDC} +\alias{print.rankDC} +\alias{plot.rankDC} +\alias{dotplot.rankDC} + +\title{Rank correlation between environmental and species dissimilarities.} +\description{ + Computes the rank correlation between distances between sites in terms + of gradient variables, such as environmental ones, and species + composition. +} +\usage{ +rankDC(g, y, dc = c("chord", "bray", "euclidean", "chi.square", "gower"), + method = "spearman") + +\method{plot}{rankDC}(x, sort = TRUE, decreasing = FALSE, + xlab = "Rank correlation", color = "blue", + pch = 21, bg = "blue", lcolor = "grey", + lty = "solid", \dots) + +\method{dotplot}{rankDC}(x, data = NULL, sort = TRUE, decreasing = FALSE, + xlab = "Rank correlation", \dots) +} +%- maybe also 'usage' for other objects documented here. +\arguments{ + \item{g}{the gradient values; usually a data frame of environmental + data.} + \item{y}{the species data; usually a data frame.} + \item{dc}{character; the set of dissimilarity coefficients for which + rank correlations with gradient distance are to be computed.} + \item{method}{character; the correlation method to use. See the + \code{method} argument of \code{\link{cor}}.} + \item{x}{an object of class \code{"rankDC"}.} + \item{data}{NULL; ignored, only present for purposes of conformance to + generic definition.} + \item{sort, decreasing}{logical; should observations be sorted prior + to plotting? If so, should they be sorted in order of decreasing + size?} + \item{xlab}{The x-axis label for the plot.} + \item{color, pch, bg, lcolor, lty}{arguments passed to + \code{\link{dotchart}}.} + \item{\dots}{arguments passed to other methods, including + \code{\link{dotchart}} and \code{\link[lattice]{dotplot}}.} +} +%%\details{ +%% ~~ If necessary, more details than the description above ~~ +%%} +\value{ + A named vector of rank correlations is returned. +} +\author{Gavin L. Simpson, based on \code{\link{rankindex}} from the + vegan package.} + +\seealso{ + \code{\link{rankindex}} from package vegan. +} +\examples{ +data(swappH) +data(swapdiat) + +rc <- rankDC(swappH, swapdiat, dc = c("chord","euclidean","gower")) + +## base plot uses dotchart() +plot(rc) + +## lattice version of the base plot +dotplot(rc) + +} +% Add one or more standard keywords, see file 'KEYWORDS' in the +% R documentation directory. +\keyword{ hplot } +\keyword{ methods } +\keyword{ utilities } +\keyword{ multivariate } From noreply at r-forge.r-project.org Wed May 22 16:53:45 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 22 May 2013 16:53:45 +0200 (CEST) Subject: [Analogue-commits] r331 - pkg/tests/Examples Message-ID: <20130522145345.E8760185551@r-forge.r-project.org> Author: gsimpson Date: 2013-05-22 16:53:45 +0200 (Wed, 22 May 2013) New Revision: 331 Modified: pkg/tests/Examples/analogue-Ex.Rout.save Log: update examples to latest current dev release checks Modified: pkg/tests/Examples/analogue-Ex.Rout.save =================================================================== --- pkg/tests/Examples/analogue-Ex.Rout.save 2013-05-22 14:53:00 UTC (rev 330) +++ pkg/tests/Examples/analogue-Ex.Rout.save 2013-05-22 14:53:45 UTC (rev 331) @@ -1,8 +1,7 @@ -R version 2.15.3 RC (2013-02-25 r62062) -- "Security Blanket" +R version 3.0.1 (2013-05-16) -- "Good Sport" Copyright (C) 2013 The R Foundation for Statistical Computing -ISBN 3-900051-07-0 -Platform: x86_64-unknown-linux-gnu (64-bit) +Platform: x86_64-pc-linux-gnu (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. @@ -24,12 +23,12 @@ > library('analogue') Loading required package: vegan Loading required package: permute -This is vegan 2.0-6 +This is vegan 2.0-7 Loading required package: princurve Loading required package: lattice -This is analogue 0.11-2 +This is analogue 0.11-3 > -> assign(".oldSearch", search(), pos = 'CheckExEnv') +> base::assign(".oldSearch", base::search(), pos = 'CheckExEnv') > cleanEx() > nameEx("ImbrieKipp") > ### * ImbrieKipp @@ -408,7 +407,7 @@ > > ### Name: analog > ### Title: Analogue matching -> ### Aliases: analog analog.default print.analog +> ### Aliases: analog analog.default analog.distance print.analog > ### Keywords: multivariate > > ### ** Examples @@ -790,9 +789,49 @@ 0.911 > +> ## Can take pre-computed dissimilarity objects +> d1 <- distance(ImbrieKipp, V12.122) +> d2 <- distance(ImbrieKipp) +> ik <- analog(d1, d2, keep.train = TRUE) +> ik + + Analogue matching for fossil samples + +Call: analog(x = d1, train = d2, keep.train = TRUE) +Dissimilarity: euclidean + +Percentiles of the dissimilarities for the training set: + + 1% 2% 5% 10% 20% +0.0669 0.0956 0.1304 0.1739 0.2341 + + Minimum dissimilarity per sample + +Dissimilarity: euclidean + + 0 10 20 30 40 50 60 70 80 90 100 110 120 +0.296 0.296 0.296 0.296 0.296 0.296 0.296 0.296 0.296 0.296 0.296 0.296 0.296 + 130 140 150 160 170 180 190 200 210 220 230 240 250 +0.296 0.296 0.296 0.296 0.296 0.296 0.296 0.296 0.296 0.297 0.296 0.297 0.296 + 260 270 280 290 300 310 320 330 340 350 360 370 380 +0.296 0.297 0.296 0.297 0.296 0.297 0.296 0.296 0.296 0.296 0.296 0.296 0.296 + 390 400 410 420 430 440 450 460 470 480 490 500 510 +0.296 0.296 0.296 0.296 0.296 0.296 0.297 0.296 0.296 0.296 0.297 0.296 0.297 + 520 530 540 550 560 570 580 590 600 610 620 630 640 +0.296 0.296 0.295 0.296 0.296 0.296 0.296 0.296 0.296 0.297 0.297 0.296 0.297 + 650 660 670 680 690 700 710 720 730 740 750 760 770 +0.296 0.296 0.296 0.297 0.296 0.296 0.296 0.296 0.297 0.296 0.297 0.296 0.296 + 780 790 800 810 820 830 840 850 860 870 880 890 900 +0.297 0.297 0.296 0.296 0.297 0.296 0.296 0.296 0.296 0.296 0.296 0.296 0.296 + 910 920 930 940 950 960 970 980 990 1000 1010 1020 1030 +0.296 0.296 0.296 0.296 0.296 0.296 0.296 0.296 0.296 0.296 0.297 0.296 0.296 + 1040 1050 1060 1070 1080 1090 +0.296 0.296 0.297 0.296 0.296 0.296 + > > > +> > cleanEx() > nameEx("bayesF") > ### * bayesF @@ -1223,7 +1262,7 @@ > > ### Name: chooseTaxa > ### Title: Select taxa (variables) on basis of maximum abundance attained -> ### and number of occurrences +> ### and number of occurrences. > ### Aliases: chooseTaxa chooseTaxa.default > ### Keywords: methods multivariate > @@ -1236,8 +1275,17 @@ > dim(IK2) [1] 61 27 > +> ## return a logical vector to select species/columns +> chooseTaxa(ImbrieKipp, n.occ = 5, value = FALSE) + O.univ G.cglob G.ruber G.tenel G.saccu G.rubes G.pacL G.pacR G.bullo G.falco + TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE +G.calid G.aequi G.gluti G.duter G.infla G.trnL G.trnR G.crasf G.scitu G.mentu + TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE +P.obliq C.nitid S.dehis G.digit Other G.quin G.hirsu + TRUE TRUE TRUE TRUE TRUE TRUE TRUE > > +> > cleanEx() > nameEx("cma") > ### * cma @@ -2297,6 +2345,7 @@ ..$ : chr [1:20] "A" "B" "C" "D" ... ..$ : chr [1:10] "a" "b" "c" "d" ... - attr(*, "method")= chr "euclidean" + - attr(*, "type")= chr "asymmetric" - attr(*, "class")= chr [1:2] "distance" "matrix" > > ## calculate Gower's general coefficient for mixed data @@ -2315,6 +2364,8 @@ [1] 0.3380952 attr(,"method") [1] "mixed" +attr(,"type") +[1] "asymmetric" attr(,"class") [1] "distance" "matrix" > @@ -2333,7 +2384,7 @@ > > ### Name: distance3 > ### Title: Flexibly calculate dissimilarity or distance measures -> ### Aliases: distance3 distance3.default +> ### Aliases: distance3 distanceX distance3.default > ### Keywords: multivariate methods > > ### ** Examples @@ -2364,6 +2415,8 @@ > ## Using distance on an object of class join > #dists <- distance3(join(train, fossil)) > #str(dists) +> dists <- distance(join(train, fossil)) +> ##distsX <- distanceX(join(train, fossil)) > > ## calculate Gower's general coefficient for mixed data > ## first, make a couple of variables factors @@ -2382,12 +2435,16 @@ [1,] 0.3380952 attr(,"method") [1] "mixed" +attr(,"type") +[1] "asymmetric" attr(,"class") [1] "distance" "matrix" > distance(x1, x2, method = "mixed", R = Rj) [1] 0.3380952 attr(,"method") [1] "mixed" +attr(,"type") +[1] "asymmetric" attr(,"class") [1] "distance" "matrix" > @@ -5044,7 +5101,7 @@ > ## the model performance statistics > performance(mod) RMSE R2 Avg.Bias Max.Bias - 2.019e+00 9.173e-01 2.228e-14 -3.815e+00 + 2.019e+00 9.173e-01 2.854e-15 -3.815e+00 > > > @@ -6008,7 +6065,7 @@ + vary = FALSE, penalty = 1.4) -------------------------------------------------------------------------------- Initial curve: d.sq: 103233.4502 -Iteration 1: d.sq: 4853.7912 +Iteration 1: d.sq: 4853.7911 Iteration 2: d.sq: 5013.4971 Iteration 3: d.sq: 5109.9732 Iteration 4: d.sq: 5135.6541 @@ -6205,6 +6262,34 @@ > > > cleanEx() +> nameEx("rankDC") +> ### * rankDC +> +> flush(stderr()); flush(stdout()) +> +> ### Name: rankDC +> ### Title: Rank correlation between environmental and species +> ### dissimilarities. +> ### Aliases: rankDC print.rankDC plot.rankDC dotplot.rankDC +> ### Keywords: hplot methods utilities multivariate +> +> ### ** Examples +> +> data(swappH) +> data(swapdiat) +> +> rc <- rankDC(swappH, swapdiat, dc = c("chord","euclidean","gower")) +> +> ## base plot uses dotchart() +> plot(rc) +> +> ## lattice version of the base plot +> dotplot(rc) +> +> +> +> +> cleanEx() > nameEx("reconPlot") > ### * reconPlot > @@ -6424,6 +6509,62 @@ > > > cleanEx() +> nameEx("scores.prcurve") +> ### * scores.prcurve +> +> flush(stderr()); flush(stdout()) +> +> ### Name: scores.prcurve +> ### Title: 'scores' method for principal curve objects of class +> ### '"prcurve"'. +> ### Aliases: scores.prcurve +> ### Keywords: methods +> +> ### ** 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) +-------------------------------------------------------------------------------- +Initial curve: d.sq: 103233.4502 +Iteration 1: d.sq: 4283.4308 +Iteration 2: d.sq: 4312.2976 +Iteration 3: d.sq: 4340.6911 +Iteration 4: d.sq: 4355.3876 +Iteration 5: d.sq: 4366.4975 +Iteration 6: d.sq: 4369.9444 +-------------------------------------------------------------------------------- +PC Converged in 6 iterations. +-------------------------------------------------------------------------------- +> +> ## Extract position on the curve +> pos <- scores(aber.pc, display = "curve") +> head(pos) + PrC +1 251.3134 +2 253.7651 +3 273.9467 +4 267.3053 +5 286.3480 +6 277.9563 +> +> ## Extract the coordinates of the curve +> coord <- scores(aber.pc, display = "dimensions") +> dim(coord) +[1] 49 36 +> all.equal(dim(coord), dim(abernethy2)) +[1] TRUE +> +> +> +> cleanEx() > nameEx("screeplot") > ### * screeplot > @@ -6565,6 +6706,46 @@ > > > cleanEx() +> nameEx("sppResponse.prcurve") +> ### * sppResponse.prcurve +> +> flush(stderr()); flush(stdout()) +> +> ### Name: sppResponse +> ### Title: Species responses along gradients. +> ### Aliases: sppResponse sppResponse.prcurve +> ### Keywords: methods +> +> ### ** 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) +-------------------------------------------------------------------------------- +Initial curve: d.sq: 103233.4502 +Iteration 1: d.sq: 4283.4308 +Iteration 2: d.sq: 4312.2976 +Iteration 3: d.sq: 4340.6911 +Iteration 4: d.sq: 4355.3876 +Iteration 5: d.sq: 4366.4975 +Iteration 6: d.sq: 4369.9444 +-------------------------------------------------------------------------------- +PC Converged in 6 iterations. +-------------------------------------------------------------------------------- +> +> ## Extract the fitted species response curves +> resp <- sppResponse(aber.pc) +> +> +> +> cleanEx() > nameEx("stdError") > ### * stdError > @@ -7416,8 +7597,9 @@ > > ### *