[Vegan-commits] r1002 - in pkg/vegan: R inst man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Sep 11 09:16:54 CEST 2009
Author: jarioksa
Date: 2009-09-11 09:16:53 +0200 (Fri, 11 Sep 2009)
New Revision: 1002
Modified:
pkg/vegan/R/capscale.R
pkg/vegan/R/ordiNAexclude.R
pkg/vegan/inst/ChangeLog
pkg/vegan/man/capscale.Rd
Log:
capscale got na.action
Modified: pkg/vegan/R/capscale.R
===================================================================
--- pkg/vegan/R/capscale.R 2009-09-10 18:46:20 UTC (rev 1001)
+++ pkg/vegan/R/capscale.R 2009-09-11 07:16:53 UTC (rev 1002)
@@ -1,7 +1,7 @@
`capscale` <-
function (formula, data, distance = "euclidean", sqrt.dist = FALSE,
comm = NULL, add = FALSE, dfun = vegdist,
- metaMDSdist = FALSE, ...)
+ metaMDSdist = FALSE, na.action = na.fail, ...)
{
EPS <- sqrt(.Machine$double.eps)
if (!inherits(formula, "formula"))
@@ -28,8 +28,6 @@
X <- dfun(X, distance)
}
}
- if (sqrt.dist)
- X <- sqrt(X)
inertia <- attr(X, "method")
if (is.null(inertia))
inertia <- "unknown"
@@ -40,7 +38,23 @@
inertia <- paste("squared", inertia)
if (add)
inertia <- paste(inertia, "(euclidified)")
- k <- attr(X, "Size") - 1
+
+ ## evaluate formula: ordiParseFormula will return dissimilarities
+ ## as a symmetric square matrix (except that some rows may be
+ ## deleted due to missing values)
+ fla <- update(formula, X ~ .)
+ environment(fla) <- environment()
+ d <- ordiParseFormula(fla, data, envdepth = 1, na.action = na.action)
+ ## Delete columns if rows were deleted due to missing values
+ if (!is.null(d$na.action)) {
+ d$X <- d$X[, -d$na.action, drop = FALSE]
+ if (!is.null(comm))
+ comm <- comm[-d$na.action,,drop=FALSE]
+ }
+ X <- as.dist(d$X)
+ k <- attr(X, "Size") - 1
+ if (sqrt.dist)
+ X <- sqrt(X)
if (max(X) >= 4 + .Machine$double.eps) {
inertia <- paste("mean", inertia)
adjust <- 1
@@ -48,12 +62,7 @@
else {
adjust <- sqrt(k)
}
- nm <- attr(X, "Labels")
- ## evaluate formula
- fla <- update(formula, X ~ .)
- environment(fla) <- environment()
- d <- ordiParseFormula(fla, data, envdepth = 1)
- X <- as.dist(d$X)
+ nm <- attr(X, "Labels")
## cmdscale is only used if 'add = TRUE': it cannot properly
## handle negative eigenvalues and therefore we normally use
## wcmdscale. If we have 'add = TRUE' there will be no negative
@@ -125,6 +134,9 @@
sol$inertia <- inertia
if (metaMDSdist)
sol$metaMDSdist <- commname
+ sol$na.action <- d$na.action
class(sol) <- c("capscale", class(sol))
+ if (!is.null(sol$na.action))
+ sol <- ordiNAexclude(sol, d$excluded)
sol
}
Modified: pkg/vegan/R/ordiNAexclude.R
===================================================================
--- pkg/vegan/R/ordiNAexclude.R 2009-09-10 18:46:20 UTC (rev 1001)
+++ pkg/vegan/R/ordiNAexclude.R 2009-09-11 07:16:53 UTC (rev 1002)
@@ -20,7 +20,8 @@
x$rowsum.excluded <- rowSums(excluded)/x$grand.total
## Estimate WA scores for NA cases with newdata of excluded
## observations
- if (is.null(x$pCCA) && inherits(nas, "exclude")) {
+ if (is.null(x$pCCA) && inherits(nas, "exclude") &&
+ !inherits(x, "capscale")) {
if (!is.null(x$CCA))
x$CCA$wa.excluded <- predict(x, newdata = excluded,
type = "wa", model = "CCA")
Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog 2009-09-10 18:46:20 UTC (rev 1001)
+++ pkg/vegan/inst/ChangeLog 2009-09-11 07:16:53 UTC (rev 1002)
@@ -4,9 +4,8 @@
Version 1.16-28 (opened September 10, 200)
- * capscale: internal changes in the function to make it possible
- to have na.action. The results should be identical to the previous
- version, and the user should see no change (hope so).
+ * capscale: implemented na.action. The WA scores are always NA for
+ missing observations in capscale.
Version 1.16-27 (closed September 10, 2009)
Modified: pkg/vegan/man/capscale.Rd
===================================================================
--- pkg/vegan/man/capscale.Rd 2009-09-10 18:46:20 UTC (rev 1001)
+++ pkg/vegan/man/capscale.Rd 2009-09-11 07:16:53 UTC (rev 1002)
@@ -21,7 +21,7 @@
\usage{
capscale(formula, data, distance = "euclidean", sqrt.dist = FALSE,
comm = NULL, add = FALSE, dfun = vegdist, metaMDSdist = FALSE,
- ...)
+ na.action = na.fail, ...)
}
\arguments{
@@ -70,6 +70,15 @@
using extended flexible shortest path dissimilarities (function
\code{\link{stepacross}}) when there are many dissimilarities based on
no shared species.}
+ \item{na.action}{Handling of missing values in constraints or
+ conditions. The default (\code{\link{na.fail}}) is to stop
+ with missing values. Choices \code{\link{na.omit}} and
+ \code{\link{na.exclude}} delete rows with missing values, but
+ differ in representation of results. With \code{na.omit} only
+ non-missing site scores are shown, but \code{na.exclude} gives
+ \code{NA} for scores of missing observations. Unlike in
+ \code{\link{rda}}, no WA scores are available for missing
+ constraints or conditions.}
\item{\dots}{Other parameters passed to \code{\link{rda}} or to
\code{\link{metaMDSdist}}. }
}
More information about the Vegan-commits
mailing list