[Vegan-commits] r1004 - in pkg/vegan: R inst man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Sep 12 07:54:17 CEST 2009
Author: jarioksa
Date: 2009-09-12 07:54:15 +0200 (Sat, 12 Sep 2009)
New Revision: 1004
Modified:
pkg/vegan/R/envfit.default.R
pkg/vegan/R/envfit.formula.R
pkg/vegan/R/factorfit.R
pkg/vegan/R/print.envfit.R
pkg/vegan/R/vectorfit.R
pkg/vegan/inst/ChangeLog
pkg/vegan/man/envfit.Rd
Log:
envfit handles missing values with na.rm argument
Modified: pkg/vegan/R/envfit.default.R
===================================================================
--- pkg/vegan/R/envfit.default.R 2009-09-11 11:59:34 UTC (rev 1003)
+++ pkg/vegan/R/envfit.default.R 2009-09-12 05:54:15 UTC (rev 1004)
@@ -1,15 +1,26 @@
"envfit.default" <-
- function (X, P, permutations = 0, strata, choices = c(1, 2),
- ...)
+ function (ord, env, permutations = 0, strata, choices = c(1, 2),
+ display = "sites", w = weights(ord), na.rm = FALSE, ...)
{
+ weights.default <- function(object, ...) NULL
+ w < eval(w)
vectors <- NULL
factors <- NULL
seed <- NULL
- if (is.data.frame(P)) {
- facts <- unlist(lapply(P, is.factor))
+ X <- scores(ord, display = display, choices = choices, ...)
+ keep <- complete.cases(X) & complete.cases(env)
+ if (any(!keep)) {
+ if (!na.rm)
+ stop("missing values in data: consider na.rm = TRUE")
+ X <- X[keep,]
+ env <- env[keep,]
+ na.action <- structure(seq_along(keep)[!keep], class="omit")
+ }
+ if (is.data.frame(env)) {
+ facts <- unlist(lapply(env, is.factor))
if (sum(facts)) {
- Pfac <- P[, facts, drop = FALSE]
- P <- P[, !facts, drop = FALSE]
+ Pfac <- env[, facts, drop = FALSE]
+ P <- env[, !facts, drop = FALSE]
if (length(P)) {
if (permutations) {
if (!exists(".Random.seed", envir = .GlobalEnv,
@@ -20,20 +31,21 @@
inherits = FALSE)
}
vectors <- vectorfit(X, P, permutations, strata,
- choices, ...)
+ choices, w = w, ...)
}
if (!is.null(seed)) {
assign(".Random.seed", seed, envir = .GlobalEnv)
}
- factors <- factorfit(X, Pfac, permutations, strata,
- choices, ...)
+ factors <- factorfit(X, Pfac, permutations, strata, ...)
sol <- list(vector = vectors, factors = factors)
}
- else vectors <- vectorfit(X, P, permutations, strata,
- choices, ...)
+ else vectors <- vectorfit(X, env, permutations, strata,
+ choices, w = w, ...)
}
- else vectors <- vectorfit(X, P, permutations, strata, choices)
+ else vectors <- vectorfit(X, env, permutations, strata, ...)
sol <- list(vectors = vectors, factors = factors)
+ if (!is.null(na.action))
+ sol$na.action <- na.action
class(sol) <- "envfit"
sol
}
Modified: pkg/vegan/R/envfit.formula.R
===================================================================
--- pkg/vegan/R/envfit.formula.R 2009-09-11 11:59:34 UTC (rev 1003)
+++ pkg/vegan/R/envfit.formula.R 2009-09-12 05:54:15 UTC (rev 1004)
@@ -6,6 +6,6 @@
X <- formula[[2]]
X <- eval(X, data, parent.frame())
formula[[2]] <- NULL
- P <- model.frame(formula, data, na.action = na.fail)
+ P <- model.frame(formula, data, na.action = na.pass)
envfit(X, P, ...)
}
Modified: pkg/vegan/R/factorfit.R
===================================================================
--- pkg/vegan/R/factorfit.R 2009-09-11 11:59:34 UTC (rev 1003)
+++ pkg/vegan/R/factorfit.R 2009-09-12 05:54:15 UTC (rev 1004)
@@ -1,18 +1,13 @@
"factorfit" <-
- function (X, P, permutations = 0, strata, choices = c(1, 2),
- display = c("sites","lc"), w = weights(X), ...)
+ function (X, P, permutations = 0, strata, w, ...)
{
- weights.default <- function(object, ...) NULL
- display <- match.arg(display)
- w <- eval(w)
P <- as.data.frame(P)
if (any(!sapply(P, is.factor)))
stop("All fitted variables must be factors")
- X <- scores(X, display = display, choices, ...)
NR <- nrow(X)
NC <- ncol(X)
NF <- ncol(P)
- if (is.null(w))
+ if (missing(w) || is.null(w))
w <- 1
if (length(w) == 1)
w <- rep(w, NR)
Modified: pkg/vegan/R/print.envfit.R
===================================================================
--- pkg/vegan/R/print.envfit.R 2009-09-11 11:59:34 UTC (rev 1003)
+++ pkg/vegan/R/print.envfit.R 2009-09-12 05:54:15 UTC (rev 1004)
@@ -9,6 +9,8 @@
cat("\n***FACTORS:\n\n")
print(x$factors)
}
+ if (!is.null(x$na.action))
+ cat("\n", naprint(x$na.action), "\n", sep="")
invisible(x)
}
Modified: pkg/vegan/R/vectorfit.R
===================================================================
--- pkg/vegan/R/vectorfit.R 2009-09-11 11:59:34 UTC (rev 1003)
+++ pkg/vegan/R/vectorfit.R 2009-09-12 05:54:15 UTC (rev 1004)
@@ -1,12 +1,7 @@
"vectorfit" <-
- function (X, P, permutations = 0, strata, choices = c(1, 2),
- display = c("sites", "lc"), w = weights(X), ...)
+ function (X, P, permutations = 0, strata, w, ...)
{
- weights.default <- function(object, ...) NULL
- display <- match.arg(display)
- w <- eval(w)
- X <- scores(X, display = display, choices, ...)
- if (is.null(w))
+ if (missing(w) || is.null(w))
w <- 1
if (length(w) == 1)
w <- rep(w, nrow(X))
Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog 2009-09-11 11:59:34 UTC (rev 1003)
+++ pkg/vegan/inst/ChangeLog 2009-09-12 05:54:15 UTC (rev 1004)
@@ -4,6 +4,12 @@
Version 1.16-28 (opened September 10, 200)
+ * envfit: handles missing values in ordination scores or in
+ environmental variables using na.rm argument. This also changes
+ the user interface so that 'vectorfit' and 'factorfit' clearly
+ become low level functions which only accept scores (no ordination
+ objects), and all processing is done in envfit.default.
+
* wcmdscale: scores (points) with zero weights (w = 0) and other
non-finite entries will be NA.
Modified: pkg/vegan/man/envfit.Rd
===================================================================
--- pkg/vegan/man/envfit.Rd 2009-09-11 11:59:34 UTC (rev 1003)
+++ pkg/vegan/man/envfit.Rd 2009-09-12 05:54:15 UTC (rev 1004)
@@ -18,23 +18,32 @@
the factors show the averages of factor levels.
}
\usage{
-\method{envfit}{default}(X, P, permutations = 0, strata, choices=c(1,2), ...)
+\method{envfit}{default}(ord, env, permutations = 0, strata, choices=c(1,2),
+ display = "sites", w = weights(ord), na.rm = FALSE, ...)
\method{envfit}{formula}(formula, data, ...)
\method{plot}{envfit}(x, choices = c(1,2), arrow.mul, at = c(0,0), axis = FALSE,
p.max = NULL, col = "blue", add = TRUE, ...)
\method{scores}{envfit}(x, display, choices, ...)
-vectorfit(X, P, permutations = 0, strata, choices=c(1,2),
- display = c("sites", "lc"), w = weights(X), ...)
-factorfit(X, P, permutations = 0, strata, choices=c(1,2),
- display = c("sites", "lc"), w = weights(X), ...)
+vectorfit(X, P, permutations = 0, strata, w, ...)
+factorfit(X, P, permutations = 0, strata, w, ...)
}
\arguments{
- \item{X}{ Ordination configuration.}
- \item{P}{ Matrix or vector of environmental variable(s). }
+ \item{ord}{An ordination object or other structure from which the
+ ordination \code{\link{scores}} can be extracted (including a data
+ frame or matrix of scores)}.
+ \item{env}{Data frame, matrix or vector of environmental
+ variables. The variables can be of mixed type (factors, continuous
+ variables) in data frames.}
+ \item{X}{Matrix or data frame of ordination scores.}
+ \item{P}{Data frame, matrix or vector of environmental
+ variable(s). These must be continuous for \code{vectorfit} and
+ factors or characters for \code{factorfit}. }
\item{permutations}{ Number of permutations for assessing significance
of vectors or factors.}
\item{formula, data}{Model \code{\link{formula}} and data. }
+ \item{na.rm}{Remove points with missing values in ordination scores or
+ environmental variables}.
\item{x}{A result object from \code{envfit}.}
\item{choices}{Axes to plotted.}
\item{arrow.mul}{Multiplier for vector lengths. The arrows are
More information about the Vegan-commits
mailing list