[Vegan-commits] r2695 - in pkg/vegan: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Nov 10 16:08:25 CET 2013


Author: jarioksa
Date: 2013-11-10 16:08:25 +0100 (Sun, 10 Nov 2013)
New Revision: 2695

Modified:
   pkg/vegan/R/anovacca.R
   pkg/vegan/man/anovacca.Rd
Log:
add permute support to anovacca

Modified: pkg/vegan/R/anovacca.R
===================================================================
--- pkg/vegan/R/anovacca.R	2013-11-10 14:20:42 UTC (rev 2694)
+++ pkg/vegan/R/anovacca.R	2013-11-10 15:08:25 UTC (rev 2695)
@@ -1,5 +1,6 @@
 `anovacca` <-
-    function(object, ..., permutations = how(nperm=999), by = NULL) 
+    function(object, ..., permutations = how(nperm=999), by = NULL,
+             strata = NULL) 
 {
     if (is.null(object$CA) || is.null(object$CCA) ||
         object$CCA$rank == 0 || object$CA$rank == 0)
@@ -8,10 +9,33 @@
         by <- match.arg(by, c("axis", "terms", "margin"))
         .NotYetUsed("by")
     }
-    seed <- NULL
+    if (!exists(".Random.seed", envir = .GlobalEnv,
+                inherits = FALSE)) 
+        runif(1)
+    seed <- get(".Random.seed", envir = .GlobalEnv, inherits = FALSE)
+    ## permutations is either a single number, a how() structure or a
+    ## permutation matrix
+    if (length(permutations) == 1) {
+        nperm <- permutations
+        permutations <- how(nperm = nperm)
+    }
+    if (!is.null(strata)) {
+        if (!inherits(permutations, "how"))
+            stop("'strata' can be used only with simple permutation or with 'how()'")
+        if (!is.null(permutations$block))
+            stop("'strata' cannot be applied when 'blocks' are defined in 'how()'")
+        permutations <- update(permutations, blocks = strata)
+    }
+    ## now permutations is either a how() structure or a permutation
+    ## matrix. Make it to a matrix if it is "how"
+    if (inherits(permutations, "how"))
+        permutations <- shuffleSet(nrow(object$CCA$u),
+                                   control = permutations)
+    else # we got a permutation matrix and seed is unknown
+        seed <- NA
+    nperm <- nrow(permutations)
+    ## stop permutations block
     tst <- permutest.cca(object, permutations = permutations, ...)
-    if (is.null(seed)) 
-        seed <- tst$Random.seed
     Fval <- c(tst$F.0, NA)
     Pval <- (sum(tst$F.perm >= tst$F.0) + 1)/(tst$nperm + 1)
     Pval <- c(Pval, NA)

Modified: pkg/vegan/man/anovacca.Rd
===================================================================
--- pkg/vegan/man/anovacca.Rd	2013-11-10 14:20:42 UTC (rev 2694)
+++ pkg/vegan/man/anovacca.Rd	2013-11-10 15:08:25 UTC (rev 2695)
@@ -23,7 +23,7 @@
 
 \usage{
 anovacca(object, ..., permutations = how(nperm=999),
-      by = NULL)
+      by = NULL, strata = NULL)
 }
 
 \arguments{
@@ -43,6 +43,14 @@
     the terms (each marginal term analysed in a model with all other
     variables). Not yet implemented.}
 
+  \item{strata}{An integer vector or factor specifying the strata for
+    permutation. If supplied, observations are permuted only within
+    the specified strata. It is an error to use this when
+    \code{permutations} is a matrix, or a \code{\link[permute]{how}}
+    defines \code{blocks}. This is a legacy argument that will be
+    deprecated in the future: use 
+    \code{permutations = how(\dots, blocks)} instead. }
+
   \item{\dots}{Parameters passed to other functions.  \code{anova.cca}
     passes all arguments to \code{permutest.cca}. In \code{anova} with
     \code{by = "axis"} you can use argument \code{cutoff} (defaults



More information about the Vegan-commits mailing list