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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Aug 24 18:58:35 CEST 2008


Author: jarioksa
Date: 2008-08-24 18:58:35 +0200 (Sun, 24 Aug 2008)
New Revision: 483

Modified:
   pkg/R/oecosimu.R
   pkg/R/print.oecosimu.R
   pkg/inst/ChangeLog
Log:
oecosimu handles vectors of statistics (needs fine tuning)

Modified: pkg/R/oecosimu.R
===================================================================
--- pkg/R/oecosimu.R	2008-08-22 11:44:53 UTC (rev 482)
+++ pkg/R/oecosimu.R	2008-08-24 16:58:35 UTC (rev 483)
@@ -8,7 +8,12 @@
                                   "quasiswap"))
     comm <- ifelse(comm > 0, 1, 0)
     ind <- nestfun(comm, ...)
-    simind <- numeric(nsimul)
+    if (is.list(ind))
+        indstat <- ind[["statistic"]]
+    else
+        indstat <- ind
+    n <- length(indstat)
+    simind <- matrix(0, nrow=n, ncol=nsimul)
     if (method %in% c("swap", "tswap")){
         checkbrd <- 1
         if (method == "tswap") {
@@ -26,22 +31,30 @@
                 x <- commsimulator(x, method= method, thin = round(checkbrd))
         for(i in 1:nsimul) {
             x <- commsimulator(x, method = method, thin = thin)
-            simind[i] <- nestfun(x, ...)$statistic
+            tmp <- nestfun(x, ...)
+            if (is.list(tmp))
+                simind[,i] <- tmp[["statistic"]]
+            else
+                simind[,i] <- tmp
         }
     }
     else {
         for (i in 1:nsimul) {
             x <- commsimulator(comm, method=method)
-            simind[i] <- nestfun(x,...)$statistic
+            tmp <- nestfun(x,...)
+            if (is.list(tmp))
+                simind[,i] <- tmp[["statistic"]]
+            else
+                simind[,i] <- tmp
         }
     }
-    z <- (ind$statistic - mean(simind))/sd(simind)
-    p <- 2*min(sum(ind$statistic > simind), sum(ind$statistic < simind))
+    z <- (indstat - rowMeans(simind))/apply(simind, 1, sd)
+    p <- 2*pmin(rowSums(indstat > simind), rowSums(indstat < simind))
     p <- (p + 1)/(nsimul + 1)
-    if (is.null(names(ind$statistic)))
-        names(ind$statistic) <- "Statistic"
+    if (is.null(names(indstat)))
+        names(indstat) <- "Statistic"
     ind$oecosimu <- list(z = z, pval = p, simulated=simind, method=method,
-                         statistic = ind$statistic)
+                         statistic = indstat)
     class(ind) <- c("oecosimu", class(ind))
     ind
 }

Modified: pkg/R/print.oecosimu.R
===================================================================
--- pkg/R/print.oecosimu.R	2008-08-22 11:44:53 UTC (rev 482)
+++ pkg/R/print.oecosimu.R	2008-08-24 16:58:35 UTC (rev 483)
@@ -1,18 +1,17 @@
 `print.oecosimu` <-
     function(x, ...)
 {
-    cat("oecosimu with", length(x$oecosimu$simulated), "simulations\n")
+    cat("oecosimu with", ncol(x$oecosimu$simulated), "simulations\n")
     cat("simulation method", x$oecosimu$method)
     if (length(att <- attributes(x$oecosimu$simulated)) > 0) {
         cat(" with", paste(names(att), att, collapse=", "))
     }
     cat("\n\n")
-    cat("summary of simulations:\n")
-    sum <- sort(c(x$oecosimu$statistic, summary(x$oecosimu$simulated)))
-    print(sum, ...)
-    cat("\n")
-    cat("P value (2-sided): ", format.pval(x$oecosimu$pval, ...), "\n")
-    cat("z (stat/sd(stat)): ", format(x$oecosimu$z), "\n\n")
+    qu <- apply(x$oecosimu$simulated, 1, quantile, probs=c(0.025, 0.5, 0.975))
+    m <- cbind("statistic" = x$oecosimu$statistic,
+               "z" = x$oecosimu$z, t(qu),
+               "Pr(sim.)"=x$oecosimu$pval)
+    printCoefmat(m)
     cl <- class(x)
     if (length(cl) > 1 && cl[2] != "list")
         NextMethod("print", x)

Modified: pkg/inst/ChangeLog
===================================================================
--- pkg/inst/ChangeLog	2008-08-22 11:44:53 UTC (rev 482)
+++ pkg/inst/ChangeLog	2008-08-24 16:58:35 UTC (rev 483)
@@ -3,8 +3,13 @@
 
 VEGAN DEVEL VERSIONS at http://r-forge.r-project.org/
 
-Version 1.14-10 (opened August 21, 2008: Prague Anniversary)
+Version 1.14-10 (opened August 21, 2008)
 
+	* oecosimu: accepts now a vector of statistics and plain
+	statistics instead of the list item statistics. This means that
+	things like species richness for sites can be analysed with
+	approprite simulation model (needs fine tuning, though).
+	
 	* ordiParseFormula: formula of the partial terms has the same
 	environment as the general formula. Cures some tricky issues when
 	the partial term of cca/rda/capscale model is updated within a



More information about the Vegan-commits mailing list