[Vegan-commits] r469 - in pkg: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Aug 12 09:24:32 CEST 2008


Author: psolymos
Date: 2008-08-12 09:24:32 +0200 (Tue, 12 Aug 2008)
New Revision: 469

Added:
   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/R/summary.permat.R
   pkg/man/permatfull.Rd
Removed:
   pkg/R/permatswap.R
   pkg/R/plot.permat.R
   pkg/R/print.permat.R
   pkg/R/print.summary.permat.R
   pkg/R/summary.permat.R
   pkg/man/permat.Rd
Log:
separate files for permat object class, but retaining svn ancestry


Copied: pkg/R/permatfull.R (from rev 467, pkg/R/permat.R)
===================================================================
--- pkg/R/permatfull.R	                        (rev 0)
+++ pkg/R/permatfull.R	2008-08-12 07:24:32 UTC (rev 469)
@@ -0,0 +1,53 @@
+## permatfull function
+`permatfull` <-
+function(m, fixedmar="both", reg=NULL, hab=NULL, mtype="count", times=100)
+{
+    if (!identical(all.equal(m, round(m)), TRUE))
+       stop("function accepts only integers (counts)")
+    mtype <- match.arg(mtype, c("prab", "count"))
+    count <- mtype == "count"
+    fixedmar <- match.arg(fixedmar, c("none", "rows", "columns", "both"))
+    m <- as.matrix(m)
+    n.row <- nrow(m)
+    n.col <- ncol(m)
+    if (mtype == "prab") m <- matrix(as.numeric(m > 0), n.row, n.col)
+    if (is.null(reg) && is.null(hab)) str <- as.factor(rep(1, n.row))
+    if (!is.null(reg) && is.null(hab)) str <- as.factor(reg)
+    if (is.null(reg) && !is.null(hab)) str <- as.factor(hab)
+    if (!is.null(reg) && !is.null(hab)) str <- interaction(reg, hab, drop=TRUE)
+    levels(str) <- 1:length(unique(str))
+    str <- as.numeric(str)
+    nstr <- length(unique(str))
+    if (any(tapply(str,list(str),length) == 1))
+        stop("strata should contain at least 2 observations")
+    perm <- list()
+    for (k in 1:times)
+        perm[[k]] <- matrix(0, n.row, n.col)
+    for (j in 1:nstr) {
+    id <- which(str == j)
+        if (fixedmar == "none")
+            for (i in 1:times)
+                if (count) perm[[i]][id,] <- matrix(sample(m[id,]), length(id), n.col)
+                else perm[[i]][id,] <- commsimulator(m[id,], method="r00")
+        if (fixedmar == "rows")
+            for (i in 1:times)
+                if (count) perm[[i]][id,] <- apply(m[id,], 2, sample)
+                else perm[[i]][id,] <- commsimulator(m[id,], method="r0")
+        if (fixedmar == "columns")
+            for (i in 1:times)
+                if (count) perm[[i]][id,] <- t(apply(m[id,], 1, sample))
+                else perm[[i]][id,] <- commsimulator(m[id,], method="c0")
+        if (fixedmar == "both")
+            for (i in 1:times)
+                if (count) perm[[i]][id,] <- r2dtable(1, apply(m[id,], 1, sum), apply(m[id,], 2, sum))[[1]]
+                else perm[[i]][id,] <- commsimulator(m[id,], method="quasiswap")
+        }
+    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
+    class(out) <- c("permat", "list")
+    return(out)
+}

Deleted: pkg/R/permatswap.R
===================================================================
--- pkg/R/permatswap.R	2008-08-12 06:23:56 UTC (rev 468)
+++ pkg/R/permatswap.R	2008-08-12 07:24:32 UTC (rev 469)
@@ -1,61 +0,0 @@
-## permatswap function
-`permatswap` <-
-function(m, reg=NULL, hab=NULL, mtype="count", method="swap", times=100, burnin = 10000, thin = 1000)
-{
-    if (!identical(all.equal(m, round(m)), TRUE))
-       stop("function accepts only integers (counts)")
-    mtype <- match.arg(mtype, c("prab", "count"))
-    count <- mtype == "count"
-    if (count) {
-        method <- match.arg(method, "swap")
-    } else {method <- match.arg(method, c("swap", "tswap"))}
-
-    m <- as.matrix(m)
-    n.row <- nrow(m)
-    n.col <- ncol(m)
-    if (mtype == "prab") m <- matrix(as.numeric(m > 0), n.row, n.col)
-    if (is.null(reg) && is.null(hab)) str <- as.factor(rep(1, n.row))
-    if (!is.null(reg) && is.null(hab)) str <- as.factor(reg)
-    if (is.null(reg) && !is.null(hab)) str <- as.factor(hab)
-    if (!is.null(reg) && !is.null(hab)) str <- interaction(reg, hab, drop=TRUE)
-    levels(str) <- 1:length(unique(str))
-    str <- as.numeric(str)
-    nstr <- length(unique(str))
-    if (any(tapply(str,list(str),length) == 1))
-        stop("strata should contain at least 2 observations")
-    perm <- list()
-    for (i in 1:times)
-        perm[[i]] <- matrix(0, n.row, n.col)
-
-    for (j in 1:nstr) {
-        id <- which(str == j)
-        temp <- m[id,]
-        if (count)
-            for (k in 1:burnin)
-                temp <- .C("swapcount", m = as.double(temp),
-                        as.integer(n.row), as.integer(n.col),
-                        as.integer(1), PACKAGE = "vegan")$m
-        else
-            for (k in 1:burnin)
-                temp <- commsimulator(temp, method=method)
-        for (i in 1:times) {
-            if (count)
-                perm[[i]][id,] <- .C("swapcount",
-                                  m = as.double(temp),
-                                  as.integer(n.row),
-                                  as.integer(n.col),
-                                  as.integer(thin),
-                                  PACKAGE = "vegan")$m
-	    else perm[[i]][id,] <- commsimulator(temp, method=method, thin=thin)
-            temp <- perm[[i]][id,]
-        }
-    }
-    specs <- list(reg=reg, hab=hab, burnin=burnin, thin=thin)
-    out <- list(call=match.call(), orig=m, perm=perm, specs=specs)
-    attr(out, "mtype") <- mtype
-    attr(out, "ptype") <- "swap"
-    attr(out, "fixedmar") <- "both"
-    attr(out, "times") <- times
-    class(out) <- c("permat", "list")
-    return(out)
-}

Copied: pkg/R/permatswap.R (from rev 467, pkg/R/permat.R)
===================================================================
--- pkg/R/permatswap.R	                        (rev 0)
+++ pkg/R/permatswap.R	2008-08-12 07:24:32 UTC (rev 469)
@@ -0,0 +1,61 @@
+## permatswap function
+`permatswap` <-
+function(m, reg=NULL, hab=NULL, mtype="count", method="swap", times=100, burnin = 10000, thin = 1000)
+{
+    if (!identical(all.equal(m, round(m)), TRUE))
+       stop("function accepts only integers (counts)")
+    mtype <- match.arg(mtype, c("prab", "count"))
+    count <- mtype == "count"
+    if (count) {
+        method <- match.arg(method, "swap")
+    } else {method <- match.arg(method, c("swap", "tswap"))}
+
+    m <- as.matrix(m)
+    n.row <- nrow(m)
+    n.col <- ncol(m)
+    if (mtype == "prab") m <- matrix(as.numeric(m > 0), n.row, n.col)
+    if (is.null(reg) && is.null(hab)) str <- as.factor(rep(1, n.row))
+    if (!is.null(reg) && is.null(hab)) str <- as.factor(reg)
+    if (is.null(reg) && !is.null(hab)) str <- as.factor(hab)
+    if (!is.null(reg) && !is.null(hab)) str <- interaction(reg, hab, drop=TRUE)
+    levels(str) <- 1:length(unique(str))
+    str <- as.numeric(str)
+    nstr <- length(unique(str))
+    if (any(tapply(str,list(str),length) == 1))
+        stop("strata should contain at least 2 observations")
+    perm <- list()
+    for (i in 1:times)
+        perm[[i]] <- matrix(0, n.row, n.col)
+
+    for (j in 1:nstr) {
+        id <- which(str == j)
+        temp <- m[id,]
+        if (count)
+            for (k in 1:burnin)
+                temp <- .C("swapcount", m = as.double(temp),
+                        as.integer(n.row), as.integer(n.col),
+                        as.integer(1), PACKAGE = "vegan")$m
+        else
+            for (k in 1:burnin)
+                temp <- commsimulator(temp, method=method)
+        for (i in 1:times) {
+            if (count)
+                perm[[i]][id,] <- .C("swapcount",
+                                  m = as.double(temp),
+                                  as.integer(n.row),
+                                  as.integer(n.col),
+                                  as.integer(thin),
+                                  PACKAGE = "vegan")$m
+	    else perm[[i]][id,] <- commsimulator(temp, method=method, thin=thin)
+            temp <- perm[[i]][id,]
+        }
+    }
+    specs <- list(reg=reg, hab=hab, burnin=burnin, thin=thin)
+    out <- list(call=match.call(), orig=m, perm=perm, specs=specs)
+    attr(out, "mtype") <- mtype
+    attr(out, "ptype") <- "swap"
+    attr(out, "fixedmar") <- "both"
+    attr(out, "times") <- times
+    class(out) <- c("permat", "list")
+    return(out)
+}

Deleted: pkg/R/plot.permat.R
===================================================================
--- pkg/R/plot.permat.R	2008-08-12 06:23:56 UTC (rev 468)
+++ pkg/R/plot.permat.R	2008-08-12 07:24:32 UTC (rev 469)
@@ -1,15 +0,0 @@
-## S3 plot method for permat
-`plot.permat` <-
-function(x, ...)
-{
-    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))), 
-        ", min = ", substitute(z, list(z=round(min(bray),3))),
-        ", max = ", substitute(z, list(z=round(max(bray),3))), ")", sep=""))
-    invisible(NULL)
-}

Copied: pkg/R/plot.permat.R (from rev 467, pkg/R/permat.R)
===================================================================
--- pkg/R/plot.permat.R	                        (rev 0)
+++ pkg/R/plot.permat.R	2008-08-12 07:24:32 UTC (rev 469)
@@ -0,0 +1,15 @@
+## S3 plot method for permat
+`plot.permat` <-
+function(x, ...)
+{
+    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))), 
+        ", min = ", substitute(z, list(z=round(min(bray),3))),
+        ", max = ", substitute(z, list(z=round(max(bray),3))), ")", sep=""))
+    invisible(NULL)
+}

Deleted: pkg/R/print.permat.R
===================================================================
--- pkg/R/print.permat.R	2008-08-12 06:23:56 UTC (rev 468)
+++ pkg/R/print.permat.R	2008-08-12 07:24:32 UTC (rev 469)
@@ -1,15 +0,0 @@
-## S3 print method for permat
-`print.permat` <-
-function(x, digits=3, ...)
-{
-    if (attr(x, "ptype") != "sar" & !is.null(x$specs$reg) | !is.null(x$specs$hab))
-        restr <- TRUE else restr <- FALSE
-    cat("Object of class 'permat'\n\nCall: ")
-    print(x$call)
-    cat("Matrix type:", attr(x, "mtype"), "\nPermutation type:", attr(x, "ptype"))
-    cat("\nRestricted:", restr, "\nFixed margins:", attr(x, "fixedmar"))
-    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))
-    cat("\nNumber of permuted matrices:", attr(x, "times"),"\n")
-}

Copied: pkg/R/print.permat.R (from rev 467, pkg/R/permat.R)
===================================================================
--- pkg/R/print.permat.R	                        (rev 0)
+++ pkg/R/print.permat.R	2008-08-12 07:24:32 UTC (rev 469)
@@ -0,0 +1,15 @@
+## S3 print method for permat
+`print.permat` <-
+function(x, digits=3, ...)
+{
+    if (attr(x, "ptype") != "sar" & !is.null(x$specs$reg) | !is.null(x$specs$hab))
+        restr <- TRUE else restr <- FALSE
+    cat("Object of class 'permat'\n\nCall: ")
+    print(x$call)
+    cat("Matrix type:", attr(x, "mtype"), "\nPermutation type:", attr(x, "ptype"))
+    cat("\nRestricted:", restr, "\nFixed margins:", attr(x, "fixedmar"))
+    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))
+    cat("\nNumber of permuted matrices:", attr(x, "times"),"\n")
+}

Deleted: pkg/R/print.summary.permat.R
===================================================================
--- pkg/R/print.summary.permat.R	2008-08-12 06:23:56 UTC (rev 468)
+++ pkg/R/print.summary.permat.R	2008-08-12 07:24:32 UTC (rev 469)
@@ -1,25 +0,0 @@
-## S3 print method for summary.permat
-`print.summary.permat` <-
-function(x, digits=2, ...)
-{
-    bray <- x$bray
-    restr <- x$restr
-    test <- x$test
-    x <- x$x
-    cat("Summary of object of class 'permat'\n\nCall: ")
-    print(x$call)
-    cat("Matrix type:", attr(x, "mtype"), "\nPermutation type:", attr(x, "ptype"))
-    cat("\nRestricted:", restr, "\nFixed margins:", attr(x, "fixedmar"))
-    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))
-    cat("\nNumber of permuted matrices:", attr(x, "times"),"\n")
-    cat("\nMatrix sums retained:", round(100*test[1], digits), "%")
-    cat("\nMatrix fill retained:", round(100*test[2], digits), "%")
-    cat("\nRow sums retained:   ", round(100*test[3], digits), "%")
-    cat("\nColumn sums retained:", round(100*test[4], digits), "%")
-    if (restr) cat("\nSums within strata retained:", round(100*test[5], digits), "%")
-    cat("\n\nBray-Curtis dissimilarities among original and permuted matrices:\n")
-    print(summary(bray))
-invisible(NULL)
-}

Copied: pkg/R/print.summary.permat.R (from rev 467, pkg/R/permat.R)
===================================================================
--- pkg/R/print.summary.permat.R	                        (rev 0)
+++ pkg/R/print.summary.permat.R	2008-08-12 07:24:32 UTC (rev 469)
@@ -0,0 +1,25 @@
+## S3 print method for summary.permat
+`print.summary.permat` <-
+function(x, digits=2, ...)
+{
+    bray <- x$bray
+    restr <- x$restr
+    test <- x$test
+    x <- x$x
+    cat("Summary of object of class 'permat'\n\nCall: ")
+    print(x$call)
+    cat("Matrix type:", attr(x, "mtype"), "\nPermutation type:", attr(x, "ptype"))
+    cat("\nRestricted:", restr, "\nFixed margins:", attr(x, "fixedmar"))
+    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))
+    cat("\nNumber of permuted matrices:", attr(x, "times"),"\n")
+    cat("\nMatrix sums retained:", round(100*test[1], digits), "%")
+    cat("\nMatrix fill retained:", round(100*test[2], digits), "%")
+    cat("\nRow sums retained:   ", round(100*test[3], digits), "%")
+    cat("\nColumn sums retained:", round(100*test[4], digits), "%")
+    if (restr) cat("\nSums within strata retained:", round(100*test[5], digits), "%")
+    cat("\n\nBray-Curtis dissimilarities among original and permuted matrices:\n")
+    print(summary(bray))
+invisible(NULL)
+}

Deleted: pkg/R/summary.permat.R
===================================================================
--- pkg/R/summary.permat.R	2008-08-12 06:23:56 UTC (rev 468)
+++ pkg/R/summary.permat.R	2008-08-12 07:24:32 UTC (rev 469)
@@ -1,32 +0,0 @@
-## S3 summary method for permat
-`summary.permat` <-
-function(object, ...)
-{
-    x <- object
-    n <- attr(x, "times")
-    if (attr(x, "ptype") != "sar" && !is.null(x$specs$reg) || !is.null(x$specs$hab))
-        restr <- TRUE else restr <- FALSE
-    if (restr) {
-        if (!is.null(x$specs$reg) && is.null(x$specs$hab)) int <- x$specs$reg
-        if (is.null(x$specs$reg) && !is.null(x$specs$hab)) int <- x$specs$hab
-        if (!is.null(x$specs$reg) && !is.null(x$specs$hab))
-            int <- interaction(x$specs$reg, x$specs$hab, drop=TRUE)
-	nlev <- length(unique(int))        
-	ssum <- numeric(n)}
-    bray <- psum <- pfill <- vrow <- vcol <- numeric(n)
-    for (i in 1:n) {
-        bray[i] <- sum(abs(x$orig-x$perm[[i]]))/sum(x$orig+x$perm[[i]])
-        psum[i] <- sum(x$orig) == sum(x$perm[[i]])
-        pfill[i] <- sum(x$orig > 0) == sum(x$perm[[i]] > 0)
-        vrow[i] <- sum(rowSums(x$orig) == rowSums(x$perm[[i]])) == nrow(x$orig)
-        vcol[i] <- sum(colSums(x$orig) == colSums(x$perm[[i]])) == ncol(x$orig)
-        if (restr) ssum[i] <- {sum(rowSums(aggregate(x$orig,list(int),sum)[,-1]) ==
-            rowSums(aggregate(x$perm[[i]],list(int),sum)[,-1])) == nlev}
-        }
-    strsum <- if (restr) sum(ssum)/n else NA
-    test <- c(sum=sum(psum)/n, fill=sum(pfill)/n, rowsums=sum(vrow)/n, colsums=sum(vcol)/n, strsum=strsum)
-    x$perm <- NULL
-    out <- list(x=x, bray=bray, test=test, restr=restr)
-    class(out) <- c("summary.permat", "list")
-    return(out)
-}

Copied: pkg/R/summary.permat.R (from rev 467, pkg/R/permat.R)
===================================================================
--- pkg/R/summary.permat.R	                        (rev 0)
+++ pkg/R/summary.permat.R	2008-08-12 07:24:32 UTC (rev 469)
@@ -0,0 +1,32 @@
+## S3 summary method for permat
+`summary.permat` <-
+function(object, ...)
+{
+    x <- object
+    n <- attr(x, "times")
+    if (attr(x, "ptype") != "sar" && !is.null(x$specs$reg) || !is.null(x$specs$hab))
+        restr <- TRUE else restr <- FALSE
+    if (restr) {
+        if (!is.null(x$specs$reg) && is.null(x$specs$hab)) int <- x$specs$reg
+        if (is.null(x$specs$reg) && !is.null(x$specs$hab)) int <- x$specs$hab
+        if (!is.null(x$specs$reg) && !is.null(x$specs$hab))
+            int <- interaction(x$specs$reg, x$specs$hab, drop=TRUE)
+	nlev <- length(unique(int))        
+	ssum <- numeric(n)}
+    bray <- psum <- pfill <- vrow <- vcol <- numeric(n)
+    for (i in 1:n) {
+        bray[i] <- sum(abs(x$orig-x$perm[[i]]))/sum(x$orig+x$perm[[i]])
+        psum[i] <- sum(x$orig) == sum(x$perm[[i]])
+        pfill[i] <- sum(x$orig > 0) == sum(x$perm[[i]] > 0)
+        vrow[i] <- sum(rowSums(x$orig) == rowSums(x$perm[[i]])) == nrow(x$orig)
+        vcol[i] <- sum(colSums(x$orig) == colSums(x$perm[[i]])) == ncol(x$orig)
+        if (restr) ssum[i] <- {sum(rowSums(aggregate(x$orig,list(int),sum)[,-1]) ==
+            rowSums(aggregate(x$perm[[i]],list(int),sum)[,-1])) == nlev}
+        }
+    strsum <- if (restr) sum(ssum)/n else NA
+    test <- c(sum=sum(psum)/n, fill=sum(pfill)/n, rowsums=sum(vrow)/n, colsums=sum(vcol)/n, strsum=strsum)
+    x$perm <- NULL
+    out <- list(x=x, bray=bray, test=test, restr=restr)
+    class(out) <- c("summary.permat", "list")
+    return(out)
+}

Deleted: pkg/man/permat.Rd
===================================================================
--- pkg/man/permat.Rd	2008-08-12 06:23:56 UTC (rev 468)
+++ pkg/man/permat.Rd	2008-08-12 07:24:32 UTC (rev 469)
@@ -1,130 +0,0 @@
-\name{permat}
-\alias{permatfull}
-\alias{permatswap}
-\alias{plot.permat}
-\alias{print.permat}
-\alias{summary.permat}
-\alias{print.summary.permat}
-
-\title{Matrix Permutation Algorithms for Presence-Absence and Count Data}
-
-\description{ Individual (for count data) or incidence (for
-presence-absence data) based null models can be generated for
-community level simulations. Options for preserving characteristics of
-the original matrix (rows/columns sums, matrix fill) and
-restricted permutations (within strata based on spatial units, habitat
-classes or both) are discussed in the Details section. By using these functions,
-hypothesis testing is separated from the null model generation, thus
-several tests can be applied on the same set of random matrices.  }
-
-\usage{
-permatfull(m, fixedmar = "both", 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{summary}{permat}(object, ...)
-\method{print}{summary.permat}(x, digits = 2, ...)
-}
-\arguments{
-  \item{m}{a community data matrix with plots (samples) as rows and species (taxa) as columns.}
-  \item{fixedmar}{character, stating which of the row/column sums should be preserved (\code{"none", "rows", "columns", "both"}).}
-  \item{reg}{numeric vector or factor with length same as \code{nrow(m)} for grouping rows within strata (regions) for restricted permutations. Unique values or levels are used.}
-  \item{hab}{numeric vector or factor with length same as \code{nrow(m)} for grouping rows within strata (habitat classes) for restricted permutations. Unique values or levels are used.}
-  \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{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{\dots}{other arguments passed to methods.}
-} 
-
-\details{
-The function \code{permatfull} is useful when matrix fill is allowed to vary, and matrix type is \code{count}.
-The \code{fixedmar} argument is used to set constraints for permutation.
-If \code{none} of the margins are fixed, cells are randomised within the matrix.
-If \code{rows} or \code{columns} are fixed, cells within rows or columns are randomised, respectively.
-If \code{both} margins are fixed, the \code{\link{r2dtable}} function is used that is based on
-Patefield's (1981) algorithm. For presence absence data, matrix fill is necessarily fixed, and \code{permatfull}
-is a wrapper for the function \code{\link{commsimulator}}. The \code{r00, r0, c0, quasiswap}
-algorithms of \code{\link{commsimulator}} are used for \code{"none", "rows", "columns", "both"} values 
-of the \code{fixedmar} argument, respectively 
-
-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.
-For presence-absence data, the \code{swap} and \code{tswap} methods of \code{\link{commsimulator}} can be used.
-For count data, a special swap algorithm (swapcount) is implemented that results in permuted matrices with
-fixed marginals and matrix fill at the same time.
-
-!!! THIS HAS TO BE EXTENDED WITH SWAPCOUNT ALGORITHM'S DOCUMENTATION !!!
-
-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 prmuted matrices, especially for the
-swap methods. If there are any tendency in the graph, higher \code{burnin} and 
-\code{thin} values can help.
-
-Unrestricted and restricted permutations: if both
-\code{reg} and \code{hab} are \code{NULL}, functions perform
-unrestricted permutations. If either of the two is given, it is used
-as is for restricted permutations. If both are given, interaction is
-used for restricted permutations. Each strata should contain at least 2 rows
-in order to perform randomization (in case of low row numbers, swap methods
-can be more slower).
-}
-
-\value{
-Functions \code{permatfull} and \code{permatswap} return an object of class \code{"permat"}.
-  \item{call}{the function call.}
-  \item{orig}{the original data matrix used for permutations.}
-  \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 invisibly containing mean
-Bray-Curtis dissimilarities calculated pairvise among original and
-permuted matrices, and check results of the constraints.  }
-
-\references{
-Original references for presence-absence swap methods are given on help
-page of \code{\link{commsimulator}}.
-
-Patefield, W. M. (1981) Algorithm AS159. An efficient method of generating r x c tables with given row and column totals. 
-Applied Statistics 30, 91-97.
-}
-
-\author{Peter Solymos, \email{Solymos.Peter at aotk.szie.hu}; Jari Oksanen translated the original swap algorithm for count data into C}
-
-\seealso{
-\code{\link{commsimulator}}, \code{\link{r2dtable}}, \code{\link{sample}}
-}
-\examples{
-## A simple artificial community data matrix.
-m <- matrix(c(
-   1,3,2,0,3,1,
-   0,2,1,0,2,1,
-   0,0,1,2,0,3,
-   0,0,0,1,4,3
-   ), 4, 6, byrow=TRUE)
-## Using the swap algorithm to create a 
-## list of permuted matrices, where
-## row/columns sums and matrix fill are preserved:
-x1 <- permatswap(m, burnin = 1000, thin = 100)
-summary(x1)
-plot(x1)
-## Unrestricted permutation retaining
-## row/columns sums but not matrix fill:
-x2 <- permatfull(m)
-summary(x2)
-plot(x2)
-## Unrestricted permutation of presence-absence type
-## not retaining row/columns sums:
-x3 <- permatfull(m, "none", mtype="prab")
-x3$orig  ## note: original matrix is binarized!
-summary(x3)
-## Restricted permutation,
-## check sums within strata:
-x4 <- permatfull(m, reg=c(1,1,2,2))
-summary(x4)
-}
-
-\keyword{multivariate}

Copied: pkg/man/permatfull.Rd (from rev 467, pkg/man/permat.Rd)
===================================================================
--- pkg/man/permatfull.Rd	                        (rev 0)
+++ pkg/man/permatfull.Rd	2008-08-12 07:24:32 UTC (rev 469)
@@ -0,0 +1,130 @@
+\name{permat}
+\alias{permatfull}
+\alias{permatswap}
+\alias{plot.permat}
+\alias{print.permat}
+\alias{summary.permat}
+\alias{print.summary.permat}
+
+\title{Matrix Permutation Algorithms for Presence-Absence and Count Data}
+
+\description{ Individual (for count data) or incidence (for
+presence-absence data) based null models can be generated for
+community level simulations. Options for preserving characteristics of
+the original matrix (rows/columns sums, matrix fill) and
+restricted permutations (within strata based on spatial units, habitat
+classes or both) are discussed in the Details section. By using these functions,
+hypothesis testing is separated from the null model generation, thus
+several tests can be applied on the same set of random matrices.  }
+
+\usage{
+permatfull(m, fixedmar = "both", 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{summary}{permat}(object, ...)
+\method{print}{summary.permat}(x, digits = 2, ...)
+}
+\arguments{
+  \item{m}{a community data matrix with plots (samples) as rows and species (taxa) as columns.}
+  \item{fixedmar}{character, stating which of the row/column sums should be preserved (\code{"none", "rows", "columns", "both"}).}
+  \item{reg}{numeric vector or factor with length same as \code{nrow(m)} for grouping rows within strata (regions) for restricted permutations. Unique values or levels are used.}
+  \item{hab}{numeric vector or factor with length same as \code{nrow(m)} for grouping rows within strata (habitat classes) for restricted permutations. Unique values or levels are used.}
+  \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{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{\dots}{other arguments passed to methods.}
+} 
+
+\details{
+The function \code{permatfull} is useful when matrix fill is allowed to vary, and matrix type is \code{count}.
+The \code{fixedmar} argument is used to set constraints for permutation.
+If \code{none} of the margins are fixed, cells are randomised within the matrix.
+If \code{rows} or \code{columns} are fixed, cells within rows or columns are randomised, respectively.
+If \code{both} margins are fixed, the \code{\link{r2dtable}} function is used that is based on
+Patefield's (1981) algorithm. For presence absence data, matrix fill is necessarily fixed, and \code{permatfull}
+is a wrapper for the function \code{\link{commsimulator}}. The \code{r00, r0, c0, quasiswap}
+algorithms of \code{\link{commsimulator}} are used for \code{"none", "rows", "columns", "both"} values 
+of the \code{fixedmar} argument, respectively 
+
+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.
+For presence-absence data, the \code{swap} and \code{tswap} methods of \code{\link{commsimulator}} can be used.
+For count data, a special swap algorithm (swapcount) is implemented that results in permuted matrices with
+fixed marginals and matrix fill at the same time.
+
+!!! THIS HAS TO BE EXTENDED WITH SWAPCOUNT ALGORITHM'S DOCUMENTATION !!!
+
+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 prmuted matrices, especially for the
+swap methods. If there are any tendency in the graph, higher \code{burnin} and 
+\code{thin} values can help.
+
+Unrestricted and restricted permutations: if both
+\code{reg} and \code{hab} are \code{NULL}, functions perform
+unrestricted permutations. If either of the two is given, it is used
+as is for restricted permutations. If both are given, interaction is
+used for restricted permutations. Each strata should contain at least 2 rows
+in order to perform randomization (in case of low row numbers, swap methods
+can be more slower).
+}
+
+\value{
+Functions \code{permatfull} and \code{permatswap} return an object of class \code{"permat"}.
+  \item{call}{the function call.}
+  \item{orig}{the original data matrix used for permutations.}
+  \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 invisibly containing mean
+Bray-Curtis dissimilarities calculated pairvise among original and
+permuted matrices, and check results of the constraints.  }
+
+\references{
+Original references for presence-absence swap methods are given on help
+page of \code{\link{commsimulator}}.
+
+Patefield, W. M. (1981) Algorithm AS159. An efficient method of generating r x c tables with given row and column totals. 
+Applied Statistics 30, 91-97.
+}
+
+\author{Peter Solymos, \email{Solymos.Peter at aotk.szie.hu}; Jari Oksanen translated the original swap algorithm for count data into C}
+
+\seealso{
+\code{\link{commsimulator}}, \code{\link{r2dtable}}, \code{\link{sample}}
+}
+\examples{
+## A simple artificial community data matrix.
+m <- matrix(c(
+   1,3,2,0,3,1,
+   0,2,1,0,2,1,
+   0,0,1,2,0,3,
+   0,0,0,1,4,3
+   ), 4, 6, byrow=TRUE)
+## Using the swap algorithm to create a 
+## list of permuted matrices, where
+## row/columns sums and matrix fill are preserved:
+x1 <- permatswap(m, burnin = 1000, thin = 100)
+summary(x1)
+plot(x1)
+## Unrestricted permutation retaining
+## row/columns sums but not matrix fill:
+x2 <- permatfull(m)
+summary(x2)
+plot(x2)
+## Unrestricted permutation of presence-absence type
+## not retaining row/columns sums:
+x3 <- permatfull(m, "none", mtype="prab")
+x3$orig  ## note: original matrix is binarized!
+summary(x3)
+## Restricted permutation,
+## check sums within strata:
+x4 <- permatfull(m, reg=c(1,1,2,2))
+summary(x4)
+}
+
+\keyword{multivariate}



More information about the Vegan-commits mailing list