[Vegan-commits] r1007 - in pkg/vegan: . R inst man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Sep 15 15:51:07 CEST 2009
Author: jarioksa
Date: 2009-09-15 15:51:06 +0200 (Tue, 15 Sep 2009)
New Revision: 1007
Modified:
pkg/vegan/DESCRIPTION
pkg/vegan/R/cca.formula.R
pkg/vegan/R/ordiGetData.R
pkg/vegan/R/ordiParseFormula.R
pkg/vegan/R/rda.formula.R
pkg/vegan/inst/ChangeLog
pkg/vegan/man/cca.Rd
Log:
cca & rda got 'subset' selection
Modified: pkg/vegan/DESCRIPTION
===================================================================
--- pkg/vegan/DESCRIPTION 2009-09-13 06:53:00 UTC (rev 1006)
+++ pkg/vegan/DESCRIPTION 2009-09-15 13:51:06 UTC (rev 1007)
@@ -1,7 +1,7 @@
Package: vegan
Title: Community Ecology Package
-Version: 1.16-28
-Date: September 10, 2009
+Version: 1.16-29
+Date: September 15, 2009
Author: Jari Oksanen, Roeland Kindt, Pierre Legendre, Bob O'Hara, Gavin L. Simpson,
Peter Solymos, M. Henry H. Stevens, Helene Wagner
Maintainer: Jari Oksanen <jari.oksanen at oulu.fi>
Modified: pkg/vegan/R/cca.formula.R
===================================================================
--- pkg/vegan/R/cca.formula.R 2009-09-13 06:53:00 UTC (rev 1006)
+++ pkg/vegan/R/cca.formula.R 2009-09-15 13:51:06 UTC (rev 1007)
@@ -1,12 +1,13 @@
`cca.formula` <-
- function (formula, data, na.action = na.fail, ...)
+ function (formula, data, na.action = na.fail, subset = NULL, ...)
{
if (missing(data)) {
data <- parent.frame()
} else {
data <- ordiGetData(match.call(), environment(formula))
}
- d <- ordiParseFormula(formula, data, na.action = na.action)
+ d <- ordiParseFormula(formula, data, na.action = na.action,
+ subset = substitute(subset))
sol <- cca.default(d$X, d$Y, d$Z)
if (!is.null(sol$CCA))
sol$CCA$centroids <- centroids.cca(sol$CCA$wa, d$modelframe,
Modified: pkg/vegan/R/ordiGetData.R
===================================================================
--- pkg/vegan/R/ordiGetData.R 2009-09-13 06:53:00 UTC (rev 1006)
+++ pkg/vegan/R/ordiGetData.R 2009-09-15 13:51:06 UTC (rev 1007)
@@ -2,7 +2,7 @@
function (call, env)
{
call$scale <- call$distance <- call$comm <- call$add <-
- call$dfun <- call$sqrt.dist <- call$metaMDSdist <- NULL
+ call$dfun <- call$sqrt.dist <- call$metaMDSdist <- call$subset <- NULL
call$na.action <- na.pass
call[[2]] <- NULL
call[[1]] <- as.name("model.frame")
Modified: pkg/vegan/R/ordiParseFormula.R
===================================================================
--- pkg/vegan/R/ordiParseFormula.R 2009-09-13 06:53:00 UTC (rev 1006)
+++ pkg/vegan/R/ordiParseFormula.R 2009-09-15 13:51:06 UTC (rev 1007)
@@ -1,16 +1,25 @@
"ordiParseFormula" <-
-function (formula, data, xlev = NULL, envdepth = 2, na.action = na.fail)
+function (formula, data, xlev = NULL, envdepth = 2, na.action = na.fail,
+ subset = NULL)
{
Terms <- terms(formula, "Condition", data = data)
flapart <- fla <- formula <- formula(Terms, width.cutoff = 500)
specdata <- formula[[2]]
X <- eval.parent(specdata, n = envdepth)
- X <- as.matrix(X)
indPartial <- attr(Terms, "specials")$Condition
mf <- Z <- NULL
- ## Get na.action attribute
formula[[2]] <- NULL
mf <- get_all_vars(formula, data)
+ ## Select a subset of data and species
+ if (!is.null(subset)) {
+ subset <- eval(subset,
+ if (inherits(data, "data.frame")) cbind(data, X) else X,
+ parent.frame())
+ X <- X[subset, , drop = FALSE]
+ if (NROW(mf) > 0)
+ mf <- mf[subset, , drop = FALSE]
+ }
+ ## Get na.action attribute
if (NCOL(mf) > 0)
nas <- attr(model.frame(mf, na.action = na.action), "na.action")
else
@@ -21,7 +30,7 @@
Pterm <- paste(Pterm, collapse = "+")
P.formula <- as.formula(paste("~", Pterm), env = environment(formula))
zlev <- xlev[names(xlev) %in% Pterm]
- mf <- model.frame(P.formula, data, na.action = na.pass,
+ mf <- model.frame(P.formula, mf, na.action = na.pass,
xlev = zlev)
Z <- model.matrix(P.formula, mf)
if (any(colnames(Z) == "(Intercept)")) {
@@ -38,7 +47,7 @@
else {
if (exists("Pterm"))
xlev <- xlev[!(names(xlev) %in% Pterm)]
- mf <- model.frame(formula, data, na.action = na.pass,
+ mf <- model.frame(formula, mf, na.action = na.pass,
xlev = xlev)
Y <- model.matrix(formula, mf)
if (any(colnames(Y) == "(Intercept)")) {
@@ -59,6 +68,7 @@
} else {
excluded <- NULL
}
+ X <- as.matrix(X)
rownames(X) <- rownames(X, do.NULL = FALSE)
colnames(X) <- colnames(X, do.NULL = FALSE)
if (!is.null(Y)) {
Modified: pkg/vegan/R/rda.formula.R
===================================================================
--- pkg/vegan/R/rda.formula.R 2009-09-13 06:53:00 UTC (rev 1006)
+++ pkg/vegan/R/rda.formula.R 2009-09-15 13:51:06 UTC (rev 1007)
@@ -1,12 +1,14 @@
"rda.formula" <-
-function (formula, data, scale = FALSE, na.action = na.fail, ...)
+function (formula, data, scale = FALSE, na.action = na.fail,
+ subset = NULL, ...)
{
if (missing(data)) {
data <- parent.frame()
} else {
data <- ordiGetData(match.call(), environment(formula))
}
- d <- ordiParseFormula(formula, data, na.action = na.action)
+ d <- ordiParseFormula(formula, data, na.action = na.action,
+ subset = substitute(subset))
sol <- rda.default(d$X, d$Y, d$Z, scale)
if (!is.null(sol$CCA))
sol$CCA$centroids <- centroids.cca(sol$CCA$wa, d$modelframe)
Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog 2009-09-13 06:53:00 UTC (rev 1006)
+++ pkg/vegan/inst/ChangeLog 2009-09-15 13:51:06 UTC (rev 1007)
@@ -2,11 +2,25 @@
VEGAN DEVEL VERSIONS at http://r-forge.r-project.org/
-Version 1.16-28 (opened September 10, 200)
+Version 1.16-29 (opened September 15, 2009)
+ * cca & rda (but not (yet?) capscale) gained argument 'subset' to
+ select rows for analysis. A 'subset' can be a logical vector (TRUE
+ for kept rows), or a logical expression which can contain
+ variables in 'data' or species (variable) names of the dependent
+ data. Some valid examples are:
+ cca(dune ~ A1 + Moisture, dune.env,
+ subset = Management %in% c("HF","BF"))
+ cca(dune ~ Moisture, dune.env,
+ subset = Lolper > 0 & Management != "SF")
+ S <- specnumber(dune)
+ cca(dune ~ 1, subset = S > 9)
+
+Version 1.16-28 (closed September 15, 2009)
+
* drop1.cca: 'scope' given as a formula was not recognized and
permutation tests were not run. Only character vectors of names
- worked. Needs testing.
+ worked.
* envfit: handles missing values in ordination scores or in
environmental variables using na.rm argument. This also changes
Modified: pkg/vegan/man/cca.Rd
===================================================================
--- pkg/vegan/man/cca.Rd 2009-09-13 06:53:00 UTC (rev 1006)
+++ pkg/vegan/man/cca.Rd 2009-09-15 13:51:06 UTC (rev 1007)
@@ -19,9 +19,11 @@
These are all very popular ordination techniques in community ecology.
}
\usage{
-\method{cca}{formula}(formula, data, na.action = na.fail, ...)
+\method{cca}{formula}(formula, data, na.action = na.fail, subset = NULL,
+ ...)
\method{cca}{default}(X, Y, Z, ...)
-\method{rda}{formula}(formula, data, scale=FALSE, na.action = na.fail, ...)
+\method{rda}{formula}(formula, data, scale=FALSE, na.action = na.fail,
+ subset = NULL, ...)
\method{rda}{default}(X, Y, Z, scale=FALSE, ...)
}
@@ -46,6 +48,10 @@
calculated. The WA scores of rows may be found also for missing
values in constraints. Missing values are never allowed in
dependent community data. }
+ \item{subset}{Subset of data rows. This can be a logical vector which
+ is \code{TRUE} for kept observations, or a logical expression which
+ can contain variables in the working environment, \code{data} or
+ species names of the community data.}
\item{...}{Other arguments for \code{print} or \code{plot} functions
(ignored in other functions).}
}
More information about the Vegan-commits
mailing list