[Vegan-commits] r655 - in pkg/vegan: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Jan 12 08:28:50 CET 2009
Author: psolymos
Date: 2009-01-12 08:28:50 +0100 (Mon, 12 Jan 2009)
New Revision: 655
Modified:
pkg/vegan/R/lines.permat.R
pkg/vegan/R/plot.permat.R
pkg/vegan/man/permatfull.Rd
Log:
plotting methods and documentation updates for permatswap
Modified: pkg/vegan/R/lines.permat.R
===================================================================
--- pkg/vegan/R/lines.permat.R 2009-01-12 07:10:35 UTC (rev 654)
+++ pkg/vegan/R/lines.permat.R 2009-01-12 07:28:50 UTC (rev 655)
@@ -1,6 +1,11 @@
## S3 lines method for permat
`lines.permat` <-
-function(x, ...)
+function(x, type = "bray", ...)
{
- lines(summary(x)$bray, ...)
+ type <- match.arg(type, c("bray", "chisq"))
+ if (type == "bray")
+ toplot <- summary(x)$bray
+ if (type == "chisq")
+ toplot <- summary(x)$chisq$chisq.perm
+ lines(toplot, ...)
}
Modified: pkg/vegan/R/plot.permat.R
===================================================================
--- pkg/vegan/R/plot.permat.R 2009-01-12 07:10:35 UTC (rev 654)
+++ pkg/vegan/R/plot.permat.R 2009-01-12 07:28:50 UTC (rev 655)
@@ -1,9 +1,8 @@
## S3 plot method for permat
`plot.permat` <-
-function(x, ylab, xlab, col, lty, lowess=TRUE, plot=TRUE, text=TRUE, ...)
+function(x, type = "bray", ylab, xlab, col, lty, lowess=TRUE, plot=TRUE, text=TRUE, ...)
{
- if (missing(ylab))
- ylab <- "Bray-Curtis dissimilarity"
+ type <- match.arg(type, c("bray", "chisq"))
if (missing(xlab))
xlab <- "Runs"
if (missing(col))
@@ -11,16 +10,25 @@
if (missing(lty))
lty <- c(1,2)
n <- attr(x, "times")
- bray <- numeric(n)
- bray <- summary(x)$bray
+ toplot <- numeric(n)
+ if (type == "bray") {
+ toplot <- summary(x)$bray
+ if (missing(ylab))
+ ylab <- "Bray-Curtis dissimilarity"
+ }
+ if (type == "chisq") {
+ toplot <- summary(x)$chisq$chisq.perm
+ if (missing(ylab))
+ ylab <- "Chi-squared"
+ }
if (plot) {
- plot(bray,type="n",ylab=ylab,xlab=xlab, ...)
- lines(bray,col=col[1], lty=lty[1])
+ plot(toplot,type="n",ylab=ylab,xlab=xlab, ...)
+ lines(toplot,col=col[1], lty=lty[1])
if (lowess)
- lines(lowess(bray),col=col[2], lty=lty[2])
- if (text) title(sub=paste("(mean = ", substitute(z, list(z=round(mean(bray),3))),
- ", min = ", substitute(z, list(z=round(min(bray),3))),
- ", max = ", substitute(z, list(z=round(max(bray),3))), ")", sep=""))
+ lines(lowess(toplot),col=col[2], lty=lty[2])
+ if (text) title(sub=paste("(mean = ", substitute(z, list(z=round(mean(toplot),3))),
+ ", min = ", substitute(z, list(z=round(min(toplot),3))),
+ ", max = ", substitute(z, list(z=round(max(toplot),3))), ")", sep=""))
}
- invisible(bray)
+ invisible(toplot)
}
Modified: pkg/vegan/man/permatfull.Rd
===================================================================
--- pkg/vegan/man/permatfull.Rd 2009-01-12 07:10:35 UTC (rev 654)
+++ pkg/vegan/man/permatfull.Rd 2009-01-12 07:28:50 UTC (rev 655)
@@ -20,14 +20,14 @@
\usage{
permatfull(m, fixedmar = "both", shuffle = "ind", strata = NULL,
mtype = "count", times = 99)
-permatswap(m, method = "quasiswap", strata = NULL,
+permatswap(m, method = "quasiswap", shuffle = "both", strata = NULL,
mtype = "count", times = 99, burnin = 10000, thin = 1000)
permat.control(ptype = "full", mtype = "count", method = "quasiswap",
fixedmar = "both", shuffle = "ind", strata = NULL,
burnin = 10000, thin = 1000)
-\method{plot}{permat}(x, ylab, xlab, col, lty,
+\method{plot}{permat}(x, type = "bray", ylab, xlab, col, lty,
lowess = TRUE, plot = TRUE, text = TRUE, ...)
-\method{lines}{permat}(x, ...)
+\method{lines}{permat}(x, type = "bray", ...)
\method{summary}{permat}(object, ...)
\method{print}{summary.permat}(x, digits = 2, ...)
}
@@ -45,6 +45,7 @@
\item{x, object}{object of class \code{"permat"}}
\item{digits}{number of digits used for rounding.}
\item{ylab, xlab, col, lty}{graphical parameters for the \code{plot} method.}
+ \item{type}{character, type of plot to be displayed: \code{"bray"} for Bray-Curtis dissimilarities, \code{"chisq"} for Chi-squared values.}
\item{lowess, plot, text}{logical arguments for the \code{plot} method, whether a lowess curve should be drawn, the plot should be drawn, and statistic values should be printed on the plot.}
\item{\dots}{other arguments passed to methods.}
}
@@ -69,8 +70,10 @@
The 'quasiswapcount' algorithm (\code{method="quasiswap"} and \code{mtype="count"}) uses the same trick as Carsten Dormann's \code{\link[bipartite]{swap.web}} function in the package 'bipartite'. First, a random matrix is generated by the \code{\link{r2dtable}} function retaining row and column sums. Than the original matrix fill is reconstructed by sequential steps to increase or decrease matrix fill in the random matrix. These steps are based on swaping 2x2 submatrices (see 'swapcount' algorithm for details) to maintain row and column totals. This algorithm generates independent matrices in each step, so \code{burnin} and \code{thin} arguments are not considered. This is the default method, because this is not sequential (as 'swapcount' is) so independence of subsequent matrices does not have to be checked.
-The 'swapcount' algorithm (\code{method="swap"} and \code{mtype="count"}) tries to find 2x2 submatrices (identified by 2 random row and 2 random column indices), that can be swapped in order to leave column and row totals and fill unchanged. First, the algorithm finds the largest value in the submatrix that can be swapped (\eqn{d}) and whether in diagonal or antidiagonal way. Submatrices that contain values larger than zero in either diagonal or antidiagonal position can be swapped. Swap means that the values in diagonal or antidiagonal positions are decreased by \eqn{d}, while remaining cells are increased by \eqn{d}. A swap is made only if fill doesn't change. This algorithm is sequential, subsequent matrices are not independent, because swaps modify little if the matrix is large. In these cases many burnin steps and thinning is needed to get independent random matrices. Although this algorithm is implemented in C, large burmin and thin values can slow it down considerably.
+The 'swapcount' algorithm (\code{method="swap"} and \code{mtype="count"}) tries to find 2x2 submatrices (identified by 2 random row and 2 random column indices), that can be swapped in order to leave column and row totals and fill unchanged. First, the algorithm finds the largest value in the submatrix that can be swapped (\eqn{d}) and whether in diagonal or antidiagonal way. Submatrices that contain values larger than zero in either diagonal or antidiagonal position can be swapped. Swap means that the values in diagonal or antidiagonal positions are decreased by \eqn{d}, while remaining cells are increased by \eqn{d}. A swap is made only if fill doesn't change. This algorithm is sequential, subsequent matrices are not independent, because swaps modify little if the matrix is large. In these cases many burnin steps and thinning is needed to get independent random matrices. Although this algorithm is implemented in C, large burmin and thin values can slow it down considerably. WARNING: according to simulations, this algorithm seems to be biased and non random, thus its use should be avoided!
+The algorithm \code{"swsh"} in the function \code{permatswap} is a hybrid algorithm. First, it makes binary quasiswaps to keep row and column incidences constant, then non-zero values are modified according to the \code{shuffle} argument (only \code{"samp"} and \code{"both"} are available in this case, because it is applied only on non-zero values).
+
Constraints on row/colum sums, matrix fill, total sum and sums within
strata can be checked by the \code{summary} method. \code{plot} method is for
visually testing the randomness of the permuted matrices, especially for the
@@ -139,6 +142,7 @@
x2 <- permatfull(m)
summary(x2)
plot(x2)
+plot(x2, "chisq")
## Unrestricted permutation of presence-absence type
## not retaining row/columns sums:
x3 <- permatfull(m, "none", mtype="prab")
More information about the Vegan-commits
mailing list