[Vegan-commits] r1213 - in pkg/vegan: R inst

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jun 1 13:22:27 CEST 2010


Author: jarioksa
Date: 2010-06-01 13:22:26 +0200 (Tue, 01 Jun 2010)
New Revision: 1213

Modified:
   pkg/vegan/R/mantel.R
   pkg/vegan/R/mantel.partial.R
   pkg/vegan/inst/ChangeLog
Log:
considerable (2x) speed-up in mantel & mantel.partial by polishing innermost loop

Modified: pkg/vegan/R/mantel.R
===================================================================
--- pkg/vegan/R/mantel.R	2010-06-01 11:04:01 UTC (rev 1212)
+++ pkg/vegan/R/mantel.R	2010-06-01 11:22:26 UTC (rev 1213)
@@ -10,10 +10,13 @@
     if (permutations) {
         N <- attributes(xdis)$Size
         perm <- rep(0, permutations)
+        ## asdist asn an index selects lower diagonal like as.dist,
+        ## but is faster since it does not seet 'dist' attributes
         xmat <- as.matrix(xdis)
+        asdist <- row(xmat) > col(xmat)
         for (i in 1:permutations) {
             take <- permuted.index(N, strata)
-            permvec <- as.dist(xmat[take, take])
+            permvec <- (xmat[take, take])[asdist]
             perm[i] <- cor(permvec, ydis, method = method)
         }
         signif <- (sum(perm >= statistic) + 1)/(permutations + 1)

Modified: pkg/vegan/R/mantel.partial.R
===================================================================
--- pkg/vegan/R/mantel.partial.R	2010-06-01 11:04:01 UTC (rev 1212)
+++ pkg/vegan/R/mantel.partial.R	2010-06-01 11:22:26 UTC (rev 1213)
@@ -18,9 +18,10 @@
         N <- attributes(xdis)$Size
         perm <- rep(0, permutations)
         xmat <- as.matrix(xdis)
+        asdist <- row(xmat) > col(xmat)
         for (i in 1:permutations) {
             take <- permuted.index(N, strata)
-            permvec <- as.dist(xmat[take, take])
+            permvec <- (xmat[take, take])[asdist]
             rxy <- cor(permvec, ydis, method = method)
             rxz <- cor(permvec, zdis, method = method)
             perm[i] <- part.cor(rxy, rxz, ryz)

Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog	2010-06-01 11:04:01 UTC (rev 1212)
+++ pkg/vegan/inst/ChangeLog	2010-06-01 11:22:26 UTC (rev 1213)
@@ -4,6 +4,10 @@
 
 Versin 1.18-6 (opened May 31, 2010)
 
+	* mantel, mantel.partial: considerable speed up by cleaning
+	innermost loop and replacing as.dist() with direct extraction of
+	lower diagonal. 
+
 	* treedist: documenting tree dissimilarity function that has been
 	in vegan devel since Aug 17, 2009 (rev928).
 	



More information about the Vegan-commits mailing list