[Vegan-commits] r1752 - pkg/permute/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Aug 24 10:02:46 CEST 2011


Author: gsimpson
Date: 2011-08-24 10:02:46 +0200 (Wed, 24 Aug 2011)
New Revision: 1752

Modified:
   pkg/permute/R/shuffleSet.R
Log:
now handles permuting strata or within strata, only permuting both strata and within now needed

Modified: pkg/permute/R/shuffleSet.R
===================================================================
--- pkg/permute/R/shuffleSet.R	2011-08-24 08:01:10 UTC (rev 1751)
+++ pkg/permute/R/shuffleSet.R	2011-08-24 08:02:46 UTC (rev 1752)
@@ -1,8 +1,8 @@
 `shuffleSet` <- function(n, nset = 1, control = permControl()) {
     Set <- matrix(nrow = nset, ncol = n)
-    ## If no strata then permute all samples using stated scheme
     WI <- getWithin(control)
     if(is.null(getStrata(control))) {
+        ## If no strata then permute all samples using stated scheme
         Args <- switch(WI$type,
                        "free" = list(x = n, size = n),
                        "series" = list(x = seq_len(n), mirror = WI$mirror),
@@ -20,7 +20,32 @@
             }
         }
     } else {
-        .NotYetImplemented()
+        ## If strata present, either permute samples, strata or both
+        BL <- getBlocks(control)
+
+        ## permute strata?
+        if(BL$type == "none") {
+            Set <- rep(seq_len(n), each = nset)
+        } else {
+            for(i in seq_len(nset)) {
+                Set[i,] <- do.call(shuffleStrata,
+                                   list(strata = control$strata, type = BL$type,
+                                        mirror = BL$mirror, flip = NULL,
+                                        nrow = BL$nrow, ncol = BL$ncol))
+            }
+        }
+
+        ## permute the samples within strata?
+        if(WI$type != "none") {
+            tab <- table(getStrat(control)[out])
+            ## the levels of the strata
+            inds <- names(tab)
+            ## same permutation within each level of strata?
+            for(i in seq_len(nset)) {
+
+            }
+            .NotYetImplemented()
+        }
     }
     Set
 }



More information about the Vegan-commits mailing list