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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Sep 3 10:02:25 CEST 2012


Author: jarioksa
Date: 2012-09-03 10:02:24 +0200 (Mon, 03 Sep 2012)
New Revision: 2266

Modified:
   pkg/vegan/R/density.anosim.R
   pkg/vegan/R/density.oecosimu.R
   pkg/vegan/R/densityplot.oecosimu.R
   pkg/vegan/inst/ChangeLog
   pkg/vegan/man/density.adonis.Rd
Log:
put observed value among permutations in density/densityplot

Modified: pkg/vegan/R/density.anosim.R
===================================================================
--- pkg/vegan/R/density.anosim.R	2012-09-02 15:49:32 UTC (rev 2265)
+++ pkg/vegan/R/density.anosim.R	2012-09-03 08:02:24 UTC (rev 2266)
@@ -8,9 +8,11 @@
 `density.anosim` <-
     function(x, ...)
 {
-    out <- density(x$perm, ...)
+    obs <- x$statistic
+    ## Put observed statistic among permutations
+    out <- density(c(obs, x$perm), ...)
     out$call <- match.call()
-    out$observed <- x$statistic
+    out$observed <- obs
     out$call[[1]] <- as.name("density")
     class(out) <- c("vegandensity", class(out))
     out
@@ -24,8 +26,10 @@
     cols <- ncol(x$f.perms)
     if (cols > 1)
         warning("'density' is meaningful only with one term, you have ", cols)
-    out <- density(x$f.perms, ...)
-    out$observed <- x$aov.tab$F.Model
+    obs <- x$aov.tab$F.Model
+    obs <- obs[!is.na(obs)]
+    out <- density(c(obs, x$f.perms), ...)
+    out$observed <- obs
     out$call <- match.call()
     out$call[[1]] <- as.name("density")
     class(out) <- c("vegandensity", class(out))
@@ -36,8 +40,9 @@
     function(x, data, xlab = "Null", ...)
 {
     require(lattice) || stop("requires package 'lattice'")
-    sim <- x$f.perms
     obs <- x$aov.tab$F.Model
+    obs <- obs[!is.na(obs)]
+    sim <- rbind(obs, x$f.perms)
     nm <- rownames(x$aov.tab)[col(sim)]
     densityplot( ~ as.vector(sim) | factor(nm, levels = unique(nm)),
                 xlab = xlab,
@@ -53,8 +58,9 @@
 `density.mantel` <-
     function(x, ...)
 {
-    out <- density(x$perm, ...)
-    out$observed <- x$statistic
+    obs <- x$statistic
+    out <- density(c(obs, x$perm), ...)
+    out$observed <- obs
     out$call <- match.call()
     out$call[[1]] <- as.name("density")
     class(out) <- c("vegandensity", class(out))
@@ -66,8 +72,9 @@
 `density.mrpp` <-
     function(x, ...)
 {
-    out <- density(x$boot.deltas, ...)
-    out$observed <- x$delta
+    obs <- x$delta
+    out <- density(c(obs, x$boot.deltas), ...)
+    out$observed <- obs
     out$call <- match.call()
     out$call[[1]] <- as.name("density")
     class(out) <- c("vegandensity", class(out))
@@ -81,8 +88,9 @@
 `density.permutest.cca` <-
     function(x, ...)
 {
-    out <- density(x$F.perm, ...)
-    out$observed <- x$F.0
+    obs <- x$F.0
+    out <- density(c(obs, x$F.perm), ...)
+    out$observed <- obs
     out$call <- match.call()
     out$call[[1]] <- as.name("density")
     class(out) <- c("vegandensity", class(out))
@@ -94,8 +102,9 @@
 `density.protest` <-
     function(x, ...)
 {
-    out <- density(x$t, ...)
-    out$observed <- x$t0
+    obs <- x$t0
+    out <- density(c(obs, x$t), ...)
+    out$observed <- obs
     out$call <- match.call()
     out$call[[1]] <- as.name("density")
     class(out) <- c("vegandensity", class(out))
@@ -108,28 +117,17 @@
 
 `plot.vegandensity` <-
     function (x, main = NULL, xlab = NULL, ylab = "Density", type = "l", 
-    zero.line = TRUE, obs.line = FALSE, ...) 
+    zero.line = TRUE, obs.line = TRUE, ...) 
 {
     if (is.null(xlab)) 
         xlab <- paste("N =", x$n, "  Bandwidth =", formatC(x$bw))
     if (is.null(main)) 
         main <- deparse(x$call)
-    ## adjust xlim of obs.line if needed
-    if (is.character(obs.line) || obs.line) {
-        xlim <- range(c(x$x, x$observed), na.rm = TRUE)
-        ## change obs.line to col=2 (red) if it was logical TRUE
-        if (isTRUE(obs.line))
-            obs.line <- 2
-    } else {
-        xlim <- NULL
-    }
-    ## check for explicit xlim in the call and use it if specified
-    if(!is.null(match.call(expand.dots = FALSE)$...$xlim))
-        plot.default(x, main = main, xlab = xlab, ylab = ylab, type = type,
-                     ...)
-    else
-        plot.default(x, main = main, xlab = xlab, ylab = ylab, type = type,
-                     xlim = xlim, ...)
+    ## change obs.line to col=2 (red) if it was logical TRUE
+    if (isTRUE(obs.line))
+        obs.line <- 2
+    plot.default(x, main = main, xlab = xlab, ylab = ylab, type = type,
+                 ...)
     if (zero.line) 
         abline(h = 0, lwd = 0.1, col = "gray")
     if (is.character(obs.line) || obs.line)

Modified: pkg/vegan/R/density.oecosimu.R
===================================================================
--- pkg/vegan/R/density.oecosimu.R	2012-09-02 15:49:32 UTC (rev 2265)
+++ pkg/vegan/R/density.oecosimu.R	2012-09-03 08:02:24 UTC (rev 2266)
@@ -4,11 +4,11 @@
     cols <- nrow(x$oecosimu$simulated)
     if (cols > 1)
         warning("'density' is meaningful only with one statistic, you have ", cols)
-    out <- density(t(x$oecosimu$simulated), ...)
-    out$observed <- x$oecosimu$statistic
+    obs <- x$oecosimu$statistic
+    out <- density(rbind(obs, t(x$oecosimu$simulated)), ...)
+    out$observed <- obs
     out$call <- match.call()
     out$call[[1]] <- as.name("density")
     class(out) <- c("vegandensity", class(out))
     out
 }
-

Modified: pkg/vegan/R/densityplot.oecosimu.R
===================================================================
--- pkg/vegan/R/densityplot.oecosimu.R	2012-09-02 15:49:32 UTC (rev 2265)
+++ pkg/vegan/R/densityplot.oecosimu.R	2012-09-03 08:02:24 UTC (rev 2266)
@@ -2,8 +2,8 @@
     function(x, data, xlab = "Simulated", ...)
 {
     require(lattice) || stop("requires package 'lattice'")
-    sim <- t(x$oecosimu$simulated)
     obs <- x$oecosimu$statistic
+    sim <- rbind(obs, t(x$oecosimu$simulated))
     nm <- names(obs)[col(sim)]
     densityplot( ~ as.vector(sim) | factor(nm, levels = unique(nm)),
                 xlab = xlab,

Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog	2012-09-02 15:49:32 UTC (rev 2265)
+++ pkg/vegan/inst/ChangeLog	2012-09-03 08:02:24 UTC (rev 2266)
@@ -25,10 +25,16 @@
 	access the returned statistic. The functions return an object of
 	class "vegandensity" that inherits from class "density". The
 	object is identical to class "density", but it is amended with
-	item "observed" that contains the observed statistic. It has a
-	plot.vegandensity() function that is similar to plot.density(),
-	but it also draws a vertical line for the observed statistic.
+	item "observed" that contains the observed statistic. The observed
+	statistic is also put among permuted values when estimating the
+	density. This can cause a pimple in density lines when the
+	observed statistic is very different from simulated values, but it
+	is consistent with the permutation tests.
 
+	The function has a plot.vegandensity() function that is similar to
+	plot.density(), but it also draws a vertical line for the observed
+	statistic.
+
 	The density methods were made available for adonis, anosim,
 	mantel & partial.mantel, mrpp, permutest.cca and procrustes. The
 	anova.cca function does not return permutated statistics.

Modified: pkg/vegan/man/density.adonis.Rd
===================================================================
--- pkg/vegan/man/density.adonis.Rd	2012-09-02 15:49:32 UTC (rev 2265)
+++ pkg/vegan/man/density.adonis.Rd	2012-09-03 08:02:24 UTC (rev 2266)
@@ -23,38 +23,39 @@
 \usage{
 \method{density}{adonis}(x, ...)
 \method{plot}{vegandensity}(x, main = NULL, xlab = NULL, ylab = "Density", 
-   type = "l", zero.line = TRUE, obs.line = FALSE, ...)
+   type = "l", zero.line = TRUE, obs.line = TRUE, ...)
 }
 
 \arguments{
   \item{x}{The object to be handled. For \code{density} and
      \code{densityplot} this is an object containing permutations. For
      \code{plot} this is a result of \pkg{vegan} \code{density}
-     function.  }
+     function.}
   \item{main, xlab, ylab, type, zero.line}{Arguments of
     \code{\link{plot.density}} and \code{\link[lattice]{densityplot}}
     functions.}
   \item{obs.line}{Draw vertical line for the observed
     statistic. Logical value \code{TRUE} draws a red line, and
-    \code{FALSE} draws nothing. Alternatively, this can be a
+    \code{FALSE} draws nothing. Alternatively, \code{obs.line} can be a
     definition of the colour used for the line, either as a numerical
-    value from the \code{\link[grDevices]{palette}} or a the name of
-    the colour, or other vallid definition of the colour.}
+    value from the \code{\link[grDevices]{palette}} or as the name of
+    the colour, or other normal definition of the colour.}
   \item{\dots}{ Other arguments passed to the function. In
     \code{density} these are passed to \code{\link{density.default}}.}
 }
 
 \details{ 
 
-  The \code{density} and \code{densityplot} function can directly
-  access permutation results of most \pkg{vegan} functions.  The
-  \code{density} function is identical to
-  \code{\link{density.default}} and takes all its arguments, but adds
-  the observed statistic to the result as item \code{"observed"}. The
-  \code{plot} method is similar to the default
-  \code{\link{plot.density}}, but can also add the observed statistic
-  to the graph as a vertical lline.  The \code{densityplot} function
-  is based on the same function in the \pkg{lattice} package (see
+  The \code{density} and \code{densityplot} function can directly access
+  permutation results of most \pkg{vegan} functions.  The \code{density}
+  function is identical to \code{\link{density.default}} and takes all
+  its arguments, but adds the observed statistic to the result as item
+  \code{"observed"}. The observed statistic is also put among the
+  permuted values so that the results are consistent with significance
+  tests. The \code{plot} method is similar to the default
+  \code{\link{plot.density}}, but can also add the observed statistic to
+  the graph as a vertical line.  The \code{densityplot} function is
+  based on the same function in the \pkg{lattice} package (see
   \code{\link[lattice]{densityplot}}).
 
   The density methods are available for \pkg{vegan} functions
@@ -65,31 +66,33 @@
   separately, and it is also used for \code{\link{adipart}},
   \code{\link{hiersimu}} and \code{\link{multipart}}.
 
-  All \pkg{vegan} \code{density} functions return an object q of
-  classes \code{"vegandensity"} inheriting from \code{\link{density}},
-  and can be plotted with its \code{plot} method.  This is identical
-  to the standard \code{plot} of \code{densiy} objects, but can also
-  add a vertical line for the observed statistic.
+  All \pkg{vegan} \code{density} functions return an object of class
+  \code{"vegandensity"} inheriting from \code{\link{density}}, and can
+  be plotted with its \code{plot} method.  This is identical to the
+  standard \code{plot} of \code{densiy} objects, but can also add a
+  vertical line for the observed statistic.
 
-  Functions that can return for several permuted statistics
-  simultaenously also have \code{\link[lattice]{densityplot}} method.
-  The standard \code{\link{density}} can only handle univariate data,
-  and a warning is issued it such a function is used for a model with
-  several observed statistic.  The \code{\link[lattice]{densityplot}}
-  method is available for \code{\link{adonis}} and
-  \code{\link{oecosimu}} (documented separately). NB, there is no
-  \code{density} method for \code{\link{anova.cca}}, but only for
-  \code{\link{permutest.cca}}.
+  Functions that can return several permuted statistics simultaenously
+  also have \code{\link[lattice]{densityplot}} method
+  (\code{\link{adonis}}, \code{\link{oecosimu}} and diversity partioning
+  functions based on \code{oecosimu}).  The standard
+  \code{\link{density}} can only handle univariate data, and a warning
+  is issued if the function is used for a model with several observed
+  statistics.  The \code{\link[lattice]{densityplot}} method is available
+  for \code{\link{adonis}} and \code{\link{oecosimu}} (documented
+  separately). NB, there is no \code{density} method for
+  \code{\link{anova.cca}}, but only for \code{\link{permutest.cca}}.
 
 }
 
 \value{
-  The \code{density} function returns the standard
-  \code{\link{density}} result object with one new item:
-  \code{"observed"} for the observed value of the statistic.
+  The \code{density} function returns the standard \code{\link{density}}
+  result object with one new item: \code{"observed"} for the observed
+  value of the statistic. The functions have a specific \code{plot}
+  method, but otherwise they use methods for
+  \code{\link{density.default}}, such as \code{print} and \code{lines}.
 }
 
-
 \author{
   Jari Oksanen
 }



More information about the Vegan-commits mailing list