[Vegan-commits] r2612 - in pkg/vegan: R inst man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Sep 10 09:36:36 CEST 2013
Author: jarioksa
Date: 2013-09-10 09:36:36 +0200 (Tue, 10 Sep 2013)
New Revision: 2612
Modified:
pkg/vegan/R/simulate.rda.R
pkg/vegan/inst/ChangeLog
pkg/vegan/man/simulate.rda.Rd
Log:
implement correlated simulation for cca, and clearly skip for capscale
Modified: pkg/vegan/R/simulate.rda.R
===================================================================
--- pkg/vegan/R/simulate.rda.R 2013-09-10 06:12:46 UTC (rev 2611)
+++ pkg/vegan/R/simulate.rda.R 2013-09-10 07:36:36 UTC (rev 2612)
@@ -91,8 +91,11 @@
### still guarantee that all marginal totals are positive.
`simulate.cca` <-
- function(object, nsim = 1, seed = NULL, indx = NULL, rank = "full", ...)
+ function(object, nsim = 1, seed = NULL, indx = NULL, rank = "full",
+ correlated = FALSE, ...)
{
+ if (is.null(indx) && correlated)
+ require(MASS) || stop("simulate options require MASS package")
## Handle RNG: code directly from stats::simulate.lm
if (!exists(".Random.seed", envir = .GlobalEnv, inherits = FALSE))
runif(1)
@@ -124,11 +127,17 @@
## Residual Xbar need weighting and back-weighting
Xbar <- sweep(object$CA$Xbar, 1, sq.r, "*")
## Simulation
+ if (correlated)
+ dev <- cov(Xbar)
+ else
+ dev <- outer(rep(1, nrow(ftd)), apply(Xbar, 2, sd))
ans <- array(0, c(dim(ftd), nsim))
for (i in seq_len(nsim)) {
if (is.null(indx)) {
- tmp <- matrix(rnorm(length(ftd),
- sd = outer(rep(1,nrow(ftd)), apply(Xbar, 2, sd))),
+ if (correlated)
+ tmp <- mvrnorm(nrow(ftd), numeric(ncol(ftd)), Sigma = dev)
+ else
+ tmp <- matrix(rnorm(length(ftd), sd = dev),
nrow = nrow(ftd))
ans[,,i] <- as.matrix(ftd + sweep(tmp, 1, sq.r, "/"))
}
@@ -176,8 +185,11 @@
### component.
`simulate.capscale` <-
- function(object, nsim = 1, seed = NULL, indx = NULL, rank = "full", ...)
+ function(object, nsim = 1, seed = NULL, indx = NULL, rank = "full",
+ correlated = FALSE, ...)
{
+ if (is.null(indx) && correlated)
+ warning("argument 'correlated' does not work and will be ignored")
## Handle RNG: code directly from stats::simulate.lm
if (!exists(".Random.seed", envir = .GlobalEnv, inherits = FALSE))
runif(1)
Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog 2013-09-10 06:12:46 UTC (rev 2611)
+++ pkg/vegan/inst/ChangeLog 2013-09-10 07:36:36 UTC (rev 2612)
@@ -11,6 +11,14 @@
further are oblique to the corresponding axis. In any case they
will have zero correlation to all subsequent dimensions.
+ * simulate.rda, simulate.cca: gained argument 'correlated' for
+ using covariances of species in generating correlated multivariate
+ normal residuals in parametric simulations. The covariances are
+ estimated from the residual ordination of species. The argument
+ defaults FALSE which implements the old parametric simulation
+ where each species is simulated independently. The argument has
+ no effect in capscale() which stores no information on species.
+
Version 2.1-34 (closed September 5, 2013)
* DESCRIPTION: dependent on R >= 2.14.0.
Modified: pkg/vegan/man/simulate.rda.Rd
===================================================================
--- pkg/vegan/man/simulate.rda.Rd 2013-09-10 06:12:46 UTC (rev 2611)
+++ pkg/vegan/man/simulate.rda.Rd 2013-09-10 07:36:36 UTC (rev 2612)
@@ -45,8 +45,9 @@
\item{correlated}{Are species regarded as correlated in parametric
simulation or when \code{indx} is not given? If
\code{correlated = TRUE}, multivariate Gaussian random error is
- generated, and if \code{FALSE}, Gaussian random error is
- generated separately for each species. }
+ generated, and if \code{FALSE}, Gaussian random error is generated
+ separately for each species. The argument has no effect in
+ \code{\link{capscale}} which has no information on species.}
\item{\dots}{additional optional arguments (ignored). }
}
More information about the Vegan-commits
mailing list