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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Sep 21 19:19:43 CEST 2009


Author: jarioksa
Date: 2009-09-21 19:19:43 +0200 (Mon, 21 Sep 2009)
New Revision: 1018

Modified:
   pkg/vegan/R/oecosimu.R
   pkg/vegan/R/print.oecosimu.R
   pkg/vegan/inst/ChangeLog
   pkg/vegan/man/oecosimu.Rd
Log:
oecosimu: new keyword 'alternative' for two or one-sided tests, and corrections in tie treatments in order statistics

Modified: pkg/vegan/R/oecosimu.R
===================================================================
--- pkg/vegan/R/oecosimu.R	2009-09-21 17:13:36 UTC (rev 1017)
+++ pkg/vegan/R/oecosimu.R	2009-09-21 17:19:43 UTC (rev 1018)
@@ -1,8 +1,10 @@
 `oecosimu` <-
     function(comm, nestfun, method, nsimul=99,
              burnin=0, thin=1, statistic = "statistic",
+             alternative = c("two.sided", "less", "greater"),
              ...)
 {
+    alternative <- match.arg(alternative)
     nestfun <- match.fun(nestfun)
     if (!is.function(method)) {
         method <- match.arg(method, c("r00", "r0", "r1", "r2", "c0",
@@ -93,13 +95,17 @@
         }
     }
     ## end of addition
-    
     sd <- apply(simind, 1, sd)
     z <- (indstat - rowMeans(simind))/sd
     if (any(sd < sqrt(.Machine$double.eps)))
         z[sd < sqrt(.Machine$double.eps)] <- 0
-    p <- 2*pmin(rowSums(indstat > simind), rowSums(indstat < simind))
-    p <- (p + 1)/(nsimul + 1)
+    pless <- rowSums(indstat <= simind)
+    pmore <- rowSums(indstat >= simind)
+    p <- switch(alternative,
+                two.sided = 2*pmin(pless, pmore),
+                less = pless,
+                greater = pmore)
+    p <- pmin(1, (p + 1)/(nsimul + 1))
 
     ## ADDITION: if z is NA then it is not correct to calculate p values
     ## try e.g. oecosimu(dune, sum, "permat")
@@ -113,7 +119,7 @@
     if (method == "custom")
         attr(method, "permfun") <- permfun
     ind$oecosimu <- list(z = z, pval = p, simulated=simind, method=method,
-                         statistic = indstat)
+                         statistic = indstat, alternative = alternative)
     class(ind) <- c("oecosimu", class(ind))
     ind
 }

Modified: pkg/vegan/R/print.oecosimu.R
===================================================================
--- pkg/vegan/R/print.oecosimu.R	2009-09-21 17:13:36 UTC (rev 1017)
+++ pkg/vegan/R/print.oecosimu.R	2009-09-21 17:19:43 UTC (rev 1018)
@@ -4,11 +4,17 @@
     attr(x$oecosimu$method, "permfun") <- NULL
     cat("oecosimu with", ncol(x$oecosimu$simulated), "simulations\n")
     cat("simulation method", x$oecosimu$method)
-    ## dim attribute is always there, but print all others
     if (length(att <- attributes(x$oecosimu$simulated)) > 1) {
         att$dim <- NULL
         cat(" with", paste(names(att), att, collapse=", "))
     }
+    alt.char <- switch(x$oecosimu$alternative,
+                       two.sided = "not equal to",
+                       less = "less than",
+                       greater = "greater than")
+    cat("\nalternative hypothesis: true mean is", alt.char, "the statistic")
+    ## dim attribute is always there, but print all others
+
     cat("\n\n")
     cl <- class(x)
     if (length(cl) > 1 && cl[2] != "list") {

Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog	2009-09-21 17:13:36 UTC (rev 1017)
+++ pkg/vegan/inst/ChangeLog	2009-09-21 17:19:43 UTC (rev 1018)
@@ -4,6 +4,16 @@
 
 Version 1.16-30 (opened September 18, 2009) 
 
+	* oecosimu: gained new keyword 'alternative' for "two.sided",
+	"less" and "greater" one-sided tests.
+	
+	* oecosimu: tied values in simulations and observed statistics
+	treated more correctly. 
+	
+	* oecosimu: if all simulations were constant, their sd became
+	zero, and z became NaN. Now z = 0 for these cases. A response to
+	the query of Martin Kopecky at the vegan-help forum in R-Forge.
+
 	* densitplot.oecosimu: panels keep the order of statistics. The
 	panels were ordered alphabetically, but the vertical line for the
 	observed statistic was in the original order (and thus often in

Modified: pkg/vegan/man/oecosimu.Rd
===================================================================
--- pkg/vegan/man/oecosimu.Rd	2009-09-21 17:13:36 UTC (rev 1017)
+++ pkg/vegan/man/oecosimu.Rd	2009-09-21 17:19:43 UTC (rev 1018)
@@ -20,7 +20,8 @@
 
 \usage{
 oecosimu(comm, nestfun, method, nsimul = 99, burnin = 0, thin = 1,
-   statistic = "statistic", ...)
+   statistic = "statistic", alternative = c("two.sided", "less", "greater"),
+   ...)
 commsimulator(x, method, thin=1)
 \method{as.ts}{oecosimu}(x, ...)
 \method{as.mcmc}{oecosimu}(x)
@@ -47,6 +48,9 @@
   \code{"swap"} and \code{"tswap"}.}
   \item{statistic}{The name of the statistic returned by
     \code{nestedfun}} 
+  \item{alternative}{a character string specifying the alternative
+    hypothesis, must be one of \code{"two.sided"} (default), \code{"greater"}
+    or \code{"less"}. You can specify just the initial letter.}
   \item{data}{Ignored argument of the generic function.}
   \item{xlab}{Label of the x-axis.}
   \item{\dots}{Other arguments to functions.}



More information about the Vegan-commits mailing list