[Vegan-commits] r527 - in pkg: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Oct 18 04:07:38 CEST 2008
Author: psolymos
Date: 2008-10-18 04:07:38 +0200 (Sat, 18 Oct 2008)
New Revision: 527
Modified:
pkg/R/permatfull.R
pkg/R/permatswap.R
pkg/R/plot.permat.R
pkg/R/print.permat.R
pkg/R/print.summary.permat.R
pkg/man/permatfull.Rd
Log:
shuffle argument with 3 options
Modified: pkg/R/permatfull.R
===================================================================
--- pkg/R/permatfull.R 2008-10-14 09:37:00 UTC (rev 526)
+++ pkg/R/permatfull.R 2008-10-18 02:07:38 UTC (rev 527)
@@ -1,6 +1,6 @@
## permatfull function
`permatfull` <-
-function(m, fixedmar="both", reg=NULL, hab=NULL, mtype="count", replace=TRUE, times=100)
+function(m, fixedmar="both", shuffle="ind", reg=NULL, hab=NULL, mtype="count", times=100)
{
## internal function
indshuffle <- function(x)
@@ -14,12 +14,21 @@
names(out) <- NULL
return(out)
}
+bothshuffle <- function(x)
+{
+x[x!=0] <- indshuffle(x[x!=0])
+return(sample(x))
+}
if (!identical(all.equal(m, round(m)), TRUE))
stop("function accepts only integers (counts)")
mtype <- match.arg(mtype, c("prab", "count"))
+ shuffle <- match.arg(shuffle, c("ind", "samp", "both"))
count <- mtype == "count"
fixedmar <- match.arg(fixedmar, c("none", "rows", "columns", "both"))
- sample.fun <- if (replace) indshuffle else sample
+ sample.fun <- switch(shuffle,
+ "ind"=indshuffle,
+ "samp"=sample,
+ "both"=bothshuffle)
m <- as.matrix(m)
n.row <- nrow(m)
n.col <- ncol(m)
@@ -56,14 +65,14 @@
else perm[[i]][id,] <- commsimulator(m[id,], method="quasiswap")
}
if (fixedmar == "both")
- replace <- NA
+ shuffle <- NA
specs <- list(reg=reg, hab=hab)
out <- list(call=match.call(), orig=m, perm=perm, specs=specs)
attr(out, "mtype") <- mtype
attr(out, "ptype") <- "full"
attr(out, "fixedmar") <- fixedmar
attr(out, "times") <- times
- attr(out, "replace") <- replace
+ attr(out, "shuffle") <- shuffle
class(out) <- c("permat", "list")
return(out)
}
Modified: pkg/R/permatswap.R
===================================================================
--- pkg/R/permatswap.R 2008-10-14 09:37:00 UTC (rev 526)
+++ pkg/R/permatswap.R 2008-10-18 02:07:38 UTC (rev 527)
@@ -56,7 +56,7 @@
attr(out, "ptype") <- "swap"
attr(out, "fixedmar") <- "both"
attr(out, "times") <- times
- attr(out, "replace") <- NA
+ attr(out, "shuffle") <- NA
class(out) <- c("permat", "list")
return(out)
}
Modified: pkg/R/plot.permat.R
===================================================================
--- pkg/R/plot.permat.R 2008-10-14 09:37:00 UTC (rev 526)
+++ pkg/R/plot.permat.R 2008-10-18 02:07:38 UTC (rev 527)
@@ -1,15 +1,16 @@
## S3 plot method for permat
`plot.permat` <-
-function(x, ...)
+function(x, ylab="Bray-Curtis dissimilarity", xlab="Runs", col=c(2,4), lty=c(1,2), plot=TRUE, text=TRUE, ...)
{
n <- attr(x, "times")
bray <- numeric(n)
for (i in 1:n) bray[i] <- sum(abs(x$orig-x$perm[[i]]))/sum(x$orig+x$perm[[i]])
- plot(bray,type="n",ylab="Bray-Curtis dissimilarity",xlab="Runs", ...)
- lines(bray,col="red")
- lines(lowess(bray),col="blue",lty=2)
- title(sub=paste("(mean = ", substitute(z, list(z=round(mean(bray),3))),
+ if (plot) {
+ plot(bray,type="n",ylab=ylab,xlab=xlab, ...)
+ lines(bray,col=col[1], lty=lty[1])
+ 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=""))
- invisible(NULL)
+ invisible(bray)
}
Modified: pkg/R/print.permat.R
===================================================================
--- pkg/R/print.permat.R 2008-10-14 09:37:00 UTC (rev 526)
+++ pkg/R/print.permat.R 2008-10-18 02:07:38 UTC (rev 527)
@@ -8,9 +8,11 @@
print(x$call)
cat("\nMatrix type:", attr(x, "mtype"), "\nPermutation type:", attr(x, "ptype"))
cat("\nRestricted:", restr, "\nFixed margins:", attr(x, "fixedmar"))
- if (!is.na(attr(x, "replace"))) {
- if (attr(x, "replace")) cat(" (individual based)")
- else cat(" (sample based)")}
+ if (!is.na(attr(x, "shuffle"))) {
+ if (attr(x, "shuffle")=="ind") cat("\nIndividuals")
+ if (attr(x, "shuffle")=="samp") cat("\nSamples")
+ if (attr(x, "shuffle")=="both") cat("\nIndividuals and samples")
+ cat(" are shuffled")}
cat("\n\nMatrix dimensions:", nrow(x$orig), "rows,", ncol(x$orig), "columns")
cat("\nSum of original matrix:", sum(x$orig))
cat("\nFill of original matrix:", round(sum(x$orig>0)/(nrow(x$orig)*ncol(x$orig)),digits))
Modified: pkg/R/print.summary.permat.R
===================================================================
--- pkg/R/print.summary.permat.R 2008-10-14 09:37:00 UTC (rev 526)
+++ pkg/R/print.summary.permat.R 2008-10-18 02:07:38 UTC (rev 527)
@@ -10,9 +10,11 @@
print(x$call)
cat("\nMatrix type:", attr(x, "mtype"), "\nPermutation type:", attr(x, "ptype"))
cat("\nRestricted:", restr, "\nFixed margins:", attr(x, "fixedmar"))
- if (!is.na(attr(x, "replace"))) {
- if (attr(x, "replace")) cat(" (individual based)")
- else cat(" (sample based)")}
+ if (!is.na(attr(x, "shuffle"))) {
+ if (attr(x, "shuffle")=="ind") cat("\nIndividuals")
+ if (attr(x, "shuffle")=="samp") cat("\nSamples")
+ if (attr(x, "shuffle")=="both") cat("\nIndividuals and samples")
+ cat(" are shuffled")}
cat("\n\nMatrix dimensions:", nrow(x$orig), "rows,", ncol(x$orig), "columns")
cat("\nSum of original matrix:", sum(x$orig))
cat("\nFill of original matrix:", round(sum(x$orig>0)/(nrow(x$orig)*ncol(x$orig)),digits))
Modified: pkg/man/permatfull.Rd
===================================================================
--- pkg/man/permatfull.Rd 2008-10-14 09:37:00 UTC (rev 526)
+++ pkg/man/permatfull.Rd 2008-10-18 02:07:38 UTC (rev 527)
@@ -19,11 +19,12 @@
several tests might be applied on the same set of random matrices. }
\usage{
-permatfull(m, fixedmar = "both", reg = NULL,
-hab = NULL, mtype = "count", replace = TRUE, times = 100)
+permatfull(m, fixedmar = "both", shuffle = "ind", reg = NULL,
+hab = NULL, mtype = "count", times = 100)
permatswap(m, reg = NULL, hab = NULL, mtype = "count",
method = "swap", times = 100, burnin = 10000, thin = 1000)
-\method{plot}{permat}(x, ...)
+\method{plot}{permat}(x, ylab="Bray-Curtis dissimilarity",
+xlab="Runs", col=c(2,4), lty=c(1,2), plot=TRUE, text=TRUE, ...)
\method{summary}{permat}(object, ...)
\method{print}{summary.permat}(x, digits = 2, ...)
}
@@ -35,11 +36,13 @@
\item{mtype}{matrix data type, either \code{"count"} for count data, or \code{"prab"} for presence-absence type incidence data.}
\item{times}{number of permuted matrices.}
\item{method}{character for method used for the swap algorithm (\code{"swap"}, \code{"tswap"}, \code{"backtrack"}) as described for function \code{\link{commsimulator}}. If \code{mtype="count"} only \code{"swap"} is available.}
- \item{replace}{logical, whether shuffle individuals (\code{TRUE}, default) or samples (cells, \code{FALSE}).}
+ \item{shuffle}{character, indicating whether individuals (\code{"ind"}), samples (\code{"samp"}) or both (\code{"both"}) should be shuffled, see details.}
\item{burnin}{number of null communities discarded before proper analysis in sequential (\code{"swap", "tswap"}) methods.}
\item{thin}{number of discarded permuted matrices between two evaluations in sequential (\code{"swap", "tswap"}) methods.}
\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{plot, text}{logical arguments for the \code{plot} method, whether a plot should be drawn, and statistic values should be printed on the plot.}
\item{\dots}{other arguments passed to methods.}
}
@@ -54,7 +57,7 @@
algorithms of \code{\link{commsimulator}} are used for \code{"none", "rows", "columns", "both"} values
of the \code{fixedmar} argument, respectively
-The \code{replace} argument only have effect if the \code{mtype = "count"} and \code{permatfull} function is used with \code{"none", "rows", "columns"} values of \code{fixedmar}. All other cases are for count data are individual based randomisations.
+The \code{shuffle} argument only have effect if the \code{mtype = "count"} and \code{permatfull} function is used with \code{"none", "rows", "columns"} values of \code{fixedmar}. All other cases for count data are individual based randomisations. The \code{"samp"} option results fixed matrix fill. The \code{"both"} option means that samples are shuffled, and individuals are shuffled among non zero cells. This however, not necessarily result in the same matrix fill. Matrix fill can be less than the original if samples bacame empty because of the shuffling of individuals.
The function \code{permatswap} is useful when matrix fill (i.e. the proportion of empty cells) should be kept constant.
\code{permatswap} uses different kinds of swap algorithms, and row and columns sums are fixed in all cases.
@@ -88,10 +91,12 @@
\item{perm}{a list of permuted matrices with length \code{times}.}
\item{specs}{a list of other specifications (variable in length, depending on the function used): \code{reg}, \code{hab}, \code{burnin}, \code{thin}.}
-\code{summary.permat} returns a list containing mean
+The \code{summary} method returns a list containing mean
Bray-Curtis dissimilarities calculated pairvise among original and
-permuted matrices, and check results of the constraints. }
+permuted matrices, and check results of the constraints.
+The \code{plot} method also returns the Bray-Curtis dissimilarities invisibly.
+}
\references{
Original references for presence-absence swap methods are given on help
page of \code{\link{commsimulator}}.
More information about the Vegan-commits
mailing list