[Vegan-commits] r1288 - in pkg/vegan: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Aug 27 18:46:12 CEST 2010
Author: psolymos
Date: 2010-08-27 18:46:12 +0200 (Fri, 27 Aug 2010)
New Revision: 1288
Modified:
pkg/vegan/R/rankindex.R
pkg/vegan/man/rankindex.Rd
Log:
rankindex accepts list of functions as indices arg
Modified: pkg/vegan/R/rankindex.R
===================================================================
--- pkg/vegan/R/rankindex.R 2010-08-26 09:34:01 UTC (rev 1287)
+++ pkg/vegan/R/rankindex.R 2010-08-27 16:46:12 UTC (rev 1288)
@@ -12,15 +12,39 @@
}
veg <- as.matrix(veg)
res <- numeric(length(indices))
- names(res) <- indices
- for (i in indices) {
- y <- vegdist(veg, i)
- if (stepacross) {
- is.na(y) <- no.shared(veg)
- y <- stepacross(y, trace = FALSE, toolong = -1, ...)
+ ## create names if indices is a list of functions without names
+ if (is.list(indices)) {
+ nam <- names(indices)
+ if (is.null(nam))
+ nam <- paste("dis", 1:length(idices), sep="")
+ } else nam <- indices
+ names(res) <- nam
+ ## indices is a list of functions which return dist objects
+ if (is.list(indices)) {
+ for (i in 1:length(indices)) {
+ ## don't accept similarities
+ if (indices[[i]](matrix(1, 2, 2)) != 0)
+ stop("define dissimilarity and not similarity")
+ y <- indices[[i]](veg)
+ ## check class of output
+ if (!inherits(y, "dist"))
+ stop("function in 'indices' must return a 'dist' object")
+ if (stepacross) {
+ is.na(y) <- no.shared(veg)
+ y <- stepacross(y, trace = FALSE, toolong = -1, ...)
+ }
+ res[i] <- cor(span, y, method = method)
}
- res[i] <- cor(span, y, method = method)
+ ## indices is a character vector naming methods in vegdist
+ } else {
+ for (i in indices) {
+ y <- vegdist(veg, i)
+ if (stepacross) {
+ is.na(y) <- no.shared(veg)
+ y <- stepacross(y, trace = FALSE, toolong = -1, ...)
+ }
+ res[i] <- cor(span, y, method = method)
+ }
}
res
}
-
Modified: pkg/vegan/man/rankindex.Rd
===================================================================
--- pkg/vegan/man/rankindex.Rd 2010-08-26 09:34:01 UTC (rev 1287)
+++ pkg/vegan/man/rankindex.Rd 2010-08-27 16:46:12 UTC (rev 1288)
@@ -15,7 +15,9 @@
\item{grad}{The gradient variable or matrix. }
\item{veg}{The community data matrix. }
\item{indices}{Dissimilarity indices compared, partial matches to
- alternatives in \code{\link{vegdist}}.}
+ alternatives in \code{\link{vegdist}}.
+ Alternatively, it can be a (named) list of functions returning
+ objects of class 'dist'.}
\item{stepacross}{Use \code{\link{stepacross}} to find
a shorter path dissimilarity. The dissimilarities for site pairs
with no shared species are set \code{NA} using
@@ -33,6 +35,14 @@
point is assessed as Euclidean distance for continuous variables, and
as Gower metric for mixed data using function
\code{\link[cluster]{daisy}} when \code{grad} has factors.
+
+ The \code{indices} argument can accept any dissimilarity
+ indices besides the ones calculated by the
+ \code{\link{vegdist}} function. For this, the argument value
+ should be a (possibly named) list of functions.
+ Each function must return a valid 'dist' object with dissimilarities,
+ similarities are not accepted and should be converted into dissimilarities
+ beforehand.
}
\value{
Returns a named vector of rank correlations.
@@ -40,7 +50,7 @@
\references{ Faith, F.P., Minchin, P.R. and Belbin,
L. (1987). Compositional dissimilarity as a robust measure of
ecological distance. \emph{Vegetatio} 69, 57-68. }
-\author{Jari Oksanen }
+\author{Jari Oksanen, with additions from Peter Solymos}
\note{
There are several problems in using rank correlation coefficients.
Typically there are very many ties when \eqn{n(n-1)/2} gradient
@@ -59,6 +69,11 @@
Earlier version of this function used \code{method = "kendall"}, but
that is far too slow in large data sets.
+
+ The functions returning dissimilarity objects ahould be self contained,
+ because the \code{...} argument passes additional parameters
+ to \code{\link{stepacross}} and not to the functions supplied
+ via the \code{indices} argument.
}
\seealso{\code{\link{vegdist}}, \code{\link{stepacross}},
@@ -74,5 +89,10 @@
## Some would use PCA transformation.
rankindex(scale(varechem), varespec)
rankindex(scale(varechem), wisconsin(varespec))
+## Using non vegdist indices as functions
+funs <- list(Manhattan=function(x) dist(x, "manhattan"),
+ Gower=function(x) daisy(x, "gower"),
+ Ochiai=function(x) designdist(x, "1-J/sqrt(A*B)"))
+rankindex(scale(varechem), varespec, funs)
}
\keyword{ multivariate }
More information about the Vegan-commits
mailing list