[Vegan-commits] r495 - pkg/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Sep 14 15:38:16 CEST 2008


Author: jarioksa
Date: 2008-09-14 15:38:16 +0200 (Sun, 14 Sep 2008)
New Revision: 495

Modified:
   pkg/R/add1.cca.R
Log:
add1.cca handles aliased terms & Condition()

Modified: pkg/R/add1.cca.R
===================================================================
--- pkg/R/add1.cca.R	2008-09-10 19:54:23 UTC (rev 494)
+++ pkg/R/add1.cca.R	2008-09-14 13:38:16 UTC (rev 495)
@@ -8,6 +8,8 @@
     cl <- class(out)
     ## Loop over terms in 'scope' and do anova.cca
     if (test == "permutation") {
+        ## Avoid nested Condition(Condition(x) + z)
+        hasfla <- update(terms(object$terminfo), . ~  Condition(.))
         if (!is.character(scope)) 
             scope <- add.scope(object, update.formula(object, scope))
         ns <- length(scope)
@@ -15,13 +17,19 @@
         adds[1, ] <- NA
         for (i in 1:ns) {
             tt <- scope[i]
-            if (!is.null(object$CCA))
-                nfit <- update(object,
-                               as.formula(paste(". ~  Condition(.) + ", tt)))
+            ## Condition(.) previous terms (if present)
+            if (!is.null(object$CCA)) {
+                fla <- update(hasfla, paste("~ . +", tt))
+                nfit <- update(object, fla)
+            }
             else
                 nfit <- update(object,
                                as.formula(paste(". ~ . +", tt)))
-            tmp <- anova(nfit, perm.max = perm.max, ...)
+            ## Handle completely aliased terms
+            if (is.null(nfit$CCA))
+                tmp <- matrix(NA, 1, 5)
+            else
+                tmp <- anova(nfit, perm.max = perm.max, ...)
             adds[i+1,] <- unlist(tmp[1,3:5])
         }
         colnames(adds) <- colnames(tmp)[3:5]



More information about the Vegan-commits mailing list