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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Mar 15 11:19:28 CET 2010


Author: jarioksa
Date: 2010-03-15 11:19:27 +0100 (Mon, 15 Mar 2010)
New Revision: 1176

Modified:
   pkg/vegan/R/permutest.cca.R
   pkg/vegan/inst/ChangeLog
Log:
speed-up (2x) in CCA and pCCA by using compiled code in re-weighting

Modified: pkg/vegan/R/permutest.cca.R
===================================================================
--- pkg/vegan/R/permutest.cca.R	2010-03-14 11:24:39 UTC (rev 1175)
+++ pkg/vegan/R/permutest.cca.R	2010-03-15 10:19:27 UTC (rev 1176)
@@ -51,26 +51,36 @@
     else E <- x$CA$Xbar
     if (isPartial && model == "direct") 
         E <- E + Y.Z
+    ## Save dimensions
     N <- nrow(E)
+    if (isCCA) {
+        Xcol <- ncol(X)
+        if (isPartial)
+            Zcol <- ncol(Z)
+    }
     if (!exists(".Random.seed", envir = .GlobalEnv, inherits = FALSE)) 
         runif(1)
     seed <- get(".Random.seed", envir = .GlobalEnv, inherits = FALSE)
     for (i in 1:permutations) {
         take <- permuted.index(N, strata)
         Y <- E[take, ]
+        if (isCCA)
+            wtake <- w[take]
         if (isPartial) {
             if (isCCA) {
-                wm <- colSums(sweep(Z, 1, w[take], "*"))
-                XZ <- sweep(Z, 2, wm, "-")
-                XZ <- sweep(XZ, 1, sqrt(w[take]), "*")
+                XZ <- .C("wcentre", x = as.double(Z), as.double(wtake),
+                         as.integer(N), as.integer(Zcol),
+                         PACKAGE = "vegan")$x
+                dim(XZ) <- c(N, Zcol)
                 QZ <- qr(XZ)
             }
             Y <- qr.resid(QZ, Y)
         }
         if (isCCA) {
-            wm <- colSums(sweep(X, 1, w[take], "*"))
-            XY <- sweep(X, 2, wm, "-")
-            XY <- sweep(XY, 1, sqrt(w[take]), "*")
+            XY <- .C("wcentre", x = as.double(X), as.double(wtake),
+                     as.integer(N), as.integer(Xcol),
+                     PACKAGE = "vegan")$x
+            dim(XY) <- c(N, Xcol)
             Q <- qr(XY)
         }
         tmp <- qr.fitted(Q, Y)

Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog	2010-03-14 11:24:39 UTC (rev 1175)
+++ pkg/vegan/inst/ChangeLog	2010-03-15 10:19:27 UTC (rev 1176)
@@ -15,6 +15,11 @@
 	Pierre Legendre had with biplot.rda(), and makes redundant the
 	name checking code in summary.cca (the redundant code was not yet
 	removed, but I see that this fix here was sound).
+
+	* permutest.cca: re-weighting of permuted CCA data matrix is now
+	done with compiled code using existing C function 'wcentre' (in
+	goffactor.c). This may give huge speed-up (>50% time save in first
+	tests) both in CCA and pCCA. 
 	
 Version 1.18-2 (closed March 8, 2010)
 



More information about the Vegan-commits mailing list