[Vegan-commits] r2745 - in pkg/vegan: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Nov 22 18:59:51 CET 2013
Author: gsimpson
Date: 2013-11-22 18:59:51 +0100 (Fri, 22 Nov 2013)
New Revision: 2745
Modified:
pkg/vegan/R/permutest.betadisper.R
pkg/vegan/R/print.permutest.betadisper.R
pkg/vegan/man/permutest.betadisper.Rd
Log:
update permutest method to the new permute API
Modified: pkg/vegan/R/permutest.betadisper.R
===================================================================
--- pkg/vegan/R/permutest.betadisper.R 2013-11-22 17:59:07 UTC (rev 2744)
+++ pkg/vegan/R/permutest.betadisper.R 2013-11-22 17:59:51 UTC (rev 2745)
@@ -1,6 +1,6 @@
`permutest.betadisper` <- function(x, pairwise = FALSE,
- control = how(nperm = 999),
- permutations = NULL, ...)
+ permutations = how(nperm = 999),
+ ...)
{
t.statistic <- function(x, y) {
m <- length(x)
@@ -17,27 +17,31 @@
stop("Only for class \"betadisper\"")
## will issue error if only a single group
mod.aov <- anova(x)
- nobs <- length(x$distances)
+ nobs <- length(x$distances) ## number of observations
mod <- lm(x$distances ~ x$group)
mod.Q <- mod$qr
p <- mod.Q$rank
resids <- qr.resid(mod.Q, x$distances)
- N <- nrow(x) ## number of observations
-
## extract groups
group <- x$group
+ ## permutations is either a single number, a how() structure or a
+ ## permutation matrix
+ if (length(permutations) == 1) {
+ nperm <- permutations
+ permutations <- how(nperm = nperm)
+ }
- ## 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))
+ ## permutations is either a single number, a how() structure or a
+ ## permutation matrix
+ if (length(permutations) == 1) {
+ nperm <- permutations
+ permutations <- how(nperm = nperm)
}
-
+ ## now permutations is either a how() structure or a permutation
+ ## matrix. Make it to a matrix if it is "how"
+ if (inherits(permutations, "how"))
+ permutations <- shuffleSet(nobs, control = permutations)
## number of permutations being performed, possibly adjusted after
## checking in shuffleSet
nperm <- nrow(permutations)
@@ -45,7 +49,6 @@
## set-up objects to hold permuted results
res <- numeric(length = nperm + 1)
res[1] <- summary(mod)$fstatistic[1]
-
## pairwise comparisons
if(pairwise) {
## unique pairings
@@ -95,12 +98,13 @@
pairwise <- NULL
}
- retval <- cbind(mod.aov[, 1:4], c(nperm, NA), c(pval, NA))
+ retval <- cbind(mod.aov[, 1:4], c(nperm + 1, NA), c(pval, NA))
dimnames(retval) <- list(c("Groups", "Residuals"),
c("Df", "Sum Sq", "Mean Sq", "F", "N.Perm",
"Pr(>F)"))
retval <- list(tab = retval, pairwise = pairwise,
- groups = levels(group), control = control)
+ groups = levels(group),
+ control = attr(permutations, "control"))
class(retval) <- "permutest.betadisper"
retval
}
Modified: pkg/vegan/R/print.permutest.betadisper.R
===================================================================
--- pkg/vegan/R/print.permutest.betadisper.R 2013-11-22 17:59:07 UTC (rev 2744)
+++ pkg/vegan/R/print.permutest.betadisper.R 2013-11-22 17:59:51 UTC (rev 2745)
@@ -21,7 +21,7 @@
zap.i <- zap.i[!(zap.i %in% i)]
if (length(i <- grep("N.Perm$", cn)))
zap.i <- zap.i[!(zap.i %in% i)]
- cat("Response: Distances", sep = "\n")
+ cat("\nResponse: Distances", sep = "\n")
printCoefmat(x$tab, digits = digits,
signif.stars = getOption("show.signif.stars"),
has.Pvalue = has.P, P.values = has.P, cs.ind = NULL,
Modified: pkg/vegan/man/permutest.betadisper.Rd
===================================================================
--- pkg/vegan/man/permutest.betadisper.Rd 2013-11-22 17:59:07 UTC (rev 2744)
+++ pkg/vegan/man/permutest.betadisper.Rd 2013-11-22 17:59:51 UTC (rev 2745)
@@ -10,18 +10,18 @@
}
\usage{
\method{permutest}{betadisper}(x, pairwise = FALSE,
- control = how(nperm = 999), permutations = NULL,
- \dots)
+ permutations = how(nperm = 999),
+ \dots)
}
%- maybe also 'usage' for other objects documented here.
\arguments{
\item{x}{an object of class \code{"betadisper"}, the result of a
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}}.}
- \item{permutations}{A permutation matrix where each row gives the
- permuted indices. If this is supplied, \code{control} is ignored.}
+ \item{permutations}{a list of control values for the permutations
+ as returned by the function \code{\link[permute]{how}}, or the
+ number of permutations required, or a permutation matrix where each
+ row gives the permuted indices.}
\item{\dots}{Arguments passed to other methods.}
}
\details{
@@ -82,7 +82,7 @@
anova(mod)
## Permutation test for F
-permutest(mod, pairwise = TRUE)
+permutest(mod, permutations = 99, pairwise = TRUE)
## Tukey's Honest Significant Differences
(mod.HSD <- TukeyHSD(mod))
More information about the Vegan-commits
mailing list