[Analogue-commits] r330 - in pkg: . R inst man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed May 22 16:53:00 CEST 2013
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 }
More information about the Analogue-commits
mailing list