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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Mar 30 00:54:10 CET 2008


Author: gsimpson
Date: 2008-03-30 00:54:09 +0100 (Sun, 30 Mar 2008)
New Revision: 295

Modified:
   pkg/R/permCheck.R
   pkg/inst/ChangeLog
Log:
Improvements to permCheck; more sanity checks for designs and better handling of numeric or integer vectors of length 1

Modified: pkg/R/permCheck.R
===================================================================
--- pkg/R/permCheck.R	2008-03-29 21:46:41 UTC (rev 294)
+++ pkg/R/permCheck.R	2008-03-29 23:54:09 UTC (rev 295)
@@ -1,5 +1,28 @@
 `permCheck` <- function(object, control = permControl())
 {
+    ## if object is numeric or integer and of length 1,
+    ## extend the object
+    if(length(object) == 1 &&
+       (is.integer(object) || is.numeric(object)))
+        object <- seq_len(object)
+    ## check the number of observations in object
+    nobs <- getNumObs(object)
+    ## if strata, check nobs == length of strata
+    ## but beware empty levels
+    if(!is.null(control$strata)) {
+        tab <- table(control$strata)
+        if(!identical(as.integer(nobs), as.integer(sum(tab))))
+            stop("Number of observations and length of 'strata' do not match.")
+        ## if "grid", check design balanced?
+        if((bal <- length(unique(tab))) > 1 && control$type == "grid")
+            stop("Unbalanced 'grid' designs are not supported.")
+        ## if constant, check design balanced?
+        if(control$constant && bal > 1)
+            stop("Unbalanced designs not allowed with 'constant = TRUE'.")
+        ## if permuting strata, must be balanced
+        if(control$type == "strata" && bal > 1)
+            stop("Design must be balanced if permuting 'strata'.")
+    }
     ## get number of possible permutations
     num.pos <- numPerms(object, control)
     if(num.pos < control$minperm) {

Modified: pkg/inst/ChangeLog
===================================================================
--- pkg/inst/ChangeLog	2008-03-29 21:46:41 UTC (rev 294)
+++ pkg/inst/ChangeLog	2008-03-29 23:54:09 UTC (rev 295)
@@ -15,6 +15,13 @@
 	mirroring was not applied the same way within each level of 
 	strata).
 
+	* permCheck: Now includes several sanity checks for balance
+	in permutation designs ('grid' & 'strata') and when using
+	same permutation in each level of 'strata' (constant = TRUE).
+	Also works if object is a (numeric or integer) vector of length 
+	1, by expanding it to seq(from = 1, to = object). This is now
+	in-line with the way numPerms works.
+
 	* screeplot: functions return now invisibly the xy.coords of
 	bars or points for eigenvalues. They used to return
 	invisibly the input data ('x'). Concerns screeplot methods for



More information about the Vegan-commits mailing list