From noreply at r-forge.r-project.org Thu Sep 5 11:57:29 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 5 Sep 2013 11:57:29 +0200 (CEST) Subject: [Vegan-commits] r2601 - pkg/vegan/R Message-ID: <20130905095729.A1ACE1851A3@r-forge.r-project.org> Author: jarioksa Date: 2013-09-05 11:57:29 +0200 (Thu, 05 Sep 2013) New Revision: 2601 Modified: pkg/vegan/R/MDSrotate.R Log: MDSrotate handles non-orthogonal designs and prepares to receive more than one external vector Modified: pkg/vegan/R/MDSrotate.R =================================================================== --- pkg/vegan/R/MDSrotate.R 2013-08-29 08:15:16 UTC (rev 2600) +++ pkg/vegan/R/MDSrotate.R 2013-09-05 09:57:29 UTC (rev 2601) @@ -36,7 +36,8 @@ } ## Rotation loop for (k in 2:N) { - rot <- vectorfit(x[keep, c(1,k)], vec[keep], permutations=0)$arrows + arrs <- vectorfit(x[keep,], vec[keep], permutations = 0)$arrows + rot <- arrs[c(1,k)]/sqrt(sum(arrs[c(1,k)]^2)) rot <- drop(rot) ## counterclockwise rotation matrix: ## [cos theta -sin theta] From noreply at r-forge.r-project.org Thu Sep 5 12:00:25 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 5 Sep 2013 12:00:25 +0200 (CEST) Subject: [Vegan-commits] r2602 - pkg/vegan/R Message-ID: <20130905100025.92F451802F0@r-forge.r-project.org> Author: jarioksa Date: 2013-09-05 12:00:25 +0200 (Thu, 05 Sep 2013) New Revision: 2602 Modified: pkg/vegan/R/MDSrotate.R Log: MDSrotate handles more than one external vector Modified: pkg/vegan/R/MDSrotate.R =================================================================== --- pkg/vegan/R/MDSrotate.R 2013-09-05 09:57:29 UTC (rev 2601) +++ pkg/vegan/R/MDSrotate.R 2013-09-05 10:00:25 UTC (rev 2602) @@ -15,46 +15,43 @@ N <- NCOL(x) if (N < 2) stop(gettextf("needs at least 2 dimensions")) - vec <- drop(vec) - if (length(dim(vec)) > 1) - stop(gettextf("function works only with univariate 'vec'")) + vec <- as.matrix(vec) + NV <- NCOL(vec) + if (NV >= N) + stop(gettextf("You can have max %d vectors, but you had %d", + N-1, NV)) if (!is.numeric(vec)) stop(gettextf("'vec' must be numeric")) ## vectorfit finds the direction cosine. We rotate first axis to ## 'vec' which means that we make other axes orthogonal to 'vec' ## one by one if (na.rm) - keep <- !is.na(vec) + keep <- complete.cases(vec) else - keep <- !logical(length(vec)) - ## scores must be orthogonal for the next loop to work - if (N > 2) { - pc <- prcomp(x[keep,]) - x <- x %*% pc$rotation - if (!all(is.na(sp))) - sp <- sp %*% pc$rotation - } + keep <- !logical(NROW(vec)) ## Rotation loop - for (k in 2:N) { - arrs <- vectorfit(x[keep,], vec[keep], permutations = 0)$arrows - rot <- arrs[c(1,k)]/sqrt(sum(arrs[c(1,k)]^2)) - rot <- drop(rot) - ## counterclockwise rotation matrix: - ## [cos theta -sin theta] - ## [sin theta cos theta] - rot <- rbind(rot, rev(rot)) - rot[1,2] <- -rot[1,2] - ## Rotation of points and species scores - x[, c(1,k)] <- x[, c(1,k)] %*% rot - if (!all(is.na(sp))) - sp[, c(1,k)] <- sp[, c(1,k)] %*% rot + for(v in seq_len(NV)) { + for (k in (v+1):N) { + arrs <- vectorfit(x[keep,], vec[keep,v], permutations = 0)$arrows + rot <- arrs[c(v,k)]/sqrt(sum(arrs[c(v,k)]^2)) + rot <- drop(rot) + ## counterclockwise rotation matrix: + ## [cos theta -sin theta] + ## [sin theta cos theta] + rot <- rbind(rot, rev(rot)) + rot[1,2] <- -rot[1,2] + ## Rotation of points and species scores + x[, c(v,k)] <- x[, c(v,k)] %*% rot + if (!all(is.na(sp))) + sp[, c(v,k)] <- sp[, c(v,k)] %*% rot + } } - ## Rotate 2..N axes to PC - if (N > 2 && attr(object$points, "pc")) { - pc <- prcomp(x[,-1]) - x[,-1] <- pc$x + ## Two or more free axes are (optionally) rotated to PCs + if (N - NV > 1 && attr(object$points, "pc")) { + pc <- prcomp(x[,-seq_len(NV)]) + x[,-seq_len(NV)] <- pc$x if (!all(is.na(sp))) - sp[,-1] <- sp[,-1] %*% pc$rotation + sp[,-seq_len(NV)] <- sp[,-seq_len(NV)] %*% pc$rotation } ## '[] <-' retains attributes object$points[] <- x From noreply at r-forge.r-project.org Thu Sep 5 12:01:18 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 5 Sep 2013 12:01:18 +0200 (CEST) Subject: [Vegan-commits] r2603 - in pkg/vegan: . inst man Message-ID: <20130905100118.79A601802F0@r-forge.r-project.org> Author: jarioksa Date: 2013-09-05 12:01:18 +0200 (Thu, 05 Sep 2013) New Revision: 2603 Modified: pkg/vegan/DESCRIPTION pkg/vegan/inst/ChangeLog pkg/vegan/man/MDSrotate.Rd Log: Document MDSrotate changes and version to 2.1-35 Modified: pkg/vegan/DESCRIPTION =================================================================== --- pkg/vegan/DESCRIPTION 2013-09-05 10:00:25 UTC (rev 2602) +++ pkg/vegan/DESCRIPTION 2013-09-05 10:01:18 UTC (rev 2603) @@ -1,7 +1,7 @@ Package: vegan Title: Community Ecology Package -Version: 2.1-34 -Date: August 28, 2013 +Version: 2.1-35 +Date: September 5, 2013 Author: Jari Oksanen, F. Guillaume Blanchet, Roeland Kindt, Pierre Legendre, Peter R. Minchin, R. B. O'Hara, Gavin L. Simpson, Peter Solymos, M. Henry H. Stevens, Helene Wagner Modified: pkg/vegan/inst/ChangeLog =================================================================== --- pkg/vegan/inst/ChangeLog 2013-09-05 10:00:25 UTC (rev 2602) +++ pkg/vegan/inst/ChangeLog 2013-09-05 10:01:18 UTC (rev 2603) @@ -2,8 +2,17 @@ VEGAN DEVEL VERSIONS at http://r-forge.r-project.org/ -Version 2.1-34 (opened August 28, 2013) +Version 2.1-35 (opened September 5, 2013) + * MDSrotate: can now rotate a solution to more than one vector, + provided that the number of dimensions is higher than the number + of vectors. Because fitted vectors usually are correlated, only + the first vector is aligned to dimension 1, but second vector and + further are oblique to the corresponding axis. In any case they + will have zero correlation to all subsequent dimensions. + +Version 2.1-34 (closed September 5, 2013) + * DESCRIPTION: dependent on R >= 2.14.0. * DESCRIPTION, vignettes: R 3.0.2-to-be checks with --as-cran Modified: pkg/vegan/man/MDSrotate.Rd =================================================================== --- pkg/vegan/man/MDSrotate.Rd 2013-09-05 10:00:25 UTC (rev 2602) +++ pkg/vegan/man/MDSrotate.Rd 2013-09-05 10:01:18 UTC (rev 2603) @@ -19,8 +19,10 @@ \item{object}{ A result object from \code{\link{metaMDS}} or \code{\link{monoMDS}}.} - \item{vec}{ A continuous environmental variable (vector of the same - length as the number of points).} + \item{vec}{ A continuous environmental variable or a matrix of such + variables. The number of variables must be lower than the number of + dimensions, and the solution is rotated to these variables in the + order they appear in the matrix.} \item{na.rm}{ Remove missing values from the continuous variable \code{vec}.} @@ -29,14 +31,22 @@ } -\details{ The orientation and rotation are undefined in - multidimensional scaling. Functions \code{\link{metaMDS}} and - \code{\link{metaMDS}} can rotate their solutions to principal - components so that the dispersion of the points is highest on the - first dimension. Sometimes a different rotation is more intuitive, - and \code{MDSrotate} allows rotation of the result so that the first - axis is parallel to a given external variable. -} +\details{ The orientation and rotation are undefined in multidimensional + scaling. Functions \code{\link{metaMDS}} and \code{\link{metaMDS}} + can rotate their solutions to principal components so that the + dispersion of the points is highest on the first dimension. Sometimes + a different rotation is more intuitive, and \code{MDSrotate} allows + rotation of the result so that the first axis is parallel to a given + external variable or two first variables are completely in a + two-dimensional plane etc. If several external variables are supplied, + they are applied in the order they are in the matrix. First axis is + rotated to the first supplied variable, and the second axis to the + second variable. Because variables are usually correlated, the second + variable is not usually aligned with the second axis, but it is + uncorrelated to later dimensions. There must be at least one free + dimension: the number of external variables must be lower than the + number of dimensions, and all used environmental variables are + uncorrelated with that free dimension.} \value{ Function returns the original ordination result, but with rotated scores (both site and species if available), and the From noreply at r-forge.r-project.org Fri Sep 6 10:12:24 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 6 Sep 2013 10:12:24 +0200 (CEST) Subject: [Vegan-commits] r2604 - pkg/vegan/R Message-ID: <20130906081224.39EA61851D9@r-forge.r-project.org> Author: jarioksa Date: 2013-09-06 10:12:23 +0200 (Fri, 06 Sep 2013) New Revision: 2604 Modified: pkg/vegan/R/print.vectorfit.R Log: vectorfit zaps nearly zero coordinates in printed output Modified: pkg/vegan/R/print.vectorfit.R =================================================================== --- pkg/vegan/R/print.vectorfit.R 2013-09-05 10:01:18 UTC (rev 2603) +++ pkg/vegan/R/print.vectorfit.R 2013-09-06 08:12:23 UTC (rev 2604) @@ -1,8 +1,9 @@ -"print.vectorfit" <- +`print.vectorfit` <- function (x, ...) { out <- cbind(x$arrows, r2 = x$r, "Pr(>r)" = x$pvals) - printCoefmat(out, na.print = "", ...) + printCoefmat(out, na.print = "", + zap.ind = seq_len(ncol(out)-2), ...) if (x$permutations) { cat("P values based on", x$permutations, "permutations") if (!is.null(x$strata)) From noreply at r-forge.r-project.org Fri Sep 6 15:29:20 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 6 Sep 2013 15:29:20 +0200 (CEST) Subject: [Vegan-commits] r2605 - pkg/vegan/vignettes Message-ID: <20130906132920.2A234184B6B@r-forge.r-project.org> Author: jarioksa Date: 2013-09-06 15:29:19 +0200 (Fri, 06 Sep 2013) New Revision: 2605 Modified: pkg/vegan/vignettes/FAQ-vegan.texi Log: add FAQ about LAPACK errors in cca/rda/capscale Modified: pkg/vegan/vignettes/FAQ-vegan.texi =================================================================== --- pkg/vegan/vignettes/FAQ-vegan.texi 2013-09-06 08:12:23 UTC (rev 2604) +++ pkg/vegan/vignettes/FAQ-vegan.texi 2013-09-06 13:29:19 UTC (rev 2605) @@ -334,6 +334,7 @@ * Where can I find numerical scores of ordination axes?:: * How the RDA results are scaled?:: * cca fails with ``data.frame expected'' or ``"site.env" missing'':: +* Ordination fails with ``Error in La.svd'':: * Variance explained by ordination axes:: * Can I have random effects in constrained ordination or in @code{adonis}?:: * Is it possible to have passive points in ordination?:: @@ -478,7 +479,7 @@ implementation details in vegan'' that you can read with @pkg{vegan} command @code{vegandocs("decision")}. - at node cca fails with ``data.frame expected'' or ``"site.env" missing'', Variance explained by ordination axes, How the RDA results are scaled?, Ordination + at node cca fails with ``data.frame expected'' or ``"site.env" missing'', Ordination fails with ``Error in La.svd'', How the RDA results are scaled?, Ordination @section cca fails with ``data.frame expected'' or ``"site.env" missing'' This is not a @pkg{vegan} error message, but it comes from the @@ -489,7 +490,29 @@ you do not need package @pkg{ade4}, you can detach it with command @code{detach(package:ade4)}. - at node Variance explained by ordination axes, Can I have random effects in constrained ordination or in @code{adonis}?, cca fails with ``data.frame expected'' or ``"site.env" missing'', Ordination + at node Ordination fails with ``Error in La.svd'', Variance explained by ordination axes, cca fails with ``data.frame expected'' or ``"site.env" missing'', Ordination + at section Ordination fails with ``Error in La.svd'' + +Constrained ordination (@code{cca}, @code{rda}, @code{capscale}) will +sometimes fail with error message + at code{Error in La.svd(x, nu, nv): error code 1 from Lapack routine 'dgesdd'.} + +It seems that the basic problem is in the @code{svd} function of + at code{LAPACK} that is used for numerical analysis in R. @code{LAPACK} +is an external library that is beyond the control of package developers +and R core team so that these problems may be unsolvable. It seems that +the problems with the LAPACK code are so common that even the help page +of @code{svd} warns about them + +Reducing the range of constraints (environmental variables) helps +sometimes. For instance, multiplying constraints by a constant < 1. This +rescaling does not influence the numerical results of constrained +ordination, but it can complicate further analyses when values of +constraints are needed, because the same scaling must be applied +there. We can only hope that this problem is fixed in the future +versions of R and @code{LAPACK}. + + at node Variance explained by ordination axes, Can I have random effects in constrained ordination or in @code{adonis}?, Ordination fails with ``Error in La.svd'', Ordination @section Variance explained by ordination axes. In general, @pkg{vegan} does not directly give any statistics on the From noreply at r-forge.r-project.org Fri Sep 6 15:32:11 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 6 Sep 2013 15:32:11 +0200 (CEST) Subject: [Vegan-commits] r2606 - www Message-ID: <20130906133211.74DC3184BCC@r-forge.r-project.org> Author: jarioksa Date: 2013-09-06 15:32:11 +0200 (Fri, 06 Sep 2013) New Revision: 2606 Modified: www/FAQ-vegan.html Log: web page of updated FAQ Modified: www/FAQ-vegan.html =================================================================== --- www/FAQ-vegan.html 2013-09-06 13:29:19 UTC (rev 2605) +++ www/FAQ-vegan.html 2013-09-06 13:32:11 UTC (rev 2606) @@ -2,7 +2,7 @@ - -