[Vegan-commits] r2275 - in branches/2.0: . R inst man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Sep 10 10:28:58 CEST 2012
Author: jarioksa
Date: 2012-09-10 10:28:57 +0200 (Mon, 10 Sep 2012)
New Revision: 2275
Added:
branches/2.0/R/density.anosim.R
branches/2.0/man/density.adonis.Rd
Modified:
branches/2.0/NAMESPACE
branches/2.0/R/density.oecosimu.R
branches/2.0/R/densityplot.oecosimu.R
branches/2.0/R/protest.R
branches/2.0/inst/ChangeLog
branches/2.0/man/adonis.Rd
branches/2.0/man/anosim.Rd
branches/2.0/man/anova.cca.Rd
branches/2.0/man/mantel.Rd
branches/2.0/man/mrpp.Rd
branches/2.0/man/procrustes.Rd
Log:
merge vegan density methods in range r2252...2266
Modified: branches/2.0/NAMESPACE
===================================================================
--- branches/2.0/NAMESPACE 2012-09-10 08:00:57 UTC (rev 2274)
+++ branches/2.0/NAMESPACE 2012-09-10 08:28:57 UTC (rev 2275)
@@ -131,8 +131,15 @@
# cophenetic: stats
S3method(cophenetic, spantree)
# density: stats
+S3method(density, adonis)
+S3method(density, anosim)
+S3method(density, mantel)
+S3method(density, mrpp)
S3method(density, oecosimu)
+S3method(density, permutest.cca)
+S3method(density, protest)
# densityplot: lattice
+S3method(densityplot, adonis)
S3method(densityplot, oecosimu)
# deviance: stats
S3method(deviance, cca)
@@ -256,6 +263,7 @@
S3method(plot, taxondive)
S3method(plot, varpart)
S3method(plot, varpart234)
+S3method(plot, vegandensity)
# points: graphics
S3method(points, cca)
S3method(points, decorana)
Copied: branches/2.0/R/density.anosim.R (from rev 2252, pkg/vegan/R/density.anosim.R)
===================================================================
--- branches/2.0/R/density.anosim.R (rev 0)
+++ branches/2.0/R/density.anosim.R 2012-09-10 08:28:57 UTC (rev 2275)
@@ -0,0 +1,136 @@
+### density & densityplot methods for vegan functions returning
+### statistics from permuted/simulated data. These are modelled after
+### density.oecosimu and densityplot.oecosimu (which are in their
+### separate files).
+
+## anosim
+
+`density.anosim` <-
+ function(x, ...)
+{
+ obs <- x$statistic
+ ## Put observed statistic among permutations
+ out <- density(c(obs, x$perm), ...)
+ out$call <- match.call()
+ out$observed <- obs
+ out$call[[1]] <- as.name("density")
+ class(out) <- c("vegandensity", class(out))
+ out
+}
+
+## adonis can return a matrix of terms, hence we also have densityplot()
+
+`density.adonis` <-
+ function(x, ...)
+{
+ cols <- ncol(x$f.perms)
+ if (cols > 1)
+ warning("'density' is meaningful only with one term, you have ", cols)
+ 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))
+ out
+}
+
+`densityplot.adonis` <-
+ function(x, data, xlab = "Null", ...)
+{
+ require(lattice) || stop("requires package 'lattice'")
+ 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,
+ panel = function(x, ...) {
+ panel.densityplot(x, ...)
+ panel.abline(v = obs[panel.number()], ...)
+ },
+ ...)
+}
+
+## mantel
+
+`density.mantel` <-
+ function(x, ...)
+{
+ 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))
+ out
+}
+
+## mrpp
+
+`density.mrpp` <-
+ function(x, ...)
+{
+ 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))
+ out
+}
+
+## anova.cca does not return permutation results, but permutest.cca
+## does. However, permutest.cca always finds only one statistic. Full
+## tables anova.cca are found by repeated calls to permutest.cca.
+
+`density.permutest.cca` <-
+ function(x, ...)
+{
+ 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))
+ out
+}
+
+## protest
+
+`density.protest` <-
+ function(x, ...)
+{
+ 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))
+ out
+}
+
+#### plot method: the following copies stats::plot.density() code but
+#### adds one new argument to draw abline(v=...) for the observed
+#### statistic
+
+`plot.vegandensity` <-
+ function (x, main = NULL, xlab = NULL, ylab = "Density", type = "l",
+ 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)
+ ## 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)
+ abline(v = x$observed, col = obs.line)
+ invisible(NULL)
+}
Modified: branches/2.0/R/density.oecosimu.R
===================================================================
--- branches/2.0/R/density.oecosimu.R 2012-09-10 08:00:57 UTC (rev 2274)
+++ branches/2.0/R/density.oecosimu.R 2012-09-10 08:28:57 UTC (rev 2275)
@@ -1,8 +1,14 @@
`density.oecosimu` <-
function(x, ...)
{
- out <- density(t(x$oecosimu$simulated), ...)
+ cols <- nrow(x$oecosimu$simulated)
+ if (cols > 1)
+ warning("'density' is meaningful only with one statistic, you have ", cols)
+ 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: branches/2.0/R/densityplot.oecosimu.R
===================================================================
--- branches/2.0/R/densityplot.oecosimu.R 2012-09-10 08:00:57 UTC (rev 2274)
+++ branches/2.0/R/densityplot.oecosimu.R 2012-09-10 08:28:57 UTC (rev 2275)
@@ -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: branches/2.0/R/protest.R
===================================================================
--- branches/2.0/R/protest.R 2012-09-10 08:00:57 UTC (rev 2274)
+++ branches/2.0/R/protest.R 2012-09-10 08:28:57 UTC (rev 2275)
@@ -12,9 +12,7 @@
tmp <- procrustes(X, Y[take, ], symmetric = TRUE)$ss
perm[i] <- sqrt(1 - tmp)
}
- perm <- c(sol$t0, perm)
- permutations <- permutations + 1
- Pval <- sum(perm >= sol$t0)/permutations
+ Pval <- (sum(perm >= sol$t0) + 1)/(permutations + 1)
if (!missing(strata)) {
strata <- deparse(substitute(strata))
s.val <- strata
Modified: branches/2.0/inst/ChangeLog
===================================================================
--- branches/2.0/inst/ChangeLog 2012-09-10 08:00:57 UTC (rev 2274)
+++ branches/2.0/inst/ChangeLog 2012-09-10 08:28:57 UTC (rev 2275)
@@ -7,6 +7,8 @@
* merge r2260: streamline adonis (internal changes).
* merge r2258: protect betadisper against changes in R-devel API.
* merge r2254: stylistic in examples of Rd files.
+ * merge r2252,56,57,61,64,66: add density methods for vegan
+ permutation functions and add plot.densityvegan to display these.
* merge r2250: do not use paste0 in envift.Rd (fails in R 2.14).
* merge r2249: fix vignette building with TeXLive 2012.
* merge r2246: remove dead code from cIndexKM() and R-devel CMD
Modified: branches/2.0/man/adonis.Rd
===================================================================
--- branches/2.0/man/adonis.Rd 2012-09-10 08:00:57 UTC (rev 2274)
+++ branches/2.0/man/adonis.Rd 2012-09-10 08:28:57 UTC (rev 2275)
@@ -129,10 +129,12 @@
sites; each column represents a fit of a sites distances (from all
other sites) to the linear model.These are what you get when you
fit distances of one site to
- your predictors. }
+ your predictors. }
\item{f.perms}{ an \eqn{N} by \eqn{m} matrix of the null \eqn{F}
- statistics for each source of variation based on \eqn{N}
- permutations of the data.}
+ statistics for each source of variation based on \eqn{N}
+ permutations of the data. The distribution of a single term can be
+ inspected with \code{\link{density.adonis}} function, or all terms
+ simultaneously with \code{densityplot.adonis}.}
\item{model.matrix}{The \code{\link{model.matrix}} for the right hand
side of the formula.}
\item{terms}{The \code{\link{terms}} component of the model.}
@@ -211,10 +213,10 @@
ordispider(mod, group=dat$field, lty=3, col="red")
### Correct hypothesis test (with strata)
-adonis(Y ~ NO3, data=dat, strata=dat$field, perm=1e3)
+adonis(Y ~ NO3, data=dat, strata=dat$field, perm=999)
### Incorrect (no strata)
-adonis(Y ~ NO3, data=dat, perm=1e3)
+adonis(Y ~ NO3, data=dat, perm=999)
}
\keyword{multivariate }
Modified: branches/2.0/man/anosim.Rd
===================================================================
--- branches/2.0/man/anosim.Rd 2012-09-10 08:00:57 UTC (rev 2274)
+++ branches/2.0/man/anosim.Rd 2012-09-10 08:28:57 UTC (rev 2275)
@@ -51,10 +51,11 @@
grouping.
The statistical significance of observed \eqn{R} is assessed by
- permuting the grouping vector to obtain the empirical
- distribution of \eqn{R} under null-model. See
- \code{\link{permutations}} for additional details on permutation tests
- in Vegan.
+ permuting the grouping vector to obtain the empirical distribution
+ of \eqn{R} under null-model. See \code{\link{permutations}} for
+ additional details on permutation tests in Vegan. The distribution
+ of simulated values can be inspected with the \code{density}
+ function.
The function has \code{summary} and \code{plot} methods. These both
show valuable information to assess the validity of the method: The
@@ -69,7 +70,8 @@
\item{call }{Function call.}
\item{statistic}{The value of ANOSIM statistic \eqn{R}}
\item{signif}{Significance from permutation.}
- \item{perm}{Permutation values of \eqn{R}}
+ \item{perm}{Permutation values of \eqn{R}. The distribution of
+ permutation values can be inspected with function \code{\link{density.anosim}}.}
\item{class.vec}{Factor with value \code{Between} for dissimilarities
between classes and class name for corresponding dissimilarity
within class.}
Modified: branches/2.0/man/anova.cca.Rd
===================================================================
--- branches/2.0/man/anova.cca.Rd 2012-09-10 08:00:57 UTC (rev 2274)
+++ branches/2.0/man/anova.cca.Rd 2012-09-10 08:28:57 UTC (rev 2275)
@@ -131,12 +131,16 @@
exit from the function.
}
-\value{
+\value{
Function \code{permutest.cca} returns an object of class
- \code{"permutest.cca"}, which has its own \code{print} method. The
- function \code{anova.cca} calls \code{permutest.cca}, fills an
- \code{\link{anova}} table and uses \code{\link{print.anova}} for printing.
+ \code{"permutest.cca"}, which has its own \code{print} method. The
+ distribution of permuted \eqn{F} values can be inspected with
+ \code{\link{density.permutest.cca}} function. The function
+ \code{anova.cca} calls \code{permutest.cca}, fills an
+ \code{\link{anova}} table and uses \code{\link{print.anova}} for
+ printing.
}
+
\note{
Some cases of \code{anova} need access to the original data on
constraints (at least \code{by = "term"} and \code{by = "margin"}),
Copied: branches/2.0/man/density.adonis.Rd (from rev 2264, pkg/vegan/man/density.adonis.Rd)
===================================================================
--- branches/2.0/man/density.adonis.Rd (rev 0)
+++ branches/2.0/man/density.adonis.Rd 2012-09-10 08:28:57 UTC (rev 2275)
@@ -0,0 +1,115 @@
+\name{density.adonis}
+\alias{density.adonis}
+\alias{density.anosim}
+\alias{density.mantel}
+\alias{density.mrpp}
+\alias{density.permutest.cca}
+\alias{density.protest}
+\alias{plot.vegandensity}
+\alias{densityplot.adonis}
+
+\title{
+ Kernel Density Estimation for Permutation Results in Vegan
+}
+
+\description{
+ The \code{density} functions can directly access the permutation
+ results of \pkg{vegan} functions, and \code{plot} can display the
+ densities. The \code{densityplot} method can access and display the
+ permutation results of functions that return permutations of several
+ statistics simultaneously.
+}
+
+\usage{
+\method{density}{adonis}(x, ...)
+\method{plot}{vegandensity}(x, main = NULL, xlab = NULL, ylab = "Density",
+ 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.}
+ \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, \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 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 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
+ \code{\link{adonis}}, \code{\link{anosim}}, \code{\link{mantel}},
+ \code{\link{mantel.partial}}, \code{\link{mrpp}},
+ \code{\link{permutest.cca}}, and \code{\link{protest}}. The
+ \code{density} function for \code{\link{oecosimu}} is documented
+ 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 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 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 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
+}
+
+\seealso{
+ \code{\link{density.default}}.
+}
+
+\examples{
+data(dune)
+data(dune.env)
+mod <- adonis(dune ~ Management, data = dune.env)
+plot(density(mod))
+library(lattice)
+mod <- adonis(dune ~ Management * Moisture, dune.env)
+densityplot(mod)
+}
+
+\keyword{ distribution }
+\keyword{ smooth }
Modified: branches/2.0/man/mantel.Rd
===================================================================
--- branches/2.0/man/mantel.Rd 2012-09-10 08:00:57 UTC (rev 2274)
+++ branches/2.0/man/mantel.Rd 2012-09-10 08:28:57 UTC (rev 2275)
@@ -56,7 +56,9 @@
\code{\link{cor.test}}.}
\item{statistic}{The Mantel statistic.}
\item{signif}{Empirical significance level from permutations.}
- \item{perm}{A vector of permuted values.}
+ \item{perm}{A vector of permuted values. The distribution of
+ permuted values can be inspected with \code{\link{density.mantel}}
+ function.}
\item{permutations}{Number of permutations.}
}
\references{ The test is due to Mantel, of course, but the
Modified: branches/2.0/man/mrpp.Rd
===================================================================
--- branches/2.0/man/mrpp.Rd 2012-09-10 08:00:57 UTC (rev 2274)
+++ branches/2.0/man/mrpp.Rd 2012-09-10 08:28:57 UTC (rev 2275)
@@ -138,7 +138,8 @@
the dist object.}
\item{weight.type}{The choice of group weights used.}
\item{boot.deltas}{The vector of "permuted deltas," the deltas
- calculated from each of the permuted datasets.}
+ calculated from each of the permuted datasets. The distribution of
+ this item can be inspected with \code{\link{density.mrpp}} function.}
\item{permutations}{The number of permutations used.}
}
\references{
Modified: branches/2.0/man/procrustes.Rd
===================================================================
--- branches/2.0/man/procrustes.Rd 2012-09-10 08:00:57 UTC (rev 2274)
+++ branches/2.0/man/procrustes.Rd 2012-09-10 08:28:57 UTC (rev 2275)
@@ -9,7 +9,6 @@
\alias{fitted.procrustes}
\alias{predict.procrustes}
\alias{protest}
-\alias{print.protest}
\title{Procrustes Rotation of Two Configurations and PROTEST }
\description{
@@ -161,7 +160,9 @@
\item{call}{Function call.}
\item{t0}{This and the following items are only in class
\code{protest}: Procrustes correlation from non-permuted solution.}
- \item{t}{Procrustes correlations from permutations.}
+ \item{t}{Procrustes correlations from permutations. The distribution
+ of these correlations can be inspected with \code{\link{density.protest}}
+ function.}
\item{signif}{`Significance' of \code{t}}
\item{permutations}{Number of permutations.}
\item{strata}{The name of the stratifying variable.}
More information about the Vegan-commits
mailing list