[Vegan-commits] r2528 - in pkg/vegan: R inst man tests
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Jun 15 18:55:49 CEST 2013
Author: gsimpson
Date: 2013-06-15 18:55:48 +0200 (Sat, 15 Jun 2013)
New Revision: 2528
Modified:
pkg/vegan/R/print.protest.R
pkg/vegan/R/protest.R
pkg/vegan/inst/ChangeLog
pkg/vegan/man/procrustes.Rd
pkg/vegan/tests/vegan-tests.R
Log:
port protest to the new permute API
Modified: pkg/vegan/R/print.protest.R
===================================================================
--- pkg/vegan/R/print.protest.R 2013-06-12 20:57:39 UTC (rev 2527)
+++ pkg/vegan/R/print.protest.R 2013-06-15 16:55:48 UTC (rev 2528)
@@ -10,8 +10,7 @@
cat("Significance: ")
cat(format.pval(x$signif),"\n")
cat("Based on", x$permutations, "permutations")
- if (!is.null(x$strata))
- cat(", stratified within", x$strata)
+ print(x$control)
cat(".\n\n")
invisible(x)
}
Modified: pkg/vegan/R/protest.R
===================================================================
--- pkg/vegan/R/protest.R 2013-06-12 20:57:39 UTC (rev 2527)
+++ pkg/vegan/R/protest.R 2013-06-15 16:55:48 UTC (rev 2528)
@@ -1,5 +1,6 @@
`protest` <-
- function (X, Y, scores = "sites", permutations = 999, strata, ...)
+ function (X, Y, scores = "sites", control = how(nperm = 999),
+ permutations = NULL, ...)
{
X <- scores(X, display = scores, ...)
Y <- scores(Y, display = scores, ...)
@@ -23,36 +24,28 @@
## procrustes() for each permutation. The following gives the
## Procrustes r directly.
procr <- function(X, Y) sum(svd(crossprod(X, Y), nv=0, nu=0)$d)
-
- if (length(permutations) == 1) {
- if (permutations > 0) {
- arg <- if (missing(strata)) NULL else strata
- permat <- t(replicate(permutations,
- permuted.index(N, strata = arg)))
- }
+
+ ## If permutations is NULL, work with control
+ if(is.null(permutations)) {
+ #np <- getNperm(control)
+ permutations <- shuffleSet(N, control = control)
} else {
- permat <- as.matrix(permutations)
- if (ncol(permat) != N)
+ permutations <- as.matrix(permutations)
+ if (ncol(permutations) != N)
stop(gettextf("'permutations' have %d columns, but data have %d observations",
- ncol(permat), N))
- permutations <- nrow(permutations)
+ ncol(permutations), N))
}
- perm <- sapply(1:permutations,
- function(i, ...) procr(X, Y[permat[i,],]))
- Pval <- (sum(perm >= sol$t0) + 1)/(permutations + 1)
- if (!missing(strata)) {
- strata <- deparse(substitute(strata))
- s.val <- strata
- }
- else {
- strata <- NULL
- s.val <- NULL
- }
+ np <- nrow(permutations)
+
+ perm <- sapply(seq_len(np),
+ function(i, ...) procr(X, Y[permutations[i,],]))
+
+ Pval <- (sum(perm >= sol$t0) + 1)/(np + 1)
+
sol$t <- perm
sol$signif <- Pval
- sol$permutations <- permutations
- sol$strata <- strata
- sol$stratum.values <- s.val
+ sol$permutations <- np
+ sol$control <- control
sol$call <- match.call()
class(sol) <- c("protest", "procrustes")
sol
Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog 2013-06-12 20:57:39 UTC (rev 2527)
+++ pkg/vegan/inst/ChangeLog 2013-06-15 16:55:48 UTC (rev 2528)
@@ -10,6 +10,13 @@
* betadisper, permutest.betadisper: Modified to use the new
permute package API (from version 0.7-3 onwards).
+ * protest: modified to use the new permute API. Gains argument
+ `control` which describes the design. As a result, `strata`
+ argument has been removed and `permutations` argument can only
+ be used to supply your own matrix of permutations. The number of
+ permutations and other features of the design are set via `control`
+ and function `how()` from permute.
+
Version 2.1-30 (opened May 5, 2013)
* bioenv: can now use Mahalanobis, Manhattan and Gower distances
Modified: pkg/vegan/man/procrustes.Rd
===================================================================
--- pkg/vegan/man/procrustes.Rd 2013-06-12 20:57:39 UTC (rev 2527)
+++ pkg/vegan/man/procrustes.Rd 2013-06-15 16:55:48 UTC (rev 2528)
@@ -28,7 +28,8 @@
\method{residuals}{procrustes}(object, ...)
\method{fitted}{procrustes}(object, truemean = TRUE, ...)
\method{predict}{procrustes}(object, newdata, truemean = TRUE, ...)
-protest(X, Y, scores = "sites", permutations = 999, strata, ...)
+protest(X, Y, scores = "sites", control = how(nperm = 999),
+ permutations = NULL, ...)
}
\arguments{
@@ -64,12 +65,10 @@
\code{truemean = FALSE}.}
\item{newdata}{Matrix of coordinates to be rotated and translated to
the target.}
- \item{permutations}{Number of permutations or a permutation matrix
- where each row gives the permuted indices. These are used to asses the
- signficance of the symmetric Procrustes statistic.}
- \item{strata}{An integer vector or factor specifying the strata for
- permutation. If supplied, observations are permuted only within the
- specified strata.}
+ \item{control}{a list defining the permutation design, from a call to
+ \code{\link{how}}.}
+ \item{permutations}{A permutation matrix where each row gives the
+ permuted indices. If this is supplied, \code{cotrol} is ignored.}
\item{ar.col}{Arrow colour.}
\item{len}{Width of the arrow head.}
\item{labels}{Character vector of text labels. Rownames of the result
@@ -167,8 +166,8 @@
function.}
\item{signif}{`Significance' of \code{t}}
\item{permutations}{Number of permutations.}
- \item{strata}{The name of the stratifying variable.}
- \item{stratum.values}{Values of the stratifying variable.}
+ \item{control}{the list passed to argument \code{control} describing
+ the permutation design.}
}
\references{
Mardia, K.V., Kent, J.T. and Bibby,
@@ -187,7 +186,9 @@
\seealso{\code{\link{monoMDS}}, for obtaining
objects for \code{procrustes}, and \code{\link{mantel}} for an
-alternative to \code{protest} without need of dimension reduction.}
+alternative to \code{protest} without need of dimension reduction. See
+\code{\link[permute]{how}} for details on specifying the type of
+permutation required.}
\examples{
data(varespec)
Modified: pkg/vegan/tests/vegan-tests.R
===================================================================
--- pkg/vegan/tests/vegan-tests.R 2013-06-12 20:57:39 UTC (rev 2527)
+++ pkg/vegan/tests/vegan-tests.R 2013-06-15 16:55:48 UTC (rev 2528)
@@ -153,13 +153,13 @@
### end envfit & plot.envfit
### protest (& Procrustes analysis): Stability of the permutations and
-### other results.
+### other results.
data(mite)
mod <- rda(mite)
x <- scores(mod, display = "si", choices=1:6)
set.seed(4711)
xp <- x[sample(nrow(x)),]
-pro <- protest(x, xp, permutations = 99)
+pro <- protest(x, xp, control = how(nperm = 99))
pro
pro$t
rm(x, xp, pro)
More information about the Vegan-commits
mailing list