[Vegan-commits] r292 - in pkg: R inst

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Mar 29 17:14:57 CET 2008


Author: gsimpson
Date: 2008-03-29 17:14:56 +0100 (Sat, 29 Mar 2008)
New Revision: 292

Modified:
   pkg/R/permuted.index2.R
   pkg/inst/ChangeLog
Log:
permuted.index2 was not consitently mirroring series and grid designs when 'constant = TRUE'

Modified: pkg/R/permuted.index2.R
===================================================================
--- pkg/R/permuted.index2.R	2008-03-29 14:54:53 UTC (rev 291)
+++ pkg/R/permuted.index2.R	2008-03-29 16:14:56 UTC (rev 292)
@@ -10,7 +10,9 @@
             unname(do.call(c, sp[.Internal(sample(lev, lev, FALSE, NULL))]))
         }
     `permuted.grid` <-
-        function(nrow, ncol, mirror = FALSE, start.row = NULL, start.col = NULL)
+        function(nrow, ncol, mirror = FALSE,
+                 start.row = NULL, start.col = NULL,
+                 flip = NULL)
         {
             if(is.null(start.row))
                 start.row <- .Internal(sample(nrow, 1, FALSE, NULL))
@@ -18,22 +20,37 @@
                 start.col <- .Internal(sample(ncol, 1, FALSE, NULL))
             ir <- seq(start.row, length=nrow) %% nrow
             ic <- seq(start.col, length=ncol) %% ncol
-            if (mirror) {
-                if (runif(1) < 0.5)
-                    ir <- rev(ir)
-                if (runif(1) < 0.5)
-                    ic <- rev(ic)
+            if(!is.null(flip)) {
+                if(any(flip)) {
+                    if(flip[1])
+                        ir <- rev(ir)
+                    if(flip[2])
+                        ic <- rev(ic)
+                }
+            } else {
+                if (mirror) {
+                    if (runif(1) < 0.5)
+                        ir <- rev(ir)
+                    if (runif(1) < 0.5)
+                        ic <- rev(ic)
+                }
             }
             rep(ic, each=nrow) * nrow + rep(ir, len=nrow*ncol) + 1
         }
-    `permuted.series` <- function(inds, mirror = FALSE, start = NULL)
+    `permuted.series` <- function(inds, mirror = FALSE,
+                                  start = NULL, flip=NULL)
     {
         n <- length(inds)
         if(is.null(start))
             start <- .Internal(sample(n, 1, FALSE, NULL))
         out <- seq(start, length = n) %% n + 1
-        if(mirror && runif(1) < 0.5)
-            out <- rev(out)
+        if(!is.null(flip)) {
+            if(flip)
+                out <- rev(out)
+        } else {
+            if(mirror && runif(1) < 0.5)
+                out <- rev(out)
+        }
         inds[out]
     }
     if (is.null(control$strata)) {
@@ -51,12 +68,14 @@
         if(control$constant) {
             if(control$type == "series") {
                 start <- .Internal(sample(n / length(inds), 1, FALSE, NULL))
+                flip <- runif(1) < 0.5
             } else if(control$type == "grid") {
                 start.row <- .Internal(sample(control$nrow, 1, FALSE, NULL))
                 start.col <- .Internal(sample(control$ncol, 1, FALSE, NULL))
+                flip <- runif(2) < 0.5
             }
         } else {
-            start <- start.row <- start.col <- NULL
+            start <- start.row <- start.col <- flip <- NULL
         }
         for (is in inds) {
             gr <- out[control$strata == is]
@@ -65,12 +84,14 @@
                                   "free" = out[gr][.Internal(sample(n.gr, n.gr,
                                   FALSE, NULL))],
                                   "series" = permuted.series(gr,
-                                  mirror = control$mirror, start = start),
+                                  mirror = control$mirror, start = start,
+                                  flip = flip),
                                   "grid" = gr[permuted.grid(nrow = control$nrow,
                                   ncol = control$ncol,
                                   mirror = control$mirror,
                                   start.row = start.row,
-                                  start.col = start.col)]
+                                  start.col = start.col,
+                                  flip = flip)]
                                   )
             }
         }

Modified: pkg/inst/ChangeLog
===================================================================
--- pkg/inst/ChangeLog	2008-03-29 14:54:53 UTC (rev 291)
+++ pkg/inst/ChangeLog	2008-03-29 16:14:56 UTC (rev 292)
@@ -5,7 +5,10 @@
 Version 1.12-7 (opened Mar 25, 2008)
 
 	* permuted.index2: was not returning correct sample indices
-	for grid designs within strata.
+	for grid designs within strata. Also,was not consitently 
+	mirroring series and grid designs when 'constant = TRUE' (i.e. 
+	mirroring was not applied the same way within each level of 
+	strata).
 
 	* screeplot: functions return now invisibly the xy.coords of
 	bars or points for eigenvalues. They used to return



More information about the Vegan-commits mailing list