[Vegan-commits] r2268 - in pkg/vegan: R inst man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Sep 4 06:25:13 CEST 2012
Author: jarioksa
Date: 2012-09-04 06:25:12 +0200 (Tue, 04 Sep 2012)
New Revision: 2268
Modified:
pkg/vegan/R/mantel.R
pkg/vegan/R/mantel.partial.R
pkg/vegan/inst/ChangeLog
pkg/vegan/man/mantel.Rd
Log:
mantel & mantel.partial gained arg na.rm = FALSE
Modified: pkg/vegan/R/mantel.R
===================================================================
--- pkg/vegan/R/mantel.R 2012-09-03 18:42:46 UTC (rev 2267)
+++ pkg/vegan/R/mantel.R 2012-09-04 04:25:12 UTC (rev 2268)
@@ -1,10 +1,15 @@
`mantel` <-
function (xdis, ydis, method = "pearson", permutations = 999,
- strata, parallel = getOption("mc.cores"))
+ strata, na.rm = FALSE, parallel = getOption("mc.cores"))
{
xdis <- as.dist(xdis)
ydis <- as.vector(as.dist(ydis))
- statistic <- cor(as.vector(xdis), ydis, method = method)
+ ## Handle missing values
+ if (na.rm)
+ use <- "complete.obs"
+ else
+ use = "all.obs"
+ statistic <- cor(as.vector(xdis), ydis, method = method, use = use)
variant <- match.arg(method, eval(formals(cor)$method))
variant <- switch(variant,
pearson = "Pearson's product-moment correlation",
@@ -33,7 +38,7 @@
asdist <- row(xmat) > col(xmat)
ptest <- function(take, ...) {
permvec <- (xmat[take, take])[asdist]
- drop(cor(permvec, ydis, method = method))
+ drop(cor(permvec, ydis, method = method, use = use))
}
## Parallel processing
if (is.null(parallel) && getRversion() >= "2.15.0")
Modified: pkg/vegan/R/mantel.partial.R
===================================================================
--- pkg/vegan/R/mantel.partial.R 2012-09-03 18:42:46 UTC (rev 2267)
+++ pkg/vegan/R/mantel.partial.R 2012-09-04 04:25:12 UTC (rev 2268)
@@ -1,6 +1,6 @@
`mantel.partial` <-
function (xdis, ydis, zdis, method = "pearson", permutations = 999,
- strata, parallel = getOption("mc.cores"))
+ strata, na.rm = FALSE, parallel = getOption("mc.cores"))
{
part.cor <- function(rxy, rxz, ryz) {
(rxy - rxz * ryz)/sqrt(1-rxz*rxz)/sqrt(1-ryz*ryz)
@@ -8,9 +8,14 @@
xdis <- as.dist(xdis)
ydis <- as.vector(as.dist(ydis))
zdis <- as.vector(as.dist(zdis))
- rxy <- cor(as.vector(xdis), ydis, method = method)
- rxz <- cor(as.vector(xdis), zdis, method = method)
- ryz <- cor(ydis, zdis, method = method)
+ ## Handle missing values
+ if (na.rm)
+ use <- "complete.obs"
+ else
+ use = "all.obs"
+ rxy <- cor(as.vector(xdis), ydis, method = method, use = use)
+ rxz <- cor(as.vector(xdis), zdis, method = method, use = use)
+ ryz <- cor(ydis, zdis, method = method, use = use)
variant <- match.arg(method, eval(formals(cor)$method))
variant <- switch(variant,
pearson = "Pearson's product-moment correlation",
@@ -39,8 +44,8 @@
asdist <- row(xmat) > col(xmat)
ptest <- function(take, ...) {
permvec <- (xmat[take, take])[asdist]
- rxy <- cor(permvec, ydis, method = method)
- rxz <- cor(permvec, zdis, method = method)
+ rxy <- cor(permvec, ydis, method = method, use = use)
+ rxz <- cor(permvec, zdis, method = method, use = use)
part.cor(rxy, rxz, ryz)
}
## parallel processing
Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog 2012-09-03 18:42:46 UTC (rev 2267)
+++ pkg/vegan/inst/ChangeLog 2012-09-04 04:25:12 UTC (rev 2268)
@@ -48,10 +48,13 @@
oecosimu-compliant earlier and simultaneously they also gained the
density and densityplot methods.
- * mantel, mantel.partial: mixed cor.test() and cor(), but now only
- use cor(). The use of cor.test() was only used to get the textual
- presentation of the correlation 'method'. Internal changes that
- should have no effect in results, but consistency is a good thing.
+ * mantel, mantel.partial: Gained argument na.rm (defaults FALSE)
+ to remove missing values from dissimilarities. To implement this,
+ there were some internal changes in functions (that should not
+ influence the results): The functions mixed cor.test() and cor(),
+ but now only use cor(). Function cor.test() was only used to get the
+ textual presentation of the correlation 'method', but this is now
+ found internally.
* protest: do not return the observed statistic as one of the
permuted values but separately.
Modified: pkg/vegan/man/mantel.Rd
===================================================================
--- pkg/vegan/man/mantel.Rd 2012-09-03 18:42:46 UTC (rev 2267)
+++ pkg/vegan/man/mantel.Rd 2012-09-04 04:25:12 UTC (rev 2268)
@@ -14,9 +14,9 @@
}
\usage{
mantel(xdis, ydis, method="pearson", permutations=999, strata,
- parallel = getOption("mc.cores"))
+ na.rm = FALSE, parallel = getOption("mc.cores"))
mantel.partial(xdis, ydis, zdis, method = "pearson", permutations = 999,
- strata, parallel = getOption("mc.cores"))
+ strata, na.rm = FALSE, parallel = getOption("mc.cores"))
}
\arguments{
@@ -28,6 +28,10 @@
\item{strata}{An integer vector or factor specifying the strata for
permutation. If supplied, observations are permuted only within the
specified strata.}
+ \item{na.rm}{Remove missing values in calculation of Mantel
+ correlation. Use this option with care. When two dissimilarities
+ have both missing values in matching positions, these matches will
+ be broken in permutation tests can be biased.}
\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}
More information about the Vegan-commits
mailing list