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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Mar 5 23:29:41 CET 2009


Author: psolymos
Date: 2009-03-05 23:29:41 +0100 (Thu, 05 Mar 2009)
New Revision: 720

Modified:
   pkg/vegan/R/as.ts.oecosimu.R
   pkg/vegan/R/diagnose.permat.R
   pkg/vegan/R/oecosimu.R
   pkg/vegan/R/permatswap.R
   pkg/vegan/R/summary.permat.R
   pkg/vegan/inst/ChangeLog
   pkg/vegan/man/diagnose.permat.Rd
Log:
time series related changes (tsp attribute now o.k., permat works with 
oecosimu)


Modified: pkg/vegan/R/as.ts.oecosimu.R
===================================================================
--- pkg/vegan/R/as.ts.oecosimu.R	2009-03-05 07:27:10 UTC (rev 719)
+++ pkg/vegan/R/as.ts.oecosimu.R	2009-03-05 22:29:41 UTC (rev 720)
@@ -1,9 +1,15 @@
 `as.ts.oecosimu` <-
     function(x, ...)
 {
-    seqmethods <- c("swap", "tswap")
+    seqmethods <- c("swap", "tswap", "permat.swap", "permat.abuswap")
     if (!(x$oecosimu$method %in% seqmethods))
         stop("as.ts available only for sequential methods ",
              paste(seqmethods, collapse=", "))
-    as.ts(t(x$oecosimu$simulated))
+    startval <- attr(x$oecosimu$simulated, "burnin") + 1 
+    thin <- attr(x$oecosimu$simulated, "thin")
+    out <- ts(t(x$oecosimu$simulated), start = startval, deltat=thin,
+        names = names(x$oecosimu$z))
+    attr(out, "burnin") <- NULL
+    attr(out, "thin") <- NULL
+    out
 }

Modified: pkg/vegan/R/diagnose.permat.R
===================================================================
--- pkg/vegan/R/diagnose.permat.R	2009-03-05 07:27:10 UTC (rev 719)
+++ pkg/vegan/R/diagnose.permat.R	2009-03-05 22:29:41 UTC (rev 720)
@@ -1,6 +1,8 @@
 diagnose.permat <-
 function(x, type = "bray", ...) {
-    tsVec <- ts(summary(x)[[type]])
+    tsVec <- summary(x)[[type]]
+    if (!is.ts(tsVec))
+        stop("'diagnose' method available only for sequential methods")
     ARmod <- arima(tsVec, order = c(1, 0, 0))
     ARmod$call <- match.call()
     ARresid <- ARmod$residuals

Modified: pkg/vegan/R/oecosimu.R
===================================================================
--- pkg/vegan/R/oecosimu.R	2009-03-05 07:27:10 UTC (rev 719)
+++ pkg/vegan/R/oecosimu.R	2009-03-05 22:29:41 UTC (rev 720)
@@ -82,22 +82,20 @@
             attr(simind, "burnin") <- NULL
         ## permatswap
         } else {
-            if (control$method %in% c("swap", "tswap")) {
-            if (burnin > 0) {
+            if (control$method %in% c("swap", "tswap", "abuswap") && burnin > 0) {
                 m <- permatswap(comm, method=control$method,
                     fixedmar=control$fixedmar,
                     shuffle=control$shuffle,
                     strata=control$strata,
                     mtype=control$mtype, times=1, 
                     burnin=burnin, thin=0)$perm[[1]]
-                } else m <- comm
-            }
+            }  else m <- comm
             for (i in 1:nsimul) {
-                x <- permatswap(comm, method=control$method,
+                x <- permatswap(m, method=control$method,
                     fixedmar=control$fixedmar,
                     shuffle=control$shuffle,
                     strata=control$strata,
-                    mtype=control$mtype, times=1, 
+                    mtype=control$mtype, times=1,
                     burnin=0, thin=thin)
                 tmp <- nestfun(x$perm[[1]], ...)
                 if (is.list(tmp))
@@ -118,6 +116,9 @@
     ## try e.g. oecosimu(dune, sum, "permat")
     if (any(is.na(z)))
         p[is.na(z)] <- NA
+    ## collapse method with control$method
+    if (method == "permat")
+        method <- paste("permat", control$method, sep=".")
 
     if (is.null(names(indstat)))
         names(indstat) <- statistic

Modified: pkg/vegan/R/permatswap.R
===================================================================
--- pkg/vegan/R/permatswap.R	2009-03-05 07:27:10 UTC (rev 719)
+++ pkg/vegan/R/permatswap.R	2009-03-05 22:29:41 UTC (rev 720)
@@ -150,7 +150,8 @@
                     }
                 } else perm[[i]][id,] <- commsimulator(temp, method=method)
             }
-            thin <- burnin <- 0
+            burnin <- 0
+            thin <- 0
         }
     } # for j end
     out <- list(call=match.call(), orig=m, perm=perm)

Modified: pkg/vegan/R/summary.permat.R
===================================================================
--- pkg/vegan/R/summary.permat.R	2009-03-05 07:27:10 UTC (rev 719)
+++ pkg/vegan/R/summary.permat.R	2009-03-05 22:29:41 UTC (rev 720)
@@ -31,6 +31,14 @@
     chisq <- sapply(x$perm, function(z) sum((z - E)^2 / E))
     attr(chisq, "chisq.orig") <- sum((x$orig - E)^2 / E)
 #    attr(chisq, "df") <- (nr - 1) * (nc - 1)
+    ## ts if sequential
+    seqmethods <- c("swap", "tswap", "abuswap")
+    if (attr(x, "method") %in% seqmethods) {
+        startval <- attr(x, "burnin") + 1 
+        dtime <- max(1, attr(x, "thin"))
+        bray <- ts(bray, start = startval, deltat = dtime)
+        chisq <- ts(chisq, start = startval, deltat = dtime)
+    }
     x$perm <- NULL
     out <- list(x=x, bray=bray, chisq=chisq, sum=psum, fill=pfill, rowsums=vrow, colsums=vcol,
         browsums=brow, bcolsums=bcol, strsum=ssum)

Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog	2009-03-05 07:27:10 UTC (rev 719)
+++ pkg/vegan/inst/ChangeLog	2009-03-05 22:29:41 UTC (rev 720)
@@ -5,14 +5,14 @@
 Version 1.16-14 (opened Feb 24, 2009)
 
 	* as.ts.oecosimu: new function for applying time series methods
-	for sequential null models ("swap", "tswap").  The method was
-	implemented to study a lighter alternative to permat.tsdiag and
-	lagplot functions of "permat" objects.
+	for sequential null models ("swap", "tswap", "abuswap").  The method was
+	implemented to study a lighter alternative to diagnose and
+	lagplot methods of "permat" objects.
 
 	* metaMDSrotate: a new function to rotate metaMDS configuration so
 	that the first axis is parallel with a continuous site variable.
 	
-	* permat.tsdiag: time series diagnostics for permat objects.
+	* diagnose.permat: time series diagnostics for permat objects.
 	Performs a first order ARIMA model and Ljung-Box test for the
 	independence of the residuals. This function is useful to diagnose
 	independence for sequential algorithms.

Modified: pkg/vegan/man/diagnose.permat.Rd
===================================================================
--- pkg/vegan/man/diagnose.permat.Rd	2009-03-05 07:27:10 UTC (rev 719)
+++ pkg/vegan/man/diagnose.permat.Rd	2009-03-05 22:29:41 UTC (rev 720)
@@ -33,7 +33,7 @@
 \details{
 
 The functions \code{lagplot} \code{diagnose} methods are useful for testing independence of permuted matrices
-when using sequential algorithms.
+when using sequential algorithms (\code{"swap", "tswap", "abuswap"}).
 
 }
 
@@ -62,10 +62,8 @@
 par(opar)
 ## The lagplot is useful to diagnose independence
 ## of successive simulations for sequential algorithms
-lagplot.permat(a, main="Not sequential") # independent
-lagplot.permat(b, main="Not sequential") # highly non-independent
+lagplot.permat(b) # highly non-independent
 ## Time series diagnostics
-diagnose(a)
 diagnose(b)
 }
 



More information about the Vegan-commits mailing list