[Vegan-commits] r2501 - in pkg/vegan: R inst man src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun May 5 19:36:48 CEST 2013
Author: jarioksa
Date: 2013-05-05 19:36:48 +0200 (Sun, 05 May 2013)
New Revision: 2501
Modified:
pkg/vegan/R/vegdist.R
pkg/vegan/inst/ChangeLog
pkg/vegan/man/vegdist.Rd
pkg/vegan/src/vegdist.c
Log:
add Mahalanobis to vegdist
Modified: pkg/vegan/R/vegdist.R
===================================================================
--- pkg/vegan/R/vegdist.R 2013-05-05 17:07:39 UTC (rev 2500)
+++ pkg/vegan/R/vegdist.R 2013-05-05 17:36:48 UTC (rev 2501)
@@ -7,7 +7,8 @@
method <- "euclidean"
METHODS <- c("manhattan", "euclidean", "canberra", "bray",
"kulczynski", "gower", "morisita", "horn", "mountford",
- "jaccard", "raup", "binomial", "chao", "altGower", "cao")
+ "jaccard", "raup", "binomial", "chao", "altGower", "cao",
+ "mahalanobis")
method <- pmatch(method, METHODS)
inm <- METHODS[method]
if (is.na(method))
@@ -25,6 +26,8 @@
dQuote(inm))
if (method == 6) # gower, but no altGower
x <- decostand(x, "range", 2, na.rm = TRUE, ...)
+ if (method == 16) # mahalanobis
+ x <- veganMahatrans(scale(x, scale = FALSE))
if (binary)
x <- decostand(x, "pa")
N <- nrow(x <- as.matrix(x))
Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog 2013-05-05 17:07:39 UTC (rev 2500)
+++ pkg/vegan/inst/ChangeLog 2013-05-05 17:36:48 UTC (rev 2501)
@@ -22,6 +22,8 @@
variance (Euclidean) or range (Manhattan), and the scaling is
already inbuilt in Mahalanobis and Gower.
+ * vegdist: added Mahalanobis distance.
+
Version 2.1-29 (closed April 19, 2013)
* ordisurf: significant changes were made to this function:
Modified: pkg/vegan/man/vegdist.Rd
===================================================================
--- pkg/vegan/man/vegdist.Rd 2013-05-05 17:07:39 UTC (rev 2500)
+++ pkg/vegan/man/vegdist.Rd 2013-05-05 17:36:48 UTC (rev 2501)
@@ -28,7 +28,7 @@
\code{"euclidean"}, \code{"canberra"}, \code{"bray"}, \code{"kulczynski"},
\code{"jaccard"}, \code{"gower"}, \code{"altGower"}, \code{"morisita"},
\code{"horn"}, \code{"mountford"}, \code{"raup"} , \code{"binomial"},
- \code{"chao"} or \code{"cao"}.}
+ \code{"chao"}, \code{"cao"} or \code{"mahalanobis"}.}
\item{binary}{Perform presence/absence standardization before analysis
using \code{\link{decostand}}.}
\item{diag}{Compute diagonals. }
@@ -209,6 +209,13 @@
Morisita index can be used with genuine count data (integers) only. Its
Horn--Morisita variant is able to handle any abundance data.
+ Mahalanobis distances are Euclidean distances of a matrix where
+ columns are centred, have unit variance, and are uncorrelated. The
+ index is not commonly used for community data, but it is sometimes
+ used for environmental variables. The calculation is based on
+ transforming data matrix and then using Euclidean distances
+ following Mardia et al. (1979).
+
Euclidean and Manhattan dissimilarities are not good in gradient
separation without proper standardization but are still included for
comparison and special needs.
@@ -272,6 +279,9 @@
Krebs, C. J. (1999). \emph{Ecological Methodology.} Addison Wesley Longman.
+ Mardia, K.V., Kent, J.T. and Bibby, J.M. (1979). \emph{Multivariate analysis}.
+ Academic Press.
+
Mountford, M. D. (1962). An index of similarity and its application to
classification problems. In: P.W.Murphy (ed.),
\emph{Progress in Soil Zoology}, 43--50. Butterworths.
Modified: pkg/vegan/src/vegdist.c
===================================================================
--- pkg/vegan/src/vegdist.c 2013-05-05 17:07:39 UTC (rev 2500)
+++ pkg/vegan/src/vegdist.c 2013-05-05 17:36:48 UTC (rev 2501)
@@ -44,6 +44,7 @@
#define CHAO 13
#define GOWERDZ 14
#define CAO 15
+#define MAHALANOBIS 16
#define MATCHING 50
#define NOSHARED 99
@@ -125,7 +126,9 @@
return dist;
}
-/* Euclidean distance: duplicates base R */
+/* Euclidean distance: duplicates base R. If Mahalanobis
+ * transformation was performred in the calling routine, this will
+ * give Mahalanobis distances. */
double veg_euclidean(double *x, int nr, int nc, int i1, int i2)
{
@@ -631,6 +634,7 @@
distfun = veg_manhattan;
break;
case EUCLIDEAN:
+ case MAHALANOBIS:
distfun = veg_euclidean;
break;
case CANBERRA:
More information about the Vegan-commits
mailing list