[Vegan-commits] r296 - in pkg: R inst man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Mar 30 15:20:47 CEST 2008
Author: gsimpson
Date: 2008-03-30 15:20:46 +0200 (Sun, 30 Mar 2008)
New Revision: 296
Modified:
pkg/R/allPerms.R
pkg/R/permCheck.R
pkg/R/permControl.R
pkg/inst/ChangeLog
pkg/man/permCheck.Rd
pkg/man/permuted.index2.Rd
Log:
Changes to permCheck, allPerms and permControl to facilitate more complete checking of schemes
Modified: pkg/R/allPerms.R
===================================================================
--- pkg/R/allPerms.R 2008-03-29 23:54:09 UTC (rev 295)
+++ pkg/R/allPerms.R 2008-03-30 13:20:46 UTC (rev 296)
@@ -78,17 +78,24 @@
X
}
## recursive fun for perms within strata
+ ##bar <- function(mat, n) {
+ ## if(n == 1)
+ ## mat
+ ## else
+ ## mat <- rbind(mat, Recall(mat, n-1))
+ ## mat
+ ##}
+ ## replacement for recursive function above
bar <- function(mat, n) {
- if(n == 1)
- mat
- else
- mat <- rbind(mat, Recall(mat, n-1))
- mat
+ res <- vector(mode = "list", length = n)
+ for(i in seq_len(n))
+ res[[i]] <- mat
+ do.call(rbind, res)
}
## start
v <- seq_len(n)
## check permutation scheme and update control
- pcheck <- permCheck(v, control = control)
+ pcheck <- permCheck(v, control = control, make.all = FALSE)
control <- pcheck$control
## get max number of permutations
## originally had:
Modified: pkg/R/permCheck.R
===================================================================
--- pkg/R/permCheck.R 2008-03-29 23:54:09 UTC (rev 295)
+++ pkg/R/permCheck.R 2008-03-30 13:20:46 UTC (rev 296)
@@ -1,4 +1,5 @@
-`permCheck` <- function(object, control = permControl())
+`permCheck` <- function(object, control = permControl(),
+ make.all = TRUE)
{
## if object is numeric or integer and of length 1,
## extend the object
@@ -7,6 +8,7 @@
object <- seq_len(object)
## check the number of observations in object
nobs <- getNumObs(object)
+ type <- control$type
## if strata, check nobs == length of strata
## but beware empty levels
if(!is.null(control$strata)) {
@@ -14,21 +16,36 @@
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")
+ if((bal <- length(unique(tab))) > 1 && type == "grid")
stop("Unbalanced 'grid' designs are not supported.")
+ ## if grid design, check nrow*ncol is multiple of nobs
+ if(type == "grid" &&
+ !identical(nobs %% (control$ncol * control$nrow), 0))
+ stop("'nrow' * 'ncol' not a multilpe of number of observations.")
## 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)
+ if(type == "strata" && bal > 1)
stop("Design must be balanced if permuting 'strata'.")
}
+ ##
+ if(!is.null(control$all.perms) &&
+ !identical(class(control$all.perms), "allPerms"))
+ stop("'control$all.perms' must be of class 'allPerms'.")
## get number of possible permutations
num.pos <- numPerms(object, control)
+ ## if number of possible perms < minperm turn on complete enumeration
if(num.pos < control$minperm) {
control$nperm <- control$maxperm <- num.pos
control$complete <- TRUE
}
+ ## if complete enumeration, generate all permutations
+ if(control$complete && make.all) {
+ control$all.perms <- allPerms(nobs, control = control,
+ max = control$maxperm,
+ observed = FALSE)
+ }
retval <- list(n = num.pos, control = control)
class(retval) <- "permCheck"
retval
Modified: pkg/R/permControl.R
===================================================================
--- pkg/R/permControl.R 2008-03-29 23:54:09 UTC (rev 295)
+++ pkg/R/permControl.R 2008-03-30 13:20:46 UTC (rev 296)
@@ -2,7 +2,8 @@
type = c("free", "series", "grid", "strata"),
maxperm = 9999, minperm = 99,
mirror = FALSE, constant = FALSE,
- ncol = NULL, nrow = NULL)
+ ncol = NULL, nrow = NULL,
+ all.perms = NULL)
{
if(missing(type))
type <- "free"
@@ -12,7 +13,7 @@
type = type,
maxperm = maxperm, minperm = minperm,
mirror = mirror, constant = constant,
- ncol = ncol, nrow = nrow,
+ ncol = ncol, nrow = nrow, all.perms = all.perms,
name.strata = deparse(substitute(strata)))
class(out) <- "permControl"
return(out)
Modified: pkg/inst/ChangeLog
===================================================================
--- pkg/inst/ChangeLog 2008-03-29 23:54:09 UTC (rev 295)
+++ pkg/inst/ChangeLog 2008-03-30 13:20:46 UTC (rev 296)
@@ -10,7 +10,7 @@
permutation designs currently handled by permuted.index2().
* permuted.index2: was not returning correct sample indices
- for grid designs within strata. Also,was not consitently
+ 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).
@@ -22,6 +22,16 @@
1, by expanding it to seq(from = 1, to = object). This is now
in-line with the way numPerms works.
+ New argument 'make.all' in permCheck() allows greater control
+ over the checking process. Allows user to check a permutation
+ design without generating the matrix of all possible permutations.
+ Used in allPerms() to allow that function to check permutation
+ designs without getting stuck in infinite recursion, as permCheck()
+ calls allPerms() if complete = TRUE. This change allows allPerms()
+ to be called by a user without having to make sure the supplied
+ design makes sense - the design is checked using
+ 'make.all = FALSE'.
+
* 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
Modified: pkg/man/permCheck.Rd
===================================================================
--- pkg/man/permCheck.Rd 2008-03-29 23:54:09 UTC (rev 295)
+++ pkg/man/permCheck.Rd 2008-03-30 13:20:46 UTC (rev 296)
@@ -26,7 +26,7 @@
selected permutation design.
}
\usage{
-permCheck(object, control = permControl())
+permCheck(object, control = permControl(), make.all = TRUE)
\method{summary}{permCheck}(object, \dots)
@@ -61,6 +61,9 @@
\item{control}{a list of control values describing properties of the
permutation design, as returned by a call to
\code{\link{permControl}}.}
+ \item{make.all}{logical; should \code{permCheck} generate all
+ possible permutations? Useful if want to check permutation design
+ but not produce the matrix of all permutations.}
\item{n}{the number of observations.}
\item{max}{the maximum number of permutations, below which complete
enumeration will be attempted. See Details.}
Modified: pkg/man/permuted.index2.Rd
===================================================================
--- pkg/man/permuted.index2.Rd 2008-03-29 23:54:09 UTC (rev 295)
+++ pkg/man/permuted.index2.Rd 2008-03-30 13:20:46 UTC (rev 296)
@@ -15,7 +15,8 @@
type = c("free", "series", "grid", "strata"),
maxperm = 9999, minperm = 99,
mirror = FALSE, constant = FALSE,
- ncol = NULL, nrow = NULL)
+ ncol = NULL, nrow = NULL,
+ all.perms = NULL)
}
\arguments{
@@ -42,6 +43,8 @@
permutation is produced for each level of \code{strata}.}
\item{ncol, nrow}{numeric; the number of columns and rows of samples
in the spatial grid respectiavly.}
+ \item{all.perms}{an object of class \code{allPerms}, the result of a
+ call to \code{\link{allPerms}}.}
}
\details{
\code{permuted.index2} can generate permutations for a wide range of
More information about the Vegan-commits
mailing list