[Vegan-commits] r2061 - in pkg/vegan: R inst man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Feb 4 10:25:23 CET 2012
Author: jarioksa
Date: 2012-02-04 10:25:22 +0100 (Sat, 04 Feb 2012)
New Revision: 2061
Modified:
pkg/vegan/R/adonis.R
pkg/vegan/inst/ChangeLog
pkg/vegan/man/adonis.Rd
Log:
parallel processing in adonis
Modified: pkg/vegan/R/adonis.R
===================================================================
--- pkg/vegan/R/adonis.R 2012-02-01 08:53:17 UTC (rev 2060)
+++ pkg/vegan/R/adonis.R 2012-02-04 09:25:22 UTC (rev 2061)
@@ -1,7 +1,7 @@
`adonis` <-
function(formula, data=NULL, permutations=999, method="bray", strata=NULL,
contr.unordered="contr.sum", contr.ordered="contr.poly",
- ...)
+ parallel = getOption("mc.cores"), ...)
{
## formula is model formula such as Y ~ A + B*C where Y is a data
## frame or a matrix, and A, B, and C may be factors or continuous
@@ -108,11 +108,42 @@
tIH.snterm <- t(I-H.snterm)
## Apply permutations for each term
## This is the new f.test (2011-06-15) that uses fewer arguments
- f.perms <- sapply(1:nterms, function(i) {
- sapply(1:permutations, function(j) {
- f.test(tH.s[[i]], G[p[,j], p[,j]], df.Exp[i], df.Res, tIH.snterm)
- } )
- })
+ ## Set first parallel processing for all terms
+ if (is.null(parallel) && getRversion() >= "2.15.0")
+ parallel <- get("default", envir = parallel:::.reg)
+ if (is.null(parallel) || getRversion() < "2.14.0")
+ parallel <- 1
+ hasClus <- inherits(parallel, "cluster")
+ isParal <- (hasClus || parallel > 1) && require(parallel)
+ isMulticore <- .Platform$OS.type == "unix" && !hasClus
+ if (isParal && !isMulticore && !hasClus) {
+ parallel <- makeCluster(parallel)
+ clusterEvalQ(parallel, library(vegan))
+ }
+ if (isParal) {
+ if (isMulticore) {
+ f.perms <-
+ sapply(1:nterms, function(i)
+ unlist(mclapply(1:permutations, function(j)
+ f.test(tH.s[[i]], G[p[,j], p[,j]],
+ df.Exp[i], df.Res, tIH.snterm))))
+ } else {
+ f.perms <-
+ sapply(1:nterms, function(i)
+ parSapply(parallel, 1:permutations, function(j)
+ f.test(tH.s[[i]], G[p[,j], p[,j]],
+ df.Exp[i], df.Res, tIH.snterm)))
+ }
+ } else {
+ f.perms <-
+ sapply(1:nterms, function(i)
+ sapply(1:permutations, function(j)
+ f.test(tH.s[[i]], G[p[,j], p[,j]],
+ df.Exp[i], df.Res, tIH.snterm)))
+ }
+ ## Close socket cluster if created here
+ if (isParal && !isMulticore && !hasClus)
+ stopCluster(parallel)
## Round to avoid arbitrary P-values with tied data
f.perms <- round(f.perms, 12)
F.Mod <- round(F.Mod, 12)
Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog 2012-02-01 08:53:17 UTC (rev 2060)
+++ pkg/vegan/inst/ChangeLog 2012-02-04 09:25:22 UTC (rev 2061)
@@ -8,8 +8,8 @@
seems to confuse users. Make this change in adonis() instead of
print.adonis to be prepared to add other policies.
- * anomsim, mantel, mantel.partial, mrpp: implemented parallel
- processing.
+ * adonis, anosim, mantel, mantel.partial, mrpp: implemented
+ parallel processing.
* RsquareAdj: implemented adjusted R2 for partial RDA results.
The adjusted R2 of model rda(Y ~ X1 + Condition(X2)) is defined so
Modified: pkg/vegan/man/adonis.Rd
===================================================================
--- pkg/vegan/man/adonis.Rd 2012-02-01 08:53:17 UTC (rev 2060)
+++ pkg/vegan/man/adonis.Rd 2012-02-04 09:25:22 UTC (rev 2061)
@@ -12,7 +12,7 @@
\usage{
adonis(formula, data, permutations = 999, method = "bray",
strata = NULL, contr.unordered = "contr.sum",
- contr.ordered = "contr.poly", ...)
+ contr.ordered = "contr.poly", parallel = getOption("mc.cores"), ...)
}
\arguments{
@@ -34,6 +34,10 @@
\item{contr.unordered, contr.ordered}{contrasts used for the design
matrix (default in R is dummy or treatment contrasts for unordered
factors). }
+ \item{parallel}{Number of parallel processes or a predefined socket
+ cluster. With \code{parallel = 1} uses ordinary, non-parallel
+ processing. The parallel processing is done with \pkg{parallel}
+ package which is available only for \R 2.14.0 and later.}
\item{\dots}{Other arguments passed to \code{vegdist}.}
}
More information about the Vegan-commits
mailing list