[Vegan-commits] r496 - in pkg: R inst

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Sep 14 19:31:04 CEST 2008


Author: jarioksa
Date: 2008-09-14 19:31:04 +0200 (Sun, 14 Sep 2008)
New Revision: 496

Added:
   pkg/R/anova.ccanull.R
Modified:
   pkg/R/anova.cca.R
   pkg/R/anova.ccabymargin.R
   pkg/inst/ChangeLog
Log:
Improved handling of anova.cca when is.null(CCA) || is.null(CA): evident in anova.cca(..., by=margin) and drop1.cca

Modified: pkg/R/anova.cca.R
===================================================================
--- pkg/R/anova.cca.R	2008-09-14 13:38:16 UTC (rev 495)
+++ pkg/R/anova.cca.R	2008-09-14 17:31:04 UTC (rev 496)
@@ -2,10 +2,8 @@
     function (object, alpha = 0.05, beta = 0.01, step = 100, perm.max = 9999, 
               by = NULL, ...) 
 {
-    if (is.null(object$CA))
-        stop("Impossible analysis: no residual unconstrained component")
-    if (is.null(object$CCA))
-        stop("Nothing to analyse: no constrained component")
+    if (is.null(object$CA) || is.null(object$CCA))
+        return(anova.ccanull(object))
     perm.max <- max(step-1, perm.max)
     if (perm.max %% step == 0)
         perm.max <- perm.max - 1

Modified: pkg/R/anova.ccabymargin.R
===================================================================
--- pkg/R/anova.ccabymargin.R	2008-09-14 13:38:16 UTC (rev 495)
+++ pkg/R/anova.ccabymargin.R	2008-09-14 17:31:04 UTC (rev 496)
@@ -22,8 +22,6 @@
             fla <- paste(fla, updfla, sep="+")
         }
         tmp <- update(object, fla)
-        if (is.null(tmp$CCA))
-            stop("cannot analyse by = \"margin\" with complete aliasing")
         tmp <- anova(tmp, step=step, ...)
         ## Meaning is to start every permutation from the same seed, but
         ## get the seed of the longest simulation and reset the RNG

Added: pkg/R/anova.ccanull.R
===================================================================
--- pkg/R/anova.ccanull.R	                        (rev 0)
+++ pkg/R/anova.ccanull.R	2008-09-14 17:31:04 UTC (rev 496)
@@ -0,0 +1,31 @@
+### anova.cca cannot be performed if residuals or constraints are
+### NULL, and this function handles these cases (but it doesn't test
+### that these are the cases).
+`anova.ccanull` <-
+    function(object, ...)
+{
+    table <- matrix(0, nrow = 2, ncol = 5)
+    if (is.null(object$CA)) {
+        table[1,] <- c(object$CCA$rank, object$CCA$tot.chi, NA, 0, NA)
+        table[2,] <- c(0,0,NA,NA,NA)
+    }
+    else {
+        table[1,] <- c(0,0,0,0,NA)
+        table[2,] <- c(object$CA$rank, object$CA$tot.chi, NA, NA, NA)
+    }
+    rownames(table) <- c("Model", "Residual")
+    colnames(table) <-  c("Df",
+                          if (inherits(object, "rda")) "Var" else "Chisq", 
+                          "F", "N.Perm", "Pr(>F)")
+    table <- as.data.frame(table)
+    if (is.null(object$CA))
+        head <- "No residual component"
+    else if (is.null(object$CCA))
+        head <- "No constrained component"
+    else
+        head <- c("!!!!! ERROR !!!!!")
+    head <- c(head, paste("Model:", c(object$call)))
+    seed <- get(".Random.seed", envir = .GlobalEnv, inherits = FALSE)
+    structure(table, heading = head, Random.seed = seed,
+              class = c("anova.cca", "anova", "data.frame"))
+}

Modified: pkg/inst/ChangeLog
===================================================================
--- pkg/inst/ChangeLog	2008-09-14 13:38:16 UTC (rev 495)
+++ pkg/inst/ChangeLog	2008-09-14 17:31:04 UTC (rev 496)
@@ -13,6 +13,12 @@
 	implementing these tests was that I found out that step(..., test
 	= "Chisq") worked(!) producing parametric likelihood ratio tests,
 	and this hole had to be closed before users notice this.
+
+	* anova.cca: improved treatment of models where constrained or
+	unconstrained models are NULL so that permutation tests are
+	impossible. These used to stop with error, but now they return a
+	zeroed result so that things like anova(..., by = "term") and
+	drop1() work. Added function anova.ccanull to handle these cases.
 	
 Version 1.14-11 (closed September 10, 2008)
 



More information about the Vegan-commits mailing list