[Vegan-commits] r2543 - in pkg/vegan: R inst man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Jul 8 05:19:38 CEST 2013
Author: gsimpson
Date: 2013-07-08 05:19:38 +0200 (Mon, 08 Jul 2013)
New Revision: 2543
Modified:
pkg/vegan/R/permutest.betadisper.R
pkg/vegan/inst/ChangeLog
pkg/vegan/man/permutest.betadisper.Rd
Log:
adds a permutations argument
Modified: pkg/vegan/R/permutest.betadisper.R
===================================================================
--- pkg/vegan/R/permutest.betadisper.R 2013-07-08 03:18:51 UTC (rev 2542)
+++ pkg/vegan/R/permutest.betadisper.R 2013-07-08 03:19:38 UTC (rev 2543)
@@ -1,5 +1,6 @@
`permutest.betadisper` <- function(x, pairwise = FALSE,
- control = how(nperm = 999), ...)
+ control = how(nperm = 999),
+ permutations = NULL, ...)
{
t.statistic <- function(x, y) {
m <- length(x)
@@ -11,7 +12,7 @@
pooled <- sqrt(((m-1)*xvar + (n-1)*yvar) / (m+n-2))
(xbar - ybar) / (pooled * sqrt(1/m + 1/n))
}
-
+
if(!inherits(x, "betadisper"))
stop("Only for class \"betadisper\"")
## will issue error if only a single group
@@ -22,20 +23,29 @@
p <- mod.Q$rank
resids <- qr.resid(mod.Q, x$distances)
+ N <- nrow(x) ## number of observations
+
## extract groups
group <- x$group
-
- ## get set of permutations - shuffleSet checks design
- perms <- shuffleSet(length(group), control = control)
+ ## If permutations is NULL, work with control
+ if(is.null(permutations)) {
+ permutations <- shuffleSet(length(group), control = control)
+ } else {
+ permutations <- as.matrix(permutations)
+ if (ncol(permutations) != N)
+ stop(gettextf("'permutations' have %d columns, but data have %d observations",
+ ncol(permutations), N))
+ }
+
## number of permutations being performed, possibly adjusted after
## checking in shuffleSet
- nperm <- nrow(perms)
+ nperm <- nrow(permutations)
## set-up objects to hold permuted results
res <- numeric(length = nperm + 1)
res[1] <- summary(mod)$fstatistic[1]
-
+
## pairwise comparisons
if(pairwise) {
## unique pairings
@@ -49,7 +59,7 @@
## begin loop over shuffleSet perms
for(i in seq_len(nperm)) {
- perm <- perms[i,] ## take current permutation from set
+ perm <- permutations[i,] ## take current permutation from set
perm.resid <- resids[perm] ## permute residuals
f <- qr.fitted(mod.Q, perm.resid) ## create new data
mss <- sum((f - mean(f))^2)
@@ -58,7 +68,7 @@
rdf <- nobs - p
resvar <- rss / rdf
res[i+1] <- (mss / (p - 1)) / resvar
-
+
## pairwise comparisons
if(pairwise) {
for(j in seq_len(n.pairs)) {
@@ -71,7 +81,7 @@
## compute permutation p-value
pval <- sum(res >= res[1]) / length(res)
-
+
if(pairwise) {
df <- apply(combin, 2, function(z) {
length(x$distances[group == z[1]]) +
@@ -84,7 +94,7 @@
} else {
pairwise <- NULL
}
-
+
retval <- cbind(mod.aov[, 1:4], c(nperm, NA), c(pval, NA))
dimnames(retval) <- list(c("Groups", "Residuals"),
c("Df", "Sum Sq", "Mean Sq", "F", "N.Perm",
Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog 2013-07-08 03:18:51 UTC (rev 2542)
+++ pkg/vegan/inst/ChangeLog 2013-07-08 03:19:38 UTC (rev 2543)
@@ -8,7 +8,9 @@
later.
* betadisper, permutest.betadisper: Modified to use the new
- permute package API (from version 0.7-3 onwards).
+ permute package API (from version 0.7-3 onwards). The `permutest`
+ method gains a new argument `permutations`, which takes a matrix
+ of permutations to be used.
* protest: modified to use the new permute API. Gains argument
`control` which describes the design. As a result, `strata`
@@ -47,7 +49,7 @@
* stressplot: metaMDS and monoMDS stressplot() use now
expression(R^2) instead of ascii R2. The stressplot.monoMDS()
function returns the plotting structures in the original input
- order.
+ order.
* vignettes: Brian Ripley urged as to remove
\usepackage{inconsolota} as this package is on the way to be
Modified: pkg/vegan/man/permutest.betadisper.Rd
===================================================================
--- pkg/vegan/man/permutest.betadisper.Rd 2013-07-08 03:18:51 UTC (rev 2542)
+++ pkg/vegan/man/permutest.betadisper.Rd 2013-07-08 03:19:38 UTC (rev 2543)
@@ -10,7 +10,8 @@
}
\usage{
\method{permutest}{betadisper}(x, pairwise = FALSE,
- control = how(nperm = 999), \dots)
+ control = how(nperm = 999), permutations = NULL,
+ \dots)
}
%- maybe also 'usage' for other objects documented here.
\arguments{
@@ -18,7 +19,9 @@
call to \code{betadisper}.}
\item{pairwise}{logical; perform pairwise comparisons of group means?}
\item{control}{a list of control values for the permutations
- as returned by the function \code{\link[permute]{how}}}
+ as returned by the function \code{\link[permute]{how}}.}
+ \item{permutations}{A permutation matrix where each row gives the
+ permuted indices. If this is supplied, \code{control} is ignored.}
\item{\dots}{Arguments passed to other methods.}
}
\details{
More information about the Vegan-commits
mailing list