[Vegan-commits] r283 - in pkg: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Mar 25 15:21:14 CET 2008


Author: gsimpson
Date: 2008-03-25 15:21:14 +0100 (Tue, 25 Mar 2008)
New Revision: 283

Modified:
   pkg/R/numPerms.R
   pkg/man/permCheck.Rd
Log:
Fixes a bug in 'series' designs where number of observations per series was 2

Modified: pkg/R/numPerms.R
===================================================================
--- pkg/R/numPerms.R	2008-03-24 10:43:27 UTC (rev 282)
+++ pkg/R/numPerms.R	2008-03-25 14:21:14 UTC (rev 283)
@@ -15,6 +15,8 @@
         if((control$type == "strata" && same.n > 1) ||
            (control$constant == TRUE && same.n > 1))
             stop("All levels of strata must have same number of samples for chosen scheme")
+        if(control$type == "grid" && same.n > 1)
+            stop("Unbalanced grid designs are not supported")
     }
     ## calculate number of possible permutations
     num.pos <- if(control$type == "free") {
@@ -29,18 +31,31 @@
                 multi <- 2
             else
                 multi <- 4
+        } else {
+            if(nobs == 2)
+                multi <- 1
         }
         if(use.strata) {
-            if(control$mirror) {
-                if(control$constant)
-                    multi * unique(tab.strata)
-                else
+            if(same.n > 1) {
+                multi <- rep(2, length = length(tab.strata))
+                multi[which(tab.strata == 2)] <- 1
+                if(control$mirror) {
                     prod(multi * tab.strata)
+                } else {
+                    prod(tab.strata)
+                }
             } else {
-                if(control$constant)
-                    unique(tab.strata)
-                else
-                    prod(tab.strata)
+                if(control$mirror) {
+                    if(control$constant)
+                        multi * unique(tab.strata)
+                    else
+                        prod(multi * tab.strata)
+                } else {
+                    if(control$constant)
+                        unique(tab.strata)
+                    else
+                        prod(tab.strata)
+                }
             }
         } else {
             if(control$mirror)

Modified: pkg/man/permCheck.Rd
===================================================================
--- pkg/man/permCheck.Rd	2008-03-24 10:43:27 UTC (rev 282)
+++ pkg/man/permCheck.Rd	2008-03-25 14:21:14 UTC (rev 283)
@@ -139,17 +139,35 @@
 }
 %\references{
 %}
-%\note{
-%  Currently, complete enumeration is not implemented in
-%  \code{\link{permuted.index2}}. \code{permCheck} sets complete
-%  enumeration in the \code{control} component of the returned object
-%  but this is not acted upon in the permutations.
-%
-%  \code{permCheck} does reduce the \code{nperm} and \code{maxperm}
-%  components of the returned object to the maximum number of possible
-%  permutations, and \code{\link{permuted.index2}} obeys these
-%  directives.
-%}
+\note{
+  In general, mirroring \code{"series"} or \code{"grid"} designs doubles
+  or quadruples, respectively,the number of permutations without
+  mirroring (within levels of strata if present). This is \strong{not}
+  true in two special cases:
+  \enumerate{
+    \item In \code{"grid"} designs where the number of columns is equal
+    to 2, and
+    \item In \code{"series"} designs where the number of observations in
+    a series is equal to 2.
+  }
+
+  For example, with 2 observations there are 2 permutations for
+  \code{"series"} designs:
+  \enumerate{
+    \item 1-2, and
+    \item 2-1.
+  }
+  If these two permutations were mirrored, we would have:
+  \enumerate{
+    \item 2-1, and
+    \item 1-2.
+  }
+  It is immediately clear that this is the same set of permutations
+  without mirroring (if one reorders the rows). A similar situation
+  arises in \code{"grid"} designs where the number of \strong{columns}
+  per \emph{grid} is equal to 2. Note that the number of rows per
+  \emph{grid} is not a factor.
+}
 \author{Gavin Simpson}
 \seealso{\code{\link{permuted.index2}} and \code{\link{permControl}}.}
 
@@ -220,6 +238,15 @@
 ## well as the matrix of permutations
 summary(tmp)
 summary(tmp2)
+
+## different numbers of observations per level of strata
+fac <- factor(rep(1:3, times = c(3,2,2)))
+## free permutations in levels of strata
+numPerms(7, permControl(type = "free", strata = fac))
+allPerms(7, permControl(type = "free", strata = fac))
+## series permutations in levels of strata
+numPerms(7, permControl(type = "series", strata = fac))
+allPerms(7, permControl(type = "series", strata = fac))
 }
 \keyword{ utilities }
 \keyword{ design }



More information about the Vegan-commits mailing list