[Vegan-commits] r1009 - in pkg/vegan: R inst man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Sep 16 19:24:30 CEST 2009


Author: jarioksa
Date: 2009-09-16 19:24:29 +0200 (Wed, 16 Sep 2009)
New Revision: 1009

Modified:
   pkg/vegan/R/cca.formula.R
   pkg/vegan/R/ordiParseFormula.R
   pkg/vegan/R/rda.formula.R
   pkg/vegan/inst/ChangeLog
   pkg/vegan/man/vegan-internal.Rd
Log:
cca, rda drop unused levels of factors plus a warning of a BUG with matrix items in formulae

Modified: pkg/vegan/R/cca.formula.R
===================================================================
--- pkg/vegan/R/cca.formula.R	2009-09-16 14:59:29 UTC (rev 1008)
+++ pkg/vegan/R/cca.formula.R	2009-09-16 17:24:29 UTC (rev 1009)
@@ -20,7 +20,7 @@
             drop = FALSE]
     }
     sol$terms <- d$terms
-    sol$terminfo <- ordiTerminfo(d, data)
+    sol$terminfo <- ordiTerminfo(d, d$modelframe)
     sol$na.action <- d$na.action
     sol$call <- match.call()
     sol$call[[1]] <- as.name("cca")

Modified: pkg/vegan/R/ordiParseFormula.R
===================================================================
--- pkg/vegan/R/ordiParseFormula.R	2009-09-16 14:59:29 UTC (rev 1008)
+++ pkg/vegan/R/ordiParseFormula.R	2009-09-16 17:24:29 UTC (rev 1009)
@@ -19,9 +19,12 @@
         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")
+    ## Get na.action attribute, remove NA and drop unused levels
+    if (NCOL(mf) > 0) {
+        mf <- model.frame(formula(mf), mf,
+                          na.action = na.action, drop.unused.levels = TRUE)
+        nas <- attr(mf, "na.action")
+    }
     else
         nas <- NULL
     if (!is.null(indPartial)) {
@@ -47,24 +50,18 @@
     else {
         if (exists("Pterm")) 
             xlev <- xlev[!(names(xlev) %in% Pterm)]
-        mf <- model.frame(formula, mf, na.action = na.pass, 
+        ymf <- model.frame(formula, mf, na.action = na.pass, 
             xlev = xlev)
-        Y <- model.matrix(formula, mf)
+        Y <- model.matrix(formula, ymf)
         if (any(colnames(Y) == "(Intercept)")) {
             xint <- which(colnames(Y) == "(Intercept)")
             Y <- Y[, -xint, drop = FALSE]
         }
     }
-    ## Check and remove NA
+    ## Check and remove NA in dependent data
     if (!is.null(nas)) {
         excluded <- X[nas, , drop = FALSE]
         X <- X[-nas,, drop=FALSE]
-        if (!is.null(Y)) {
-            Y <- Y[-nas,, drop=FALSE]
-            mf <- mf[-nas,, drop=FALSE]
-        }
-        if (!is.null(Z))
-            Z <- Z[-nas,, drop=FALSE]
     } else {
         excluded <-  NULL
     }

Modified: pkg/vegan/R/rda.formula.R
===================================================================
--- pkg/vegan/R/rda.formula.R	2009-09-16 14:59:29 UTC (rev 1008)
+++ pkg/vegan/R/rda.formula.R	2009-09-16 17:24:29 UTC (rev 1009)
@@ -20,7 +20,7 @@
             drop = FALSE]
     }
     sol$terms <- d$terms
-    sol$terminfo <- ordiTerminfo(d, data)
+    sol$terminfo <- ordiTerminfo(d, d$modelframe)
     sol$na.action <- d$na.action
     sol$call <- match.call()
     sol$call[[1]] <- as.name("rda")

Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog	2009-09-16 14:59:29 UTC (rev 1008)
+++ pkg/vegan/inst/ChangeLog	2009-09-16 17:24:29 UTC (rev 1009)
@@ -4,6 +4,21 @@
 
 Version 1.16-29 (opened September 15, 2009)
 
+	* WARNING OF A BUG in cca, rda & capscale: all versions have
+	failed since rev 972 (Sep 1, 2009) if an argument in a model was a
+	matrix. Now these things work so that tess pass, but results are
+	wrong , because get_all_vars() does not get names right for matrix
+	columns in the model frame. This is manifest in the example of
+	varpart() that uses matrix items (such as mite.pcnm). It can be
+	also seen with this:
+	p <- poly(dune.env$A1, 3)
+	cca(dune ~  p + Management, dune.env)
+	The following seems to work:
+	cca(dune ~  poly(A1, 3) + Management, dune.env)
+	
+	* cca, rda etc. drop unused levels of factors. This became actual
+	with 'subset' and 'na.action'.
+	
 	* 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
@@ -15,7 +30,7 @@
 	    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

Modified: pkg/vegan/man/vegan-internal.Rd
===================================================================
--- pkg/vegan/man/vegan-internal.Rd	2009-09-16 14:59:29 UTC (rev 1008)
+++ pkg/vegan/man/vegan-internal.Rd	2009-09-16 17:24:29 UTC (rev 1009)
@@ -17,7 +17,8 @@
 }
 \usage{
 ordiGetData(call, env)
-ordiParseFormula(formula, data, xlev = NULL, envdepth = 2, na.action = na.fail)
+ordiParseFormula(formula, data, xlev = NULL, envdepth = 2, 
+   na.action = na.fail, subset = NULL)
 ordiTerminfo(d, data)
 ordiNAexclude(x, excluded)
 ordiNApredict(omit, x)



More information about the Vegan-commits mailing list