From noreply at r-forge.r-project.org Sun Apr 7 08:00:58 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 7 Apr 2013 08:00:58 +0200 (CEST) Subject: [Vegan-commits] r2484 - in pkg/vegan: R inst Message-ID: <20130407060058.8184D18441F@r-forge.r-project.org> Author: jarioksa Date: 2013-04-07 08:00:57 +0200 (Sun, 07 Apr 2013) New Revision: 2484 Modified: pkg/vegan/R/betadisper.R pkg/vegan/inst/ChangeLog Log: betadisper(..., type = 'centroid') failed when there was only one group Modified: pkg/vegan/R/betadisper.R =================================================================== --- pkg/vegan/R/betadisper.R 2013-03-19 14:22:26 UTC (rev 2483) +++ pkg/vegan/R/betadisper.R 2013-04-07 06:00:57 UTC (rev 2484) @@ -92,11 +92,13 @@ ## Uses in-line Resids function as we want LAD residuals for ## median method, and LSQ residuals for centroid method dist.pos <- Resids(vectors[, pos, drop=FALSE], - centroids[group, pos, drop=FALSE]) + if (is.vector(centroids)) centroids[pos] + else centroids[group, pos, drop=FALSE]) dist.neg <- 0 if(any(!pos)) dist.neg <- Resids(vectors[, !pos, drop=FALSE], - centroids[group, !pos, drop=FALSE]) + if (is.vector(centroids)) centroids[!pos] + else centroids[group, !pos, drop=FALSE]) ## zij are the distances of each point to its group centroid zij <- sqrt(abs(dist.pos - dist.neg)) Modified: pkg/vegan/inst/ChangeLog =================================================================== --- pkg/vegan/inst/ChangeLog 2013-03-19 14:22:26 UTC (rev 2483) +++ pkg/vegan/inst/ChangeLog 2013-04-07 06:00:57 UTC (rev 2484) @@ -4,6 +4,10 @@ Version 2.1-28 (opened March 17, 2013) + * betadisper: failed with type = "centroid" when there was only + one group (i.e., in estimating the overall beta diversity in the + data). Reported by Pierre Legendre. + * rda: eigenvalues are now regarded as zero if they are very small compared to the first eigenvalue. Earlier we used fixed limit of 1e-4, but now the limit is first eigenvalues * 1e-5. Similar From noreply at r-forge.r-project.org Sun Apr 7 22:19:34 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 7 Apr 2013 22:19:34 +0200 (CEST) Subject: [Vegan-commits] r2485 - in pkg/vegan: R inst man Message-ID: <20130407201934.E8FCD18532D@r-forge.r-project.org> Author: gsimpson Date: 2013-04-07 22:19:34 +0200 (Sun, 07 Apr 2013) New Revision: 2485 Modified: pkg/vegan/R/betadisper.R pkg/vegan/R/eigenvals.R pkg/vegan/R/print.betadisper.R pkg/vegan/inst/ChangeLog pkg/vegan/man/betadisper.Rd Log: redo fix applied in r2484 in a different way, print 'mediod' when using type = "median", reduce number of eigenvalues printed, add eigenvals method for betadisper Modified: pkg/vegan/R/betadisper.R =================================================================== --- pkg/vegan/R/betadisper.R 2013-04-07 06:00:57 UTC (rev 2484) +++ pkg/vegan/R/betadisper.R 2013-04-07 20:19:34 UTC (rev 2485) @@ -18,6 +18,18 @@ spMedNeg <- ordimedian(vectors, group, choices = axes[!pos]) cbind(spMedPos, spMedNeg) } + ## inline function for centroids + centroidFUN <- function(vec, group) { + cent <- apply(vec, 2, + function(x, group) tapply(x, INDEX = group, FUN = mean), + group = group) + if(!is.matrix(cent)) { ## if only 1 group, cent is vector + cent <- matrix(cent, nrow = 1, + dimnames = list(as.character(levels(group)), + paste0("Dim", seq_len(NCOL(vec))))) + } + cent + } ## inline function for distance computation Resids <- function(x, c) { if(is.matrix(c)) @@ -69,7 +81,6 @@ warning("Missing observations due to 'd' removed.") } x <- x + t(x) - storage.mode(x) <- "double" x <- dblcen(x) e <- eigen(-x/2, symmetric = TRUE) vectors <- e$vectors @@ -84,7 +95,7 @@ ## group centroids in PCoA space centroids <- switch(type, - centroid = apply(vectors, 2, function(x) tapply(x, group, mean)), + centroid = centroidFUN(vectors, group), median = spatialMed(vectors, group, pos) ) ## for each of the groups, calculate distance to centroid for @@ -92,13 +103,11 @@ ## Uses in-line Resids function as we want LAD residuals for ## median method, and LSQ residuals for centroid method dist.pos <- Resids(vectors[, pos, drop=FALSE], - if (is.vector(centroids)) centroids[pos] - else centroids[group, pos, drop=FALSE]) + centroids[group, pos, drop=FALSE]) dist.neg <- 0 if(any(!pos)) dist.neg <- Resids(vectors[, !pos, drop=FALSE], - if (is.vector(centroids)) centroids[!pos] - else centroids[group, !pos, drop=FALSE]) + centroids[group, !pos, drop=FALSE]) ## zij are the distances of each point to its group centroid zij <- sqrt(abs(dist.pos - dist.neg)) Modified: pkg/vegan/R/eigenvals.R =================================================================== --- pkg/vegan/R/eigenvals.R 2013-04-07 06:00:57 UTC (rev 2484) +++ pkg/vegan/R/eigenvals.R 2013-04-07 20:19:34 UTC (rev 2485) @@ -28,7 +28,7 @@ out } -## squares of sdev +## squares of sdev `eigenvals.prcomp` <- function(x, ...) { @@ -78,6 +78,13 @@ out } +## betadisper (vegan) +`eigenvals.betadisper` <- function(x, ...) { + out <- x$eig + class(out) <- "eigenvals" + out +} + ## dudi objects of ade4 `eigenvals.dudi` <- @@ -112,8 +119,8 @@ class(out) <- "eigenvals" out } - + `print.eigenvals` <- function(x, ...) { Modified: pkg/vegan/R/print.betadisper.R =================================================================== --- pkg/vegan/R/print.betadisper.R 2013-04-07 06:00:57 UTC (rev 2484) +++ pkg/vegan/R/print.betadisper.R 2013-04-07 20:19:34 UTC (rev 2485) @@ -1,6 +1,9 @@ `print.betadisper` <- function(x, digits = max(3, getOption("digits") - 3), - ...) + ...) { + ## limit number of eignvals to 8 + ax.lim <- 8 + ## cat("\n") writeLines(strwrap("Homogeneity of multivariate dispersions\n", prefix = "\t")) @@ -9,10 +12,12 @@ cat(paste("\nNo. of Positive Eigenvalues:", sum(x$eig > 0))) cat(paste("\nNo. of Negative Eigenvalues:", sum(x$eig < 0))) cat("\n\n") - writeLines(strwrap("Average distance to centroid:\n")) + type <- ifelse(isTRUE(all.equal(attr(x, "type"), "median")), + "mediod", "centroid") + writeLines(strwrap(paste0("Average distance to ", type, ":\n"))) print.default(tapply(x$distances, x$group, mean), digits = digits) cat("\n") writeLines(strwrap("Eigenvalues for PCoA axes:\n")) - print.default(round(x$eig, digits = digits)) + print.default(round(x$eig[seq_len(ax.lim)], digits = digits)) invisible(x) } Modified: pkg/vegan/inst/ChangeLog =================================================================== --- pkg/vegan/inst/ChangeLog 2013-04-07 06:00:57 UTC (rev 2484) +++ pkg/vegan/inst/ChangeLog 2013-04-07 20:19:34 UTC (rev 2485) @@ -8,6 +8,12 @@ one group (i.e., in estimating the overall beta diversity in the data). Reported by Pierre Legendre. + Now correctly reports distance to "mediod" in the print method + when type = "median". Reported by Pierre Legendre. The print + method also now shows only the first 8 eigenvalues. + + * eigenvals: new method for class "betadisper". + * rda: eigenvalues are now regarded as zero if they are very small compared to the first eigenvalue. Earlier we used fixed limit of 1e-4, but now the limit is first eigenvalues * 1e-5. Similar Modified: pkg/vegan/man/betadisper.Rd =================================================================== --- pkg/vegan/man/betadisper.Rd 2013-04-07 06:00:57 UTC (rev 2484) +++ pkg/vegan/man/betadisper.Rd 2013-04-07 20:19:34 UTC (rev 2485) @@ -6,6 +6,7 @@ \alias{plot.betadisper} \alias{boxplot.betadisper} \alias{TukeyHSD.betadisper} +\alias{eigenvals.betadisper} \alias{ordimedian} \title{Multivariate homogeneity of groups dispersions (variances)} @@ -33,6 +34,8 @@ \method{scores}{betadisper}(x, display = c("sites", "centroids"), choices = c(1,2), \dots) +\method{eigenvals}{betadisper}(x, \dots) + \method{plot}{betadisper}(x, axes = c(1,2), cex = 0.7, hull = TRUE, ylab, xlab, main, sub, \dots) @@ -160,6 +163,8 @@ The \code{boxplot} function invisibly returns a list whose components are documented in \code{\link[graphics]{boxplot}}. + \code{eigenvals.betadisper} returns a named vector of eigenvalues. + \code{TukeyHSD.betadisper} returns a list. See \code{\link{TukeyHSD}} for further details. @@ -251,6 +256,23 @@ ## Draw a boxplot of the distances to centroid for each group boxplot(mod) +## `scores` and `eigenvals` also work +scrs <- scores(mod) +str(scrs) +head(scores(mod, 1:4, display = "sites")) +# group centroids/mediods +scores(mod, 1:4, display = "centroids") +# eigenvalues from the underlying principal coordinates analysis +eigenvals(mod) + +## try out bias correction; compare with mod3 +(mod3B <- betadisper(dis, groups, type = "median", bias.adjust=TRUE)) + +## should always work for a single group +group <- factor(rep("grazed", NROW(varespec))) +(tmp <- betadisper(dis, group, type = "median")) +(tmp <- betadisper(dis, group, type = "centroid")) + ## simulate missing values in 'd' and 'group' ## using spatial medians groups[c(2,20)] <- NA @@ -272,9 +294,6 @@ boxplot(mod3) plot(TukeyHSD(mod3)) -## try out bias correction; compare with mod3 -(mod3B <- betadisper(dis, groups, type = "median", bias.adjust=TRUE)) - } \keyword{methods} \keyword{multivariate} From noreply at r-forge.r-project.org Mon Apr 8 19:10:52 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 8 Apr 2013 19:10:52 +0200 (CEST) Subject: [Vegan-commits] r2486 - in pkg/vegan: . R inst man Message-ID: <20130408171052.6448C18460E@r-forge.r-project.org> Author: jarioksa Date: 2013-04-08 19:10:52 +0200 (Mon, 08 Apr 2013) New Revision: 2486 Modified: pkg/vegan/NAMESPACE pkg/vegan/R/print.betadisper.R pkg/vegan/inst/ChangeLog pkg/vegan/man/betadisper.Rd Log: janitorial after r2485: betadisper medoid and print rewrite Modified: pkg/vegan/NAMESPACE =================================================================== --- pkg/vegan/NAMESPACE 2013-04-07 20:19:34 UTC (rev 2485) +++ pkg/vegan/NAMESPACE 2013-04-08 17:10:52 UTC (rev 2486) @@ -152,6 +152,7 @@ # drop1: stats S3method(drop1, cca) # eigenvals: vegan +S3method(eigenvals, betadisper) S3method(eigenvals, cca) S3method(eigenvals, default) S3method(eigenvals, dudi) Modified: pkg/vegan/R/print.betadisper.R =================================================================== --- pkg/vegan/R/print.betadisper.R 2013-04-07 20:19:34 UTC (rev 2485) +++ pkg/vegan/R/print.betadisper.R 2013-04-08 17:10:52 UTC (rev 2486) @@ -13,7 +13,7 @@ cat(paste("\nNo. of Negative Eigenvalues:", sum(x$eig < 0))) cat("\n\n") type <- ifelse(isTRUE(all.equal(attr(x, "type"), "median")), - "mediod", "centroid") + "medoid", "centroid") writeLines(strwrap(paste0("Average distance to ", type, ":\n"))) print.default(tapply(x$distances, x$group, mean), digits = digits) cat("\n") Modified: pkg/vegan/inst/ChangeLog =================================================================== --- pkg/vegan/inst/ChangeLog 2013-04-07 20:19:34 UTC (rev 2485) +++ pkg/vegan/inst/ChangeLog 2013-04-08 17:10:52 UTC (rev 2486) @@ -8,7 +8,7 @@ one group (i.e., in estimating the overall beta diversity in the data). Reported by Pierre Legendre. - Now correctly reports distance to "mediod" in the print method + Now correctly reports distance to "medoid" in the print method when type = "median". Reported by Pierre Legendre. The print method also now shows only the first 8 eigenvalues. Modified: pkg/vegan/man/betadisper.Rd =================================================================== --- pkg/vegan/man/betadisper.Rd 2013-04-07 20:19:34 UTC (rev 2485) +++ pkg/vegan/man/betadisper.Rd 2013-04-08 17:10:52 UTC (rev 2486) @@ -260,7 +260,7 @@ scrs <- scores(mod) str(scrs) head(scores(mod, 1:4, display = "sites")) -# group centroids/mediods +# group centroids/medoids scores(mod, 1:4, display = "centroids") # eigenvalues from the underlying principal coordinates analysis eigenvals(mod) From noreply at r-forge.r-project.org Mon Apr 8 19:13:29 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 8 Apr 2013 19:13:29 +0200 (CEST) Subject: [Vegan-commits] r2487 - in pkg/vegan/tests: . Examples Message-ID: <20130408171329.BA2761847A7@r-forge.r-project.org> Author: jarioksa Date: 2013-04-08 19:13:29 +0200 (Mon, 08 Apr 2013) New Revision: 2487 Modified: pkg/vegan/tests/Examples/vegan-Ex.Rout.save pkg/vegan/tests/vegan-tests.Rout.save Log: update tests/ Modified: pkg/vegan/tests/Examples/vegan-Ex.Rout.save =================================================================== --- pkg/vegan/tests/Examples/vegan-Ex.Rout.save 2013-04-08 17:10:52 UTC (rev 2486) +++ pkg/vegan/tests/Examples/vegan-Ex.Rout.save 2013-04-08 17:13:29 UTC (rev 2487) @@ -1,6 +1,6 @@ -R version 2.15.2 (2012-10-26) -- "Trick or Treat" -Copyright (C) 2012 The R Foundation for Statistical Computing +R version 2.13.1 (2011-07-08) +Copyright (C) 2011 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit) @@ -23,7 +23,7 @@ > options(warn = 1) > library('vegan') Loading required package: permute -This is vegan 2.1-27 +This is vegan 2.1-1 > > assign(".oldSearch", search(), pos = 'CheckExEnv') > cleanEx() @@ -154,17 +154,17 @@ > plot(ef) > ordisurf(mod ~ pH, varechem, knots = 1, add = TRUE) Loading required package: mgcv -This is mgcv 1.7-22. For overview type 'help("mgcv-package")'. +This is mgcv 1.7-6. For overview type 'help("mgcv-package")'. Family: gaussian Link function: identity Formula: y ~ poly(x1, 1) + poly(x2, 1) - + Total model degrees of freedom 3 -GCV score: 0.04278782 +GCV score: 0.0427924 > > > @@ -425,19 +425,77 @@ Inertia is mean squared contingency coefficient Eigenvalues for constrained axes: - CCA1 CCA2 CCA3 -0.4187 0.1330 0.0766 + CCA1 CCA2 CCA3 +0.41868 0.13304 0.07659 Eigenvalues for unconstrained axes: - CA1 CA2 CA3 CA4 CA5 CA6 CA7 CA8 CA9 CA10 CA11 -0.4098 0.2259 0.1761 0.1234 0.1082 0.0908 0.0859 0.0609 0.0566 0.0467 0.0419 - CA12 CA13 CA14 CA15 CA16 -0.0201 0.0143 0.0099 0.0085 0.0080 + CA1 CA2 CA3 CA4 CA5 CA6 CA7 CA8 +0.409782 0.225913 0.176062 0.123389 0.108171 0.090751 0.085878 0.060894 + CA9 CA10 CA11 CA12 CA13 CA14 CA15 CA16 +0.056606 0.046688 0.041926 0.020103 0.014335 0.009917 0.008505 0.008033 -> ## see ?ordistep to do the same, but based on permutation P-values -> ## Not run: -> ##D ordistep(cca(dune ~ 1, dune.env), reformulate(names(dune.env)), perm.max=200) -> ## End(Not run) +> ## The same, but based on permutation P-values +> ordistep(cca(dune ~ 1, dune.env), reformulate(names(dune.env)), perm.max=200) + +Start: dune ~ 1 + + Df AIC F N.Perm Pr(>F) ++ Moisture 3 86.608 2.2536 199 0.005 ** ++ Management 3 86.935 2.1307 199 0.005 ** ++ Manure 4 88.832 1.5251 199 0.025 * ++ A1 1 87.411 2.1400 199 0.035 * ++ Use 2 89.134 1.1431 99 0.130 +--- +Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 + +Step: dune ~ Moisture + + Df AIC F N.Perm Pr(>F) +- Moisture 3 87.657 2.2536 99 0.01 ** +--- +Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 + + Df AIC F N.Perm Pr(>F) ++ Management 3 86.813 1.4565 199 0.035 * ++ Use 2 87.259 1.2760 199 0.095 . ++ Manure 4 87.342 1.3143 199 0.095 . ++ A1 1 86.992 1.2624 99 0.170 +--- +Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 + +Step: dune ~ Moisture + Management + + Df AIC F N.Perm Pr(>F) +- Management 3 86.608 1.4565 199 0.035 * +- Moisture 3 86.935 1.5518 99 0.020 * +--- +Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 + + Df AIC F N.Perm Pr(>F) ++ A1 1 86.190 1.6817 199 0.09 . ++ Manure 3 88.430 0.8167 99 0.58 ++ Use 2 88.245 0.7534 99 0.65 +--- +Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 + +Call: cca(formula = dune ~ Moisture + Management, data = dune.env) + + Inertia Proportion Rank +Total 2.1153 1.0000 +Constrained 1.0024 0.4739 6 +Unconstrained 1.1129 0.5261 13 +Inertia is mean squared contingency coefficient + +Eigenvalues for constrained axes: + CCA1 CCA2 CCA3 CCA4 CCA5 CCA6 +0.44583 0.28869 0.11239 0.07166 0.04937 0.03444 + +Eigenvalues for unconstrained axes: + CA1 CA2 CA3 CA4 CA5 CA6 CA7 CA8 +0.350396 0.152057 0.125084 0.109838 0.092209 0.077107 0.059441 0.047755 + CA9 CA10 CA11 CA12 CA13 +0.036958 0.022266 0.020700 0.010827 0.008252 + > ## Manual model building > ## -- define the maximal model for scope > mbig <- rda(dune ~ ., dune.env) @@ -447,21 +505,21 @@ > add1(m0, scope=formula(mbig), test="perm") Df AIC F N.Perm Pr(>F) 89.620 -A1 1 89.591 1.9217 199 0.070 . +A1 1 89.591 1.9217 199 0.055 . Moisture 3 87.707 2.5883 199 0.005 ** Management 3 87.082 2.8400 199 0.005 ** -Use 2 91.032 1.1741 99 0.180 +Use 2 91.032 1.1741 99 0.270 Manure 4 89.232 1.9539 199 0.010 ** --- Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 > m0 <- update(m0, . ~ . + Management) > add1(m0, scope=formula(mbig), test="perm") - Df AIC F N.Perm Pr(>F) - 87.082 -A1 1 87.424 1.2965 99 0.240 -Moisture 3 85.567 1.9764 199 0.005 ** -Use 2 88.284 1.0510 99 0.430 -Manure 3 87.517 1.3902 199 0.130 + Df AIC F N.Perm Pr(>F) + 87.082 +A1 1 87.424 1.2965 99 0.21 +Moisture 3 85.567 1.9764 199 0.03 * +Use 2 88.284 1.0510 99 0.41 +Manure 3 87.517 1.3902 199 0.07 . --- Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 > m0 <- update(m0, . ~ . + Moisture) @@ -469,16 +527,16 @@ > drop1(m0, test="perm") Df AIC F N.Perm Pr(>F) 85.567 -Management 3 87.707 2.1769 199 0.010 ** -Moisture 3 87.082 1.9764 199 0.015 * +Management 3 87.707 2.1769 199 0.015 * +Moisture 3 87.082 1.9764 199 0.005 ** --- Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 > add1(m0, scope=formula(mbig), test="perm") Df AIC F N.Perm Pr(>F) 85.567 -A1 1 86.220 0.8359 99 0.72 -Use 2 86.842 0.8027 99 0.77 -Manure 3 85.762 1.1225 99 0.26 +A1 1 86.220 0.8359 99 0.66 +Use 2 86.842 0.8027 99 0.66 +Manure 3 85.762 1.1225 99 0.31 > > > @@ -491,8 +549,7 @@ > ### Name: adipart > ### Title: Additive Diversity Partitioning and Hierarchical Null Model > ### Testing -> ### Aliases: adipart adipart.default adipart.formula hiersimu -> ### hiersimu.default hiersimu.formula +> ### Aliases: adipart hiersimu print.hiersimu > ### Keywords: multivariate > > ### ** Examples @@ -508,10 +565,10 @@ + out <- rep(1, length(x)) + for (i in 2:(length(cut) - 1)) + out[which(x > cut[i] & x <= cut[(i + 1)])] <- i -+ return(out)} ++ return(as.factor(out))} > ## The hierarchy of sample aggregation > levsm <- data.frame( -+ l1=1:nrow(mite), ++ l1=as.factor(1:nrow(mite)), + l2=cutter(mite.xy$y, cut = seq(0, 10, by = 2.5)), + l3=cutter(mite.xy$y, cut = seq(0, 10, by = 5)), + l4=cutter(mite.xy$y, cut = seq(0, 10, by = 10))) @@ -522,90 +579,41 @@ > plot(mite.xy, main="l3", col=as.numeric(levsm$l3)+1) > par(mfrow=c(1,1)) > ## Additive diversity partitioning -> adipart(mite, index="richness", nsimul=19) -adipart object +> adipart(mite ~., levsm, index="richness", nsimul=19) +adipart with 19 simulations +with index richness, weights unif -Call: adipart(y = mite, index = "richness", nsimul = 19) - -nullmodel method ?r2dtable? with 19 simulations -options: index richness, weights unif -alternative hypothesis: simulated median is not equal to the statistic - - statistic z mean 2.5% 50% 97.5% Pr(sim.) -alpha.1 15.114 -38.43 22.344 22.032 22.300 22.608 0.05 * -gamma 35.000 0.00 35.000 35.000 35.000 35.000 1.00 -beta.1 19.886 38.43 12.656 12.392 12.700 12.968 0.05 * + statistic z 2.5% 50% 97.5% Pr(sim.) +alpha.1 15.1143 -38.7550 22.0321 22.3000 22.608 0.05 * +alpha.2 29.7500 -27.1142 34.5000 34.7500 35.000 0.05 * +alpha.3 33.0000 0.0000 35.0000 35.0000 35.000 0.05 * +gamma 35.0000 0.0000 35.0000 35.0000 35.000 1.00 +beta.1 14.6357 9.0433 12.1629 12.4500 12.955 0.05 * +beta.2 3.2500 16.4371 0.0000 0.2500 0.500 0.05 * +beta.3 2.0000 0.0000 0.0000 0.0000 0.000 0.05 * --- Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 -> adipart(mite ~ ., levsm, index="richness", nsimul=19) -adipart object - -Call: adipart(formula = mite ~ ., data = levsm, index = "richness", -nsimul = 19) - -nullmodel method ?r2dtable? with 19 simulations -options: index richness, weights unif -alternative hypothesis: simulated median is not equal to the statistic - - statistic z mean 2.5% 50% 97.5% Pr(sim.) -alpha.1 15.114 -46.2370 22.39624 22.12571 22.44286 22.6236 0.05 * -alpha.2 29.750 -21.7076 34.81579 34.36250 35.00000 35.0000 0.05 * -alpha.3 33.000 0.0000 35.00000 35.00000 35.00000 35.0000 0.05 * -gamma 35.000 0.0000 35.00000 35.00000 35.00000 35.0000 1.00 -beta.1 14.636 9.0407 12.41955 12.00750 12.42857 12.8743 0.05 * -beta.2 3.250 13.1373 0.18421 0.00000 0.00000 0.6375 0.05 * -beta.3 2.000 0.0000 0.00000 0.00000 0.00000 0.0000 0.05 * ---- -Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 > ## Hierarchical null model testing > ## diversity analysis (similar to adipart) -> hiersimu(mite, FUN=diversity, relative=TRUE, nsimul=19) -hiersimu object +> hiersimu(mite ~., levsm, diversity, relative=TRUE, nsimul=19) +hiersimu with 19 simulations -Call: hiersimu(y = mite, FUN = diversity, relative = TRUE, nsimul = 19) - -nullmodel method ?r2dtable? with 19 simulations - -alternative hypothesis: simulated median is not equal to the statistic - - statistic z mean 2.5% 50% 97.5% Pr(sim.) -level_1 0.76064 -71.195 0.93904 0.93487 0.93856 0.9444 0.05 * -leve_2 1.00000 0.000 1.00000 1.00000 1.00000 1.0000 1.00 + statistic z 2.5% 50% 97.5% Pr(sim.) +l1 0.76064 -65.47286 0.93511 0.93959 0.9437 0.05 * +l2 0.89736 -127.77766 0.99635 0.99815 0.9989 0.05 * +l3 0.92791 -516.33891 0.99921 0.99948 0.9997 0.05 * +l4 1.00000 0.00000 1.00000 1.00000 1.0000 1.00 --- Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 -> hiersimu(mite ~., levsm, FUN=diversity, relative=TRUE, nsimul=19) -hiersimu object - -Call: hiersimu(formula = mite ~ ., data = levsm, FUN = diversity, -relative = TRUE, nsimul = 19) - -nullmodel method ?r2dtable? with 19 simulations - -alternative hypothesis: simulated median is not equal to the statistic - - statistic z mean 2.5% 50% 97.5% Pr(sim.) -l1 0.76064 -75.139 0.93833 0.93389 0.93819 0.9427 0.05 * -l2 0.89736 -110.968 0.99811 0.99699 0.99814 0.9999 0.05 * -l3 0.92791 -417.338 0.99940 0.99904 0.99943 0.9996 0.05 * -l4 1.00000 0.000 1.00000 1.00000 1.00000 1.0000 1.00 ---- -Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 > ## Hierarchical testing with the Morisita index > morfun <- function(x) dispindmorisita(x)$imst > hiersimu(mite ~., levsm, morfun, drop.highest=TRUE, nsimul=19) -hiersimu object +hiersimu with 19 simulations -Call: hiersimu(formula = mite ~ ., data = levsm, FUN = morfun, -drop.highest = TRUE, nsimul = 19) - -nullmodel method ?r2dtable? with 19 simulations - -alternative hypothesis: simulated median is not equal to the statistic - - statistic z mean 2.5% 50% 97.5% Pr(sim.) -l1 0.52070 8.5216 0.353253 0.322624 0.351073 0.3848 0.05 * -l2 0.60234 14.3854 0.153047 0.096700 0.150434 0.1969 0.05 * -l3 0.67509 20.3162 -0.182473 -0.234793 -0.195937 -0.0988 0.05 * + statistic z 2.5% 50% 97.5% Pr(sim.) +l1 0.52070 4.98527 0.31016 0.36570 0.4227 0.05 * +l2 0.60234 12.33099 0.11979 0.17096 0.2283 0.05 * +l3 0.67509 19.37352 -0.24164 -0.16761 -0.0895 0.05 * --- Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 > @@ -633,8 +641,6 @@ Call: adonis(formula = dune ~ Management * A1, data = dune.env, permutations = 99) -Terms added sequentially (first to last) - Df SumsOfSqs MeanSqs F.Model R2 Pr(>F) Management 3 1.4686 0.48953 3.2629 0.34161 0.01 ** A1 1 0.4409 0.44089 2.9387 0.10256 0.02 * @@ -671,12 +677,12 @@ > > Y <- data.frame(Agropyron, Schizachyrium) > mod <- metaMDS(Y) -Run 0 stress 0.08556586 -Run 1 stress 0.1560544 -Run 2 stress 0.08556586 -... New best solution -... procrustes: rmse 1.094365e-06 max resid 1.88838e-06 +Run 0 stress 0.08556588 +Run 1 stress 0.1560545 +Run 2 stress 0.08556612 +... procrustes: rmse 0.0001630123 max resid 0.0003642025 *** Solution reached + > plot(mod) > ### Hulls show treatment > ordihull(mod, group=dat$NO3, show="0") @@ -685,32 +691,28 @@ > ordispider(mod, group=dat$field, lty=3, col="red") > > ### Correct hypothesis test (with strata) -> adonis(Y ~ NO3, data=dat, strata=dat$field, perm=999) +> adonis(Y ~ NO3, data=dat, strata=dat$field, perm=1e3) Call: -adonis(formula = Y ~ NO3, data = dat, permutations = 999, strata = dat$field) +adonis(formula = Y ~ NO3, data = dat, permutations = 1000, strata = dat$field) -Terms added sequentially (first to last) - - Df SumsOfSqs MeanSqs F.Model R2 Pr(>F) -NO3 1 0.055856 0.055856 4.0281 0.28714 0.009 ** -Residuals 10 0.138667 0.013867 0.71286 -Total 11 0.194524 1.00000 + Df SumsOfSqs MeanSqs F.Model R2 Pr(>F) +NO3 1 0.055856 0.055856 4.0281 0.28714 0.008991 ** +Residuals 10 0.138667 0.013867 0.71286 +Total 11 0.194524 1.00000 --- Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 > > ### Incorrect (no strata) -> adonis(Y ~ NO3, data=dat, perm=999) +> adonis(Y ~ NO3, data=dat, perm=1e3) Call: -adonis(formula = Y ~ NO3, data = dat, permutations = 999) +adonis(formula = Y ~ NO3, data = dat, permutations = 1000) -Terms added sequentially (first to last) - - Df SumsOfSqs MeanSqs F.Model R2 Pr(>F) -NO3 1 0.055856 0.055856 4.0281 0.28714 0.005 ** -Residuals 10 0.138667 0.013867 0.71286 -Total 11 0.194524 1.00000 + Df SumsOfSqs MeanSqs F.Model R2 Pr(>F) +NO3 1 0.055856 0.055856 4.0281 0.28714 0.004995 ** +Residuals 10 0.138667 0.013867 0.71286 +Total 11 0.194524 1.00000 --- Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 > @@ -748,7 +750,7 @@ Based on 999 permutations -Upper quantiles of permutations (null model): +Empirical upper confidence limits of R: 90% 95% 97.5% 99% 0.116 0.160 0.203 0.233 @@ -1190,7 +1192,6 @@ > boxplot(mod) > > ## simulate missing values in 'd' and 'group' -> ## using spatial medians > groups[c(2,20)] <- NA > dis[c(2, 20)] <- NA > mod2 <- betadisper(dis, groups) ## warnings @@ -1244,24 +1245,24 @@ > boxplot(mod2) > plot(TukeyHSD(mod2)) > -> ## Using group centroids -> mod3 <- betadisper(dis, groups, type = "centroid") -Warning in betadisper(dis, groups, type = "centroid") : +> ## Using spatial median +> mod3 <- betadisper(dis, groups, type = "median") +Warning in betadisper(dis, groups, type = "median") : Missing observations due to 'group' removed. -Warning in betadisper(dis, groups, type = "centroid") : +Warning in betadisper(dis, groups, type = "median") : Missing observations due to 'd' removed. > mod3 Homogeneity of multivariate dispersions -Call: betadisper(d = dis, group = groups, type = "centroid") +Call: betadisper(d = dis, group = groups, type = "median") No. of Positive Eigenvalues: 14 No. of Negative Eigenvalues: 5 Average distance to centroid: grazed ungrazed - 0.4001 0.3108 + 0.3984 0.3008 Eigenvalues for PCoA axes: PCoA1 PCoA2 PCoA3 PCoA4 PCoA5 PCoA6 PCoA7 PCoA8 PCoA9 PCoA10 @@ -1282,52 +1283,22 @@ Mirrored permutations for Samples?: No Response: Distances - Df Sum Sq Mean Sq F N.Perm Pr(>F) -Groups 1 0.033468 0.033468 3.1749 100 0.06931 . -Residuals 18 0.189749 0.010542 ---- -Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 + Df Sum Sq Mean Sq F N.Perm Pr(>F) +Groups 1 0.039979 0.039979 2.4237 100 0.1287 +Residuals 18 0.296910 0.016495 > anova(mod3) Analysis of Variance Table Response: Distances - Df Sum Sq Mean Sq F value Pr(>F) -Groups 1 0.033468 0.033468 3.1749 0.09166 . -Residuals 18 0.189749 0.010542 ---- -Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 + Df Sum Sq Mean Sq F value Pr(>F) +Groups 1 0.039979 0.039979 2.4237 0.1369 +Residuals 18 0.296910 0.016495 > plot(mod3) > boxplot(mod3) > plot(TukeyHSD(mod3)) > -> ## try out bias correction; compare with mod3 -> (mod3B <- betadisper(dis, groups, type = "median", bias.adjust=TRUE)) -Warning in betadisper(dis, groups, type = "median", bias.adjust = TRUE) : - Missing observations due to 'group' removed. -Warning in betadisper(dis, groups, type = "median", bias.adjust = TRUE) : - Missing observations due to 'd' removed. - - Homogeneity of multivariate dispersions - -Call: betadisper(d = dis, group = groups, type = "median", bias.adjust -= TRUE) - -No. of Positive Eigenvalues: 14 -No. of Negative Eigenvalues: 5 - -Average distance to centroid: - grazed ungrazed - 0.4134 0.3295 - -Eigenvalues for PCoA axes: - PCoA1 PCoA2 PCoA3 PCoA4 PCoA5 PCoA6 PCoA7 PCoA8 PCoA9 PCoA10 - 1.4755 0.8245 0.4218 0.3456 0.2159 0.1688 0.1150 0.1060 0.0912 0.0639 - PCoA11 PCoA12 PCoA13 PCoA14 PCoA15 PCoA16 PCoA17 PCoA18 PCoA19 - 0.0420 0.0267 0.0157 0.0020 -0.0025 -0.0215 -0.0221 -0.0486 -0.0592 > > -> -> > cleanEx() > nameEx("betadiver") > ### * betadiver @@ -1545,10 +1516,10 @@ 0.5413 0.3265 0.1293 Eigenvalues for unconstrained axes: - MDS1 MDS2 MDS3 MDS4 MDS5 MDS6 MDS7 MDS8 MDS9 MDS10 MDS11 -0.9065 0.5127 0.3379 0.2626 0.2032 0.1618 0.1242 0.0856 0.0689 0.0583 0.0501 - MDS12 MDS13 MDS14 MDS15 -0.0277 0.0208 0.0073 0.0013 + MDS1 MDS2 MDS3 MDS4 MDS5 MDS6 MDS7 MDS8 +0.906518 0.512743 0.337915 0.262598 0.203220 0.161762 0.124174 0.085570 + MDS9 MDS10 MDS11 MDS12 MDS13 MDS14 MDS15 +0.068881 0.058346 0.050083 0.027738 0.020839 0.007306 0.001345 > plot(vare.cap) > anova(vare.cap) @@ -1582,8 +1553,6 @@ 1.4408 0.8523 0.6015 0.4888 0.4187 0.3538 0.2877 0.2160 (Showed only 8 of all 19 unconstrained eigenvalues) -Constant added to distances: 0.2614286 - > ## Avoid negative eigenvalues by taking square roots of dissimilarities > capscale(varespec ~ N + P + K + Condition(Al), varechem, + dist = "bray", sqrt.dist= TRUE) @@ -1691,14 +1660,16 @@ Inertia is mean squared contingency coefficient Eigenvalues for constrained axes: - CCA1 CCA2 CCA3 CCA4 CCA5 CCA6 CCA7 CCA8 CCA9 CCA10 CCA11 -0.4389 0.2918 0.1628 0.1421 0.1180 0.0890 0.0703 0.0584 0.0311 0.0133 0.0084 - CCA12 CCA13 CCA14 -0.0065 0.0062 0.0047 + CCA1 CCA2 CCA3 CCA4 CCA5 CCA6 CCA7 CCA8 +0.438870 0.291775 0.162847 0.142130 0.117952 0.089029 0.070295 0.058359 + CCA9 CCA10 CCA11 CCA12 CCA13 CCA14 +0.031141 0.013294 0.008364 0.006538 0.006156 0.004733 Eigenvalues for unconstrained axes: - CA1 CA2 CA3 CA4 CA5 CA6 CA7 CA8 CA9 -0.19776 0.14193 0.10117 0.07079 0.05330 0.03330 0.01887 0.01510 0.00949 + CA1 CA2 CA3 CA4 CA5 CA6 CA7 CA8 +0.197765 0.141926 0.101174 0.070787 0.053303 0.033299 0.018868 0.015104 + CA9 +0.009488 > plot(vare.cca) > ## Formula interface and a better model @@ -1714,8 +1685,8 @@ Inertia is mean squared contingency coefficient Eigenvalues for constrained axes: - CCA1 CCA2 CCA3 CCA4 CCA5 CCA6 -0.3756 0.2342 0.1407 0.1323 0.1068 0.0561 + CCA1 CCA2 CCA3 CCA4 CCA5 CCA6 +0.37563 0.23419 0.14067 0.13229 0.10675 0.05614 Eigenvalues for unconstrained axes: CA1 CA2 CA3 CA4 CA5 CA6 CA7 CA8 @@ -1734,12 +1705,12 @@ Inertia is mean squared contingency coefficient Eigenvalues for constrained axes: - CCA1 -0.15722 + CCA1 +0.1572 Eigenvalues for unconstrained axes: - CA1 CA2 CA3 CA4 CA5 CA6 CA7 CA8 -0.4745 0.2939 0.2140 0.1954 0.1748 0.1171 0.1121 0.0880 + CA1 CA2 CA3 CA4 CA5 CA6 CA7 CA8 +0.47455 0.29389 0.21403 0.19541 0.17482 0.11711 0.11207 0.08797 (Showed only 8 of all 22 unconstrained eigenvalues) > cca(varespec ~ Ca + Condition(pH), varechem) @@ -1753,12 +1724,12 @@ Inertia is mean squared contingency coefficient Eigenvalues for constrained axes: - CCA1 -0.18269 + CCA1 +0.1827 Eigenvalues for unconstrained axes: - CA1 CA2 CA3 CA4 CA5 CA6 CA7 CA8 -0.3834 0.2749 0.2123 0.1760 0.1701 0.1161 0.1089 0.0880 + CA1 CA2 CA3 CA4 CA5 CA6 CA7 CA8 +0.38343 0.27487 0.21233 0.17599 0.17013 0.11613 0.10892 0.08797 (Showed only 8 of all 21 unconstrained eigenvalues) > ## RDA @@ -1819,18 +1790,18 @@ > > ### Name: clamtest > ### Title: Multinomial Species Classification Method (CLAM) -> ### Aliases: clamtest summary.clamtest plot.clamtest +> ### Aliases: clamtest summary.clamtest print.summary.clamtest plot.clamtest > ### Keywords: htest > > ### ** Examples > > data(mite) > data(mite.env) -> sol <- clamtest(mite, mite.env$Shrub=="None", alpha=0.005) -> summary(sol) +> x <- clamtest(mite, mite.env$Shrub=="None", alpha=0.005, specialization = 0.667) +> summary(x) Two Groups Species Classification Method (CLAM) -Specialization threshold = 0.6666667 +Specialization threshold = 0.667 Alpha level = 0.005 Estimated sample coverage: @@ -1846,7 +1817,7 @@ Specialist_FALSE 14 0.400 Specialist_TRUE 4 0.114 Too_rare 7 0.200 -> head(sol) +> head(x) Species Total_FALSE Total_TRUE Classes 1 Brachy 534 77 Generalist 2 PHTH 89 0 Specialist_FALSE @@ -1854,7 +1825,7 @@ 4 RARD 85 0 Specialist_FALSE 5 SSTR 22 0 Too_rare 6 Protopl 26 0 Too_rare -> plot(sol) +> plot(x) > > > @@ -1876,20 +1847,20 @@ + array(replicate(n, sample(x)), c(dim(x), n)) > (cs <- commsim("r00", fun=f, binary=TRUE, + isSeq=FALSE, mode="integer")) -An object of class ?commsim? -?r00? method (binary, non-sequential, integer mode) +An object of class "commsim" +"r00" method (binary, non-sequential, integer mode) > > ## retrieving the sequential swap algorithm > (cs <- make.commsim("swap")) -An object of class ?commsim? -?swap? method (binary, sequential, integer mode) +An object of class "commsim" +"swap" method (binary, sequential, integer mode) > > ## feeding a commsim object as argument > make.commsim(cs) -An object of class ?commsim? -?swap? method (binary, sequential, integer mode) +An object of class "commsim" +"swap" method (binary, sequential, integer mode) > > ## structural constraints @@ -1906,46 +1877,46 @@ + y <- simulate(m, nsim=n) + out <- rowMeans(sapply(1:dim(y)[3], + function(i) diagfun(attr(y, "data"), y[,,i]))) -+ z <- as.numeric(c(attr(y, "binary"), attr(y, "isSeq"), -+ attr(y, "mode") == "double")) -+ names(z) <- c("binary", "isSeq", "double") ++ z <- as.numeric(c(attr(y, "binary"), attr(y, "isSeq"))) ++ names(z) <- c("binary", "isSeq") + c(z, out) + } > x <- matrix(rbinom(10*12, 1, 0.5)*rpois(10*12, 3), 12, 10) > algos <- make.commsim() > a <- t(sapply(algos, evalfun, x=x, n=10)) +Warning in storage.mode(state) <- object$commsim$mode : + NAs introduced by coercion > print(as.table(ifelse(a==1,1,0)), zero.print = ".") - binary isSeq double sum fill rowSums colSums rowFreq colFreq -r00 1 . . 1 1 . . . . -c0 1 . . 1 1 . 1 . 1 -r0 1 . . 1 1 1 . 1 . -r0_old 1 . . 1 1 1 . 1 . -r1 1 . . 1 1 1 . 1 . -r2 1 . . 1 1 1 . 1 . -quasiswap 1 . . 1 1 1 1 1 1 -swap 1 1 . 1 1 1 1 1 1 -tswap 1 1 . 1 1 1 1 1 1 -backtrack 1 . . 1 1 1 1 1 1 -r2dtable . . . 1 . 1 1 . . -swap_count . 1 . 1 1 1 1 . . -quasiswap_count . . . 1 1 1 1 . . -swsh_samp . . . 1 1 . . 1 1 -swsh_both . . . 1 1 . . 1 1 -swsh_samp_r . . . 1 1 1 . 1 1 -swsh_samp_c . . . 1 1 . 1 1 1 -swsh_both_r . . . 1 1 1 . 1 1 -swsh_both_c . . . 1 1 . 1 1 1 -abuswap_r . 1 1 1 1 1 . 1 1 -abuswap_c . 1 1 1 1 . 1 1 1 -r00_samp . . 1 1 1 . . . . -c0_samp . . 1 1 1 . 1 . 1 -r0_samp . . 1 1 1 1 . 1 . -r00_ind . . . 1 . . . . . -c0_ind . . . 1 . . 1 . . -r0_ind . . . 1 . 1 . . . -r00_both . . . 1 1 . . . . -c0_both . . . 1 1 . 1 . 1 -r0_both . . . 1 1 1 . 1 . + binary isSeq sum fill rowSums colSums rowFreq colFreq +r00 1 . 1 1 . . . . +c0 1 . 1 1 . 1 . 1 +r0 1 . 1 1 1 . 1 . +r1 1 . 1 1 1 . 1 . +r2 1 . 1 1 1 . 1 . +quasiswap 1 . 1 1 1 1 1 1 +swap 1 1 1 1 1 1 1 1 +tswap 1 1 1 1 1 1 1 1 +backtrack 1 . 1 1 1 1 1 1 +r2dtable . . 1 . 1 1 . . +swap_count . 1 . . . . . . +quasiswap_count . . 1 1 1 1 . . +swsh_samp . . 1 1 . . 1 1 +swsh_both . . 1 1 . . 1 1 +swsh_samp_r . . 1 1 1 . 1 1 +swsh_samp_c . . 1 1 . 1 1 1 +swsh_both_r . . 1 1 1 . 1 1 +swsh_both_c . . 1 1 . 1 1 1 +abuswap_r . 1 1 1 1 . 1 1 +abuswap_c . 1 1 1 . 1 1 1 +r00_samp . . 1 1 . . . . +c0_samp . . 1 1 . 1 . 1 +r0_samp . . 1 1 1 . 1 . +r00_ind . . 1 . . . . . +c0_ind . . 1 . . 1 . . +r0_ind . . 1 . 1 . . . +r00_both . . 1 1 . . . . +c0_both . . 1 1 . 1 . 1 +r0_both . . 1 1 1 . 1 . > > > @@ -2169,7 +2140,7 @@ > > ### Name: decostand > ### Title: Standardization Methods for Community Ecology -> ### Aliases: decostand wisconsin scoverage +> ### Aliases: decostand wisconsin > ### Keywords: multivariate manip > > ### ** Examples @@ -2194,40 +2165,9 @@ > sptrans <- decostand(varespec, "chi.square") > plot(procrustes(rda(sptrans), cca(varespec))) > -> data(mite) -> sptrans <- scoverage(mite) > > -> > cleanEx() -> nameEx("density.adonis") -> ### * density.adonis -> -> flush(stderr()); flush(stdout()) -> -> ### Name: density.adonis -> ### Title: Kernel Density Estimation for Permutation Results in Vegan -> ### Aliases: density.adonis density.anosim density.mantel density.mrpp -> ### density.permutest.cca density.protest plot.vegandensity -> ### densityplot.adonis -> ### Keywords: distribution smooth -> -> ### ** Examples -> -> data(dune) -> data(dune.env) -> mod <- adonis(dune ~ Management, data = dune.env) -> plot(density(mod)) -> library(lattice) -> mod <- adonis(dune ~ Management * Moisture, dune.env) -> densityplot(mod) -> -> -> -> cleanEx() - -detaching ?package:lattice? - > nameEx("designdist") > ### * designdist > @@ -2285,8 +2225,78 @@ > deviance(cca(dune)) [1] 1448.956 -> # Stepwise selection (forward from an empty model "dune ~ 1") +> # Backward elimination from a complete model "dune ~ ." > ord <- cca(dune ~ ., dune.env) +> ord +Call: cca(formula = dune ~ A1 + Moisture + Management + Use + Manure, +data = dune.env) + + Inertia Proportion Rank +Total 2.1153 1.0000 +Constrained 1.5032 0.7106 12 +Unconstrained 0.6121 0.2894 7 +Inertia is mean squared contingency coefficient +Some constraints were aliased because they were collinear (redundant) + +Eigenvalues for constrained axes: + CCA1 CCA2 CCA3 CCA4 CCA5 CCA6 CCA7 CCA8 CCA9 CCA10 +0.46713 0.34102 0.17606 0.15317 0.09528 0.07027 0.05887 0.04993 0.03183 0.02596 + CCA11 CCA12 +0.02282 0.01082 + +Eigenvalues for unconstrained axes: + CA1 CA2 CA3 CA4 CA5 CA6 CA7 +0.27237 0.10876 0.08975 0.06305 0.03489 0.02529 0.01798 + +> step(ord) +Start: AIC=86.86 +dune ~ A1 + Moisture + Management + Use + Manure + + Df AIC +- Use 2 86.711 + 86.857 +- Management 2 87.470 +- Manure 3 87.819 +- A1 1 88.181 +- Moisture 3 89.179 + +Step: AIC=86.71 +dune ~ A1 + Moisture + Management + Manure + + Df AIC +- Manure 3 86.190 +- Management 2 86.446 + 86.711 +- Moisture 3 87.873 +- A1 1 88.430 + +Step: AIC=86.19 +dune ~ A1 + Moisture + Management + + Df AIC + 86.190 +- Moisture 3 86.460 +- A1 1 86.813 +- Management 3 86.992 +Call: cca(formula = dune ~ A1 + Moisture + Management, data = dune.env) + + Inertia Proportion Rank +Total 2.1153 1.0000 +Constrained 1.1392 0.5385 7 +Unconstrained 0.9761 0.4615 12 +Inertia is mean squared contingency coefficient + +Eigenvalues for constrained axes: + CCA1 CCA2 CCA3 CCA4 CCA5 CCA6 CCA7 +0.44826 0.30014 0.14995 0.10733 0.05668 0.04335 0.03345 + +Eigenvalues for unconstrained axes: + CA1 CA2 CA3 CA4 CA5 CA6 CA7 CA8 +0.306366 0.131911 0.115157 0.109469 0.077242 0.075754 0.048714 0.037582 + CA9 CA10 CA11 CA12 +0.031058 0.021024 0.012542 0.009277 + +> # Stepwise selection (forward from an empty model "dune ~ 1") > step(cca(dune ~ 1, dune.env), scope = formula(ord)) Start: AIC=87.66 dune ~ 1 @@ -2318,15 +2328,28 @@ Inertia is mean squared contingency coefficient Eigenvalues for constrained axes: - CCA1 CCA2 CCA3 [TRUNCATED] To get the complete diff run: svnlook diff /svnroot/vegan -r 2487 From noreply at r-forge.r-project.org Tue Apr 9 10:43:27 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 9 Apr 2013 10:43:27 +0200 (CEST) Subject: [Vegan-commits] r2488 - pkg/vegan/tests/Examples Message-ID: <20130409084328.126F8184E39@r-forge.r-project.org> Author: jarioksa Date: 2013-04-09 10:43:27 +0200 (Tue, 09 Apr 2013) New Revision: 2488 Modified: pkg/vegan/tests/Examples/vegan-Ex.Rout.save Log: correct (= up-to-date) Examples in tests/ Modified: pkg/vegan/tests/Examples/vegan-Ex.Rout.save =================================================================== --- pkg/vegan/tests/Examples/vegan-Ex.Rout.save 2013-04-08 17:13:29 UTC (rev 2487) +++ pkg/vegan/tests/Examples/vegan-Ex.Rout.save 2013-04-09 08:43:27 UTC (rev 2488) @@ -1,6 +1,6 @@ -R version 2.13.1 (2011-07-08) -Copyright (C) 2011 The R Foundation for Statistical Computing +R version 2.15.3 (2013-03-01) -- "Security Blanket" +Copyright (C) 2013 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit) @@ -23,7 +23,7 @@ > options(warn = 1) > library('vegan') Loading required package: permute -This is vegan 2.1-1 +This is vegan 2.1-28 > > assign(".oldSearch", search(), pos = 'CheckExEnv') > cleanEx() @@ -154,17 +154,17 @@ > plot(ef) > ordisurf(mod ~ pH, varechem, knots = 1, add = TRUE) Loading required package: mgcv -This is mgcv 1.7-6. For overview type 'help("mgcv-package")'. +This is mgcv 1.7-22. For overview type 'help("mgcv-package")'. Family: gaussian Link function: identity Formula: y ~ poly(x1, 1) + poly(x2, 1) - + Total model degrees of freedom 3 -GCV score: 0.0427924 +GCV score: 0.04278782 > > > @@ -425,77 +425,19 @@ Inertia is mean squared contingency coefficient Eigenvalues for constrained axes: - CCA1 CCA2 CCA3 -0.41868 0.13304 0.07659 + CCA1 CCA2 CCA3 +0.4187 0.1330 0.0766 Eigenvalues for unconstrained axes: - CA1 CA2 CA3 CA4 CA5 CA6 CA7 CA8 -0.409782 0.225913 0.176062 0.123389 0.108171 0.090751 0.085878 0.060894 - CA9 CA10 CA11 CA12 CA13 CA14 CA15 CA16 -0.056606 0.046688 0.041926 0.020103 0.014335 0.009917 0.008505 0.008033 + CA1 CA2 CA3 CA4 CA5 CA6 CA7 CA8 CA9 CA10 CA11 +0.4098 0.2259 0.1761 0.1234 0.1082 0.0908 0.0859 0.0609 0.0566 0.0467 0.0419 + CA12 CA13 CA14 CA15 CA16 +0.0201 0.0143 0.0099 0.0085 0.0080 -> ## The same, but based on permutation P-values -> ordistep(cca(dune ~ 1, dune.env), reformulate(names(dune.env)), perm.max=200) - -Start: dune ~ 1 - - Df AIC F N.Perm Pr(>F) -+ Moisture 3 86.608 2.2536 199 0.005 ** -+ Management 3 86.935 2.1307 199 0.005 ** -+ Manure 4 88.832 1.5251 199 0.025 * -+ A1 1 87.411 2.1400 199 0.035 * -+ Use 2 89.134 1.1431 99 0.130 ---- -Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 - -Step: dune ~ Moisture - - Df AIC F N.Perm Pr(>F) -- Moisture 3 87.657 2.2536 99 0.01 ** ---- -Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 - - Df AIC F N.Perm Pr(>F) -+ Management 3 86.813 1.4565 199 0.035 * -+ Use 2 87.259 1.2760 199 0.095 . -+ Manure 4 87.342 1.3143 199 0.095 . -+ A1 1 86.992 1.2624 99 0.170 ---- -Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 - -Step: dune ~ Moisture + Management - - Df AIC F N.Perm Pr(>F) -- Management 3 86.608 1.4565 199 0.035 * -- Moisture 3 86.935 1.5518 99 0.020 * ---- -Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 - - Df AIC F N.Perm Pr(>F) -+ A1 1 86.190 1.6817 199 0.09 . -+ Manure 3 88.430 0.8167 99 0.58 -+ Use 2 88.245 0.7534 99 0.65 ---- -Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 - -Call: cca(formula = dune ~ Moisture + Management, data = dune.env) - - Inertia Proportion Rank -Total 2.1153 1.0000 -Constrained 1.0024 0.4739 6 -Unconstrained 1.1129 0.5261 13 -Inertia is mean squared contingency coefficient - -Eigenvalues for constrained axes: - CCA1 CCA2 CCA3 CCA4 CCA5 CCA6 -0.44583 0.28869 0.11239 0.07166 0.04937 0.03444 - -Eigenvalues for unconstrained axes: - CA1 CA2 CA3 CA4 CA5 CA6 CA7 CA8 -0.350396 0.152057 0.125084 0.109838 0.092209 0.077107 0.059441 0.047755 - CA9 CA10 CA11 CA12 CA13 -0.036958 0.022266 0.020700 0.010827 0.008252 - +> ## see ?ordistep to do the same, but based on permutation P-values +> ## Not run: +> ##D ordistep(cca(dune ~ 1, dune.env), reformulate(names(dune.env)), perm.max=200) +> ## End(Not run) > ## Manual model building > ## -- define the maximal model for scope > mbig <- rda(dune ~ ., dune.env) @@ -505,21 +447,21 @@ > add1(m0, scope=formula(mbig), test="perm") Df AIC F N.Perm Pr(>F) 89.620 -A1 1 89.591 1.9217 199 0.055 . +A1 1 89.591 1.9217 199 0.070 . Moisture 3 87.707 2.5883 199 0.005 ** Management 3 87.082 2.8400 199 0.005 ** -Use 2 91.032 1.1741 99 0.270 +Use 2 91.032 1.1741 99 0.180 Manure 4 89.232 1.9539 199 0.010 ** --- Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 > m0 <- update(m0, . ~ . + Management) > add1(m0, scope=formula(mbig), test="perm") - Df AIC F N.Perm Pr(>F) - 87.082 -A1 1 87.424 1.2965 99 0.21 -Moisture 3 85.567 1.9764 199 0.03 * -Use 2 88.284 1.0510 99 0.41 -Manure 3 87.517 1.3902 199 0.07 . + Df AIC F N.Perm Pr(>F) + 87.082 +A1 1 87.424 1.2965 99 0.240 +Moisture 3 85.567 1.9764 199 0.005 ** +Use 2 88.284 1.0510 99 0.430 +Manure 3 87.517 1.3902 199 0.130 --- Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 > m0 <- update(m0, . ~ . + Moisture) @@ -527,16 +469,16 @@ > drop1(m0, test="perm") Df AIC F N.Perm Pr(>F) 85.567 -Management 3 87.707 2.1769 199 0.015 * -Moisture 3 87.082 1.9764 199 0.005 ** +Management 3 87.707 2.1769 199 0.010 ** +Moisture 3 87.082 1.9764 199 0.015 * --- Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 > add1(m0, scope=formula(mbig), test="perm") Df AIC F N.Perm Pr(>F) 85.567 -A1 1 86.220 0.8359 99 0.66 -Use 2 86.842 0.8027 99 0.66 -Manure 3 85.762 1.1225 99 0.31 +A1 1 86.220 0.8359 99 0.72 +Use 2 86.842 0.8027 99 0.77 +Manure 3 85.762 1.1225 99 0.26 > > > @@ -549,7 +491,8 @@ > ### Name: adipart > ### Title: Additive Diversity Partitioning and Hierarchical Null Model > ### Testing -> ### Aliases: adipart hiersimu print.hiersimu +> ### Aliases: adipart adipart.default adipart.formula hiersimu +> ### hiersimu.default hiersimu.formula > ### Keywords: multivariate > > ### ** Examples @@ -565,10 +508,10 @@ + out <- rep(1, length(x)) + for (i in 2:(length(cut) - 1)) + out[which(x > cut[i] & x <= cut[(i + 1)])] <- i -+ return(as.factor(out))} ++ return(out)} > ## The hierarchy of sample aggregation > levsm <- data.frame( -+ l1=as.factor(1:nrow(mite)), ++ l1=1:nrow(mite), + l2=cutter(mite.xy$y, cut = seq(0, 10, by = 2.5)), + l3=cutter(mite.xy$y, cut = seq(0, 10, by = 5)), + l4=cutter(mite.xy$y, cut = seq(0, 10, by = 10))) @@ -579,41 +522,90 @@ > plot(mite.xy, main="l3", col=as.numeric(levsm$l3)+1) > par(mfrow=c(1,1)) > ## Additive diversity partitioning -> adipart(mite ~., levsm, index="richness", nsimul=19) -adipart with 19 simulations -with index richness, weights unif +> adipart(mite, index="richness", nsimul=19) +adipart object - statistic z 2.5% 50% 97.5% Pr(sim.) -alpha.1 15.1143 -38.7550 22.0321 22.3000 22.608 0.05 * -alpha.2 29.7500 -27.1142 34.5000 34.7500 35.000 0.05 * -alpha.3 33.0000 0.0000 35.0000 35.0000 35.000 0.05 * -gamma 35.0000 0.0000 35.0000 35.0000 35.000 1.00 -beta.1 14.6357 9.0433 12.1629 12.4500 12.955 0.05 * -beta.2 3.2500 16.4371 0.0000 0.2500 0.500 0.05 * -beta.3 2.0000 0.0000 0.0000 0.0000 0.000 0.05 * +Call: adipart(y = mite, index = "richness", nsimul = 19) + +nullmodel method ?r2dtable? with 19 simulations +options: index richness, weights unif +alternative hypothesis: simulated median is not equal to the statistic + + statistic z mean 2.5% 50% 97.5% Pr(sim.) +alpha.1 15.114 -38.43 22.344 22.032 22.300 22.608 0.05 * +gamma 35.000 0.00 35.000 35.000 35.000 35.000 1.00 +beta.1 19.886 38.43 12.656 12.392 12.700 12.968 0.05 * --- Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 +> adipart(mite ~ ., levsm, index="richness", nsimul=19) +adipart object + +Call: adipart(formula = mite ~ ., data = levsm, index = "richness", +nsimul = 19) + +nullmodel method ?r2dtable? with 19 simulations +options: index richness, weights unif +alternative hypothesis: simulated median is not equal to the statistic + + statistic z mean 2.5% 50% 97.5% Pr(sim.) +alpha.1 15.114 -46.2370 22.39624 22.12571 22.44286 22.6236 0.05 * +alpha.2 29.750 -21.7076 34.81579 34.36250 35.00000 35.0000 0.05 * +alpha.3 33.000 0.0000 35.00000 35.00000 35.00000 35.0000 0.05 * +gamma 35.000 0.0000 35.00000 35.00000 35.00000 35.0000 1.00 +beta.1 14.636 9.0407 12.41955 12.00750 12.42857 12.8743 0.05 * +beta.2 3.250 13.1373 0.18421 0.00000 0.00000 0.6375 0.05 * +beta.3 2.000 0.0000 0.00000 0.00000 0.00000 0.0000 0.05 * +--- +Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 > ## Hierarchical null model testing > ## diversity analysis (similar to adipart) -> hiersimu(mite ~., levsm, diversity, relative=TRUE, nsimul=19) -hiersimu with 19 simulations +> hiersimu(mite, FUN=diversity, relative=TRUE, nsimul=19) +hiersimu object - statistic z 2.5% 50% 97.5% Pr(sim.) -l1 0.76064 -65.47286 0.93511 0.93959 0.9437 0.05 * -l2 0.89736 -127.77766 0.99635 0.99815 0.9989 0.05 * -l3 0.92791 -516.33891 0.99921 0.99948 0.9997 0.05 * -l4 1.00000 0.00000 1.00000 1.00000 1.0000 1.00 +Call: hiersimu(y = mite, FUN = diversity, relative = TRUE, nsimul = 19) + +nullmodel method ?r2dtable? with 19 simulations + +alternative hypothesis: simulated median is not equal to the statistic + + statistic z mean 2.5% 50% 97.5% Pr(sim.) +level_1 0.76064 -71.195 0.93904 0.93487 0.93856 0.9444 0.05 * +leve_2 1.00000 0.000 1.00000 1.00000 1.00000 1.0000 1.00 --- Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 +> hiersimu(mite ~., levsm, FUN=diversity, relative=TRUE, nsimul=19) +hiersimu object + +Call: hiersimu(formula = mite ~ ., data = levsm, FUN = diversity, +relative = TRUE, nsimul = 19) + +nullmodel method ?r2dtable? with 19 simulations + +alternative hypothesis: simulated median is not equal to the statistic + + statistic z mean 2.5% 50% 97.5% Pr(sim.) +l1 0.76064 -75.139 0.93833 0.93389 0.93819 0.9427 0.05 * +l2 0.89736 -110.968 0.99811 0.99699 0.99814 0.9999 0.05 * +l3 0.92791 -417.338 0.99940 0.99904 0.99943 0.9996 0.05 * +l4 1.00000 0.000 1.00000 1.00000 1.00000 1.0000 1.00 +--- +Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 > ## Hierarchical testing with the Morisita index > morfun <- function(x) dispindmorisita(x)$imst > hiersimu(mite ~., levsm, morfun, drop.highest=TRUE, nsimul=19) -hiersimu with 19 simulations +hiersimu object - statistic z 2.5% 50% 97.5% Pr(sim.) -l1 0.52070 4.98527 0.31016 0.36570 0.4227 0.05 * -l2 0.60234 12.33099 0.11979 0.17096 0.2283 0.05 * -l3 0.67509 19.37352 -0.24164 -0.16761 -0.0895 0.05 * +Call: hiersimu(formula = mite ~ ., data = levsm, FUN = morfun, +drop.highest = TRUE, nsimul = 19) + +nullmodel method ?r2dtable? with 19 simulations + +alternative hypothesis: simulated median is not equal to the statistic + + statistic z mean 2.5% 50% 97.5% Pr(sim.) +l1 0.52070 8.5216 0.353253 0.322624 0.351073 0.3848 0.05 * +l2 0.60234 14.3854 0.153047 0.096700 0.150434 0.1969 0.05 * +l3 0.67509 20.3162 -0.182473 -0.234793 -0.195937 -0.0988 0.05 * --- Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 > @@ -641,6 +633,8 @@ Call: adonis(formula = dune ~ Management * A1, data = dune.env, permutations = 99) +Terms added sequentially (first to last) + Df SumsOfSqs MeanSqs F.Model R2 Pr(>F) Management 3 1.4686 0.48953 3.2629 0.34161 0.01 ** A1 1 0.4409 0.44089 2.9387 0.10256 0.02 * @@ -677,12 +671,12 @@ > > Y <- data.frame(Agropyron, Schizachyrium) > mod <- metaMDS(Y) -Run 0 stress 0.08556588 -Run 1 stress 0.1560545 -Run 2 stress 0.08556612 -... procrustes: rmse 0.0001630123 max resid 0.0003642025 +Run 0 stress 0.08556586 +Run 1 stress 0.1560544 +Run 2 stress 0.08556586 +... New best solution +... procrustes: rmse 1.094365e-06 max resid 1.88838e-06 *** Solution reached - > plot(mod) > ### Hulls show treatment > ordihull(mod, group=dat$NO3, show="0") @@ -691,28 +685,32 @@ > ordispider(mod, group=dat$field, lty=3, col="red") > > ### Correct hypothesis test (with strata) -> adonis(Y ~ NO3, data=dat, strata=dat$field, perm=1e3) +> adonis(Y ~ NO3, data=dat, strata=dat$field, perm=999) Call: -adonis(formula = Y ~ NO3, data = dat, permutations = 1000, strata = dat$field) +adonis(formula = Y ~ NO3, data = dat, permutations = 999, strata = dat$field) - Df SumsOfSqs MeanSqs F.Model R2 Pr(>F) -NO3 1 0.055856 0.055856 4.0281 0.28714 0.008991 ** -Residuals 10 0.138667 0.013867 0.71286 -Total 11 0.194524 1.00000 +Terms added sequentially (first to last) + + Df SumsOfSqs MeanSqs F.Model R2 Pr(>F) +NO3 1 0.055856 0.055856 4.0281 0.28714 0.009 ** +Residuals 10 0.138667 0.013867 0.71286 +Total 11 0.194524 1.00000 --- Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 > > ### Incorrect (no strata) -> adonis(Y ~ NO3, data=dat, perm=1e3) +> adonis(Y ~ NO3, data=dat, perm=999) Call: -adonis(formula = Y ~ NO3, data = dat, permutations = 1000) +adonis(formula = Y ~ NO3, data = dat, permutations = 999) - Df SumsOfSqs MeanSqs F.Model R2 Pr(>F) -NO3 1 0.055856 0.055856 4.0281 0.28714 0.004995 ** -Residuals 10 0.138667 0.013867 0.71286 -Total 11 0.194524 1.00000 +Terms added sequentially (first to last) + + Df SumsOfSqs MeanSqs F.Model R2 Pr(>F) +NO3 1 0.055856 0.055856 4.0281 0.28714 0.005 ** +Residuals 10 0.138667 0.013867 0.71286 +Total 11 0.194524 1.00000 --- Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 > @@ -750,7 +748,7 @@ Based on 999 permutations -Empirical upper confidence limits of R: +Upper quantiles of permutations (null model): 90% 95% 97.5% 99% 0.116 0.160 0.203 0.233 @@ -1094,7 +1092,8 @@ > ### Name: betadisper > ### Title: Multivariate homogeneity of groups dispersions (variances) > ### Aliases: betadisper scores.betadisper anova.betadisper plot.betadisper -> ### boxplot.betadisper TukeyHSD.betadisper ordimedian +> ### boxplot.betadisper TukeyHSD.betadisper eigenvals.betadisper +> ### ordimedian > ### Keywords: methods multivariate hplot > > ### ** Examples @@ -1118,17 +1117,13 @@ No. of Positive Eigenvalues: 15 No. of Negative Eigenvalues: 8 -Average distance to centroid: +Average distance to medoid: grazed ungrazed 0.3926 0.2706 Eigenvalues for PCoA axes: - PCoA1 PCoA2 PCoA3 PCoA4 PCoA5 PCoA6 PCoA7 PCoA8 PCoA9 PCoA10 - 1.7552 1.1334 0.4429 0.3698 0.2454 0.1961 0.1751 0.1284 0.0972 0.0760 - PCoA11 PCoA12 PCoA13 PCoA14 PCoA15 PCoA16 PCoA17 PCoA18 PCoA19 PCoA20 - 0.0637 0.0583 0.0395 0.0173 0.0051 -0.0004 -0.0065 -0.0133 -0.0254 -0.0375 - PCoA21 PCoA22 PCoA23 --0.0480 -0.0537 -0.0741 + PCoA1 PCoA2 PCoA3 PCoA4 PCoA5 PCoA6 PCoA7 PCoA8 +1.7552 1.1334 0.4429 0.3698 0.2454 0.1961 0.1751 0.1284 > > ## Perform test > anova(mod) @@ -1191,7 +1186,98 @@ > ## Draw a boxplot of the distances to centroid for each group > boxplot(mod) > +> ## `scores` and `eigenvals` also work +> scrs <- scores(mod) +> str(scrs) +List of 2 + $ sites : num [1:24, 1:2] 0.0946 -0.3125 -0.3511 -0.3291 -0.1926 ... + ..- attr(*, "dimnames")=List of 2 + .. ..$ : chr [1:24] "18" "15" "24" "27" ... + .. ..$ : chr [1:2] "PCoA1" "PCoA2" + $ centroids: num [1:2, 1:2] -0.1455 0.2786 0.0758 -0.2111 + ..- attr(*, "dimnames")=List of 2 + .. ..$ : chr [1:2] "grazed" "ungrazed" + .. ..$ : chr [1:2] "PCoA1" "PCoA2" +> head(scores(mod, 1:4, display = "sites")) + PCoA1 PCoA2 PCoA3 PCoA4 +18 0.09459373 0.15914576 0.074400844 -0.202466025 +15 -0.31248809 0.10032751 -0.062243360 0.110844864 +24 -0.35106507 -0.05954096 -0.038079447 0.095060928 +27 -0.32914546 -0.17019348 0.231623720 0.019110623 +23 -0.19259443 -0.01459250 -0.005679372 -0.209718312 +19 -0.06794575 -0.14501690 -0.085645653 0.002431355 +> # group centroids/medoids +> scores(mod, 1:4, display = "centroids") + PCoA1 PCoA2 PCoA3 PCoA4 +grazed -0.1455200 0.07584572 -0.01366220 -0.0178990 +ungrazed 0.2786095 -0.21114993 -0.03475586 0.0220129 +> # eigenvalues from the underlying principal coordinates analysis +> eigenvals(mod) + PCoA1 PCoA2 PCoA3 PCoA4 PCoA5 PCoA6 PCoA7 + 1.7552165 1.1334455 0.4429018 0.3698054 0.2453532 0.1960921 0.1751131 + PCoA8 PCoA9 PCoA10 PCoA11 PCoA12 PCoA13 PCoA14 + 0.1284467 0.0971594 0.0759601 0.0637178 0.0583225 0.0394934 0.0172699 + PCoA15 PCoA16 PCoA17 PCoA18 PCoA19 PCoA20 PCoA21 + 0.0051011 -0.0004131 -0.0064654 -0.0133147 -0.0253944 -0.0375105 -0.0480069 + PCoA22 PCoA23 +-0.0537146 -0.0741390 +> +> ## try out bias correction; compare with mod3 +> (mod3B <- betadisper(dis, groups, type = "median", bias.adjust=TRUE)) + + Homogeneity of multivariate dispersions + +Call: betadisper(d = dis, group = groups, type = "median", bias.adjust += TRUE) + +No. of Positive Eigenvalues: 15 +No. of Negative Eigenvalues: 8 + +Average distance to medoid: + grazed ungrazed + 0.4055 0.2893 + +Eigenvalues for PCoA axes: + PCoA1 PCoA2 PCoA3 PCoA4 PCoA5 PCoA6 PCoA7 PCoA8 +1.7552 1.1334 0.4429 0.3698 0.2454 0.1961 0.1751 0.1284 +> +> ## should always work for a single group +> group <- factor(rep("grazed", NROW(varespec))) +> (tmp <- betadisper(dis, group, type = "median")) + + Homogeneity of multivariate dispersions + +Call: betadisper(d = dis, group = group, type = "median") + +No. of Positive Eigenvalues: 15 +No. of Negative Eigenvalues: 8 + +Average distance to medoid: +grazed +0.4255 + +Eigenvalues for PCoA axes: + PCoA1 PCoA2 PCoA3 PCoA4 PCoA5 PCoA6 PCoA7 PCoA8 +1.7552 1.1334 0.4429 0.3698 0.2454 0.1961 0.1751 0.1284 +> (tmp <- betadisper(dis, group, type = "centroid")) + + Homogeneity of multivariate dispersions + +Call: betadisper(d = dis, group = group, type = "centroid") + +No. of Positive Eigenvalues: 15 +No. of Negative Eigenvalues: 8 + +Average distance to centroid: +grazed +0.4261 + +Eigenvalues for PCoA axes: + PCoA1 PCoA2 PCoA3 PCoA4 PCoA5 PCoA6 PCoA7 PCoA8 +1.7552 1.1334 0.4429 0.3698 0.2454 0.1961 0.1751 0.1284 +> > ## simulate missing values in 'd' and 'group' +> ## using spatial medians > groups[c(2,20)] <- NA > dis[c(2, 20)] <- NA > mod2 <- betadisper(dis, groups) ## warnings @@ -1208,15 +1294,13 @@ No. of Positive Eigenvalues: 14 No. of Negative Eigenvalues: 5 -Average distance to centroid: +Average distance to medoid: grazed ungrazed 0.3984 0.3008 Eigenvalues for PCoA axes: - PCoA1 PCoA2 PCoA3 PCoA4 PCoA5 PCoA6 PCoA7 PCoA8 PCoA9 PCoA10 - 1.4755 0.8245 0.4218 0.3456 0.2159 0.1688 0.1150 0.1060 0.0912 0.0639 - PCoA11 PCoA12 PCoA13 PCoA14 PCoA15 PCoA16 PCoA17 PCoA18 PCoA19 - 0.0420 0.0267 0.0157 0.0020 -0.0025 -0.0215 -0.0221 -0.0486 -0.0592 + PCoA1 PCoA2 PCoA3 PCoA4 PCoA5 PCoA6 PCoA7 PCoA8 +1.4755 0.8245 0.4218 0.3456 0.2159 0.1688 0.1150 0.1060 > permutest(mod2, control = permControl(nperm = 100)) Permutation test for homogeneity of multivariate dispersions @@ -1245,30 +1329,28 @@ > boxplot(mod2) > plot(TukeyHSD(mod2)) > -> ## Using spatial median -> mod3 <- betadisper(dis, groups, type = "median") -Warning in betadisper(dis, groups, type = "median") : +> ## Using group centroids +> mod3 <- betadisper(dis, groups, type = "centroid") +Warning in betadisper(dis, groups, type = "centroid") : Missing observations due to 'group' removed. -Warning in betadisper(dis, groups, type = "median") : +Warning in betadisper(dis, groups, type = "centroid") : Missing observations due to 'd' removed. > mod3 Homogeneity of multivariate dispersions -Call: betadisper(d = dis, group = groups, type = "median") +Call: betadisper(d = dis, group = groups, type = "centroid") No. of Positive Eigenvalues: 14 No. of Negative Eigenvalues: 5 Average distance to centroid: grazed ungrazed - 0.3984 0.3008 + 0.4001 0.3108 Eigenvalues for PCoA axes: - PCoA1 PCoA2 PCoA3 PCoA4 PCoA5 PCoA6 PCoA7 PCoA8 PCoA9 PCoA10 - 1.4755 0.8245 0.4218 0.3456 0.2159 0.1688 0.1150 0.1060 0.0912 0.0639 - PCoA11 PCoA12 PCoA13 PCoA14 PCoA15 PCoA16 PCoA17 PCoA18 PCoA19 - 0.0420 0.0267 0.0157 0.0020 -0.0025 -0.0215 -0.0221 -0.0486 -0.0592 + PCoA1 PCoA2 PCoA3 PCoA4 PCoA5 PCoA6 PCoA7 PCoA8 +1.4755 0.8245 0.4218 0.3456 0.2159 0.1688 0.1150 0.1060 > permutest(mod3, control = permControl(nperm = 100)) Permutation test for homogeneity of multivariate dispersions @@ -1283,22 +1365,27 @@ Mirrored permutations for Samples?: No Response: Distances - Df Sum Sq Mean Sq F N.Perm Pr(>F) -Groups 1 0.039979 0.039979 2.4237 100 0.1287 -Residuals 18 0.296910 0.016495 + Df Sum Sq Mean Sq F N.Perm Pr(>F) +Groups 1 0.033468 0.033468 3.1749 100 0.06931 . +Residuals 18 0.189749 0.010542 +--- +Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 > anova(mod3) Analysis of Variance Table Response: Distances - Df Sum Sq Mean Sq F value Pr(>F) -Groups 1 0.039979 0.039979 2.4237 0.1369 -Residuals 18 0.296910 0.016495 + Df Sum Sq Mean Sq F value Pr(>F) +Groups 1 0.033468 0.033468 3.1749 0.09166 . +Residuals 18 0.189749 0.010542 +--- +Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 > plot(mod3) > boxplot(mod3) > plot(TukeyHSD(mod3)) > > > +> > cleanEx() > nameEx("betadiver") > ### * betadiver @@ -1516,10 +1603,10 @@ 0.5413 0.3265 0.1293 Eigenvalues for unconstrained axes: - MDS1 MDS2 MDS3 MDS4 MDS5 MDS6 MDS7 MDS8 -0.906518 0.512743 0.337915 0.262598 0.203220 0.161762 0.124174 0.085570 - MDS9 MDS10 MDS11 MDS12 MDS13 MDS14 MDS15 -0.068881 0.058346 0.050083 0.027738 0.020839 0.007306 0.001345 + MDS1 MDS2 MDS3 MDS4 MDS5 MDS6 MDS7 MDS8 MDS9 MDS10 MDS11 +0.9065 0.5127 0.3379 0.2626 0.2032 0.1618 0.1242 0.0856 0.0689 0.0583 0.0501 + MDS12 MDS13 MDS14 MDS15 +0.0277 0.0208 0.0073 0.0013 > plot(vare.cap) > anova(vare.cap) @@ -1553,6 +1640,8 @@ 1.4408 0.8523 0.6015 0.4888 0.4187 0.3538 0.2877 0.2160 (Showed only 8 of all 19 unconstrained eigenvalues) +Constant added to distances: 0.2614286 + > ## Avoid negative eigenvalues by taking square roots of dissimilarities > capscale(varespec ~ N + P + K + Condition(Al), varechem, + dist = "bray", sqrt.dist= TRUE) @@ -1660,16 +1749,14 @@ Inertia is mean squared contingency coefficient Eigenvalues for constrained axes: - CCA1 CCA2 CCA3 CCA4 CCA5 CCA6 CCA7 CCA8 -0.438870 0.291775 0.162847 0.142130 0.117952 0.089029 0.070295 0.058359 - CCA9 CCA10 CCA11 CCA12 CCA13 CCA14 -0.031141 0.013294 0.008364 0.006538 0.006156 0.004733 + CCA1 CCA2 CCA3 CCA4 CCA5 CCA6 CCA7 CCA8 CCA9 CCA10 CCA11 +0.4389 0.2918 0.1628 0.1421 0.1180 0.0890 0.0703 0.0584 0.0311 0.0133 0.0084 + CCA12 CCA13 CCA14 +0.0065 0.0062 0.0047 Eigenvalues for unconstrained axes: - CA1 CA2 CA3 CA4 CA5 CA6 CA7 CA8 -0.197765 0.141926 0.101174 0.070787 0.053303 0.033299 0.018868 0.015104 - CA9 -0.009488 + CA1 CA2 CA3 CA4 CA5 CA6 CA7 CA8 CA9 +0.19776 0.14193 0.10117 0.07079 0.05330 0.03330 0.01887 0.01510 0.00949 > plot(vare.cca) > ## Formula interface and a better model @@ -1685,8 +1772,8 @@ Inertia is mean squared contingency coefficient Eigenvalues for constrained axes: - CCA1 CCA2 CCA3 CCA4 CCA5 CCA6 -0.37563 0.23419 0.14067 0.13229 0.10675 0.05614 + CCA1 CCA2 CCA3 CCA4 CCA5 CCA6 +0.3756 0.2342 0.1407 0.1323 0.1068 0.0561 Eigenvalues for unconstrained axes: CA1 CA2 CA3 CA4 CA5 CA6 CA7 CA8 @@ -1705,12 +1792,12 @@ Inertia is mean squared contingency coefficient Eigenvalues for constrained axes: - CCA1 -0.1572 + CCA1 +0.15722 Eigenvalues for unconstrained axes: - CA1 CA2 CA3 CA4 CA5 CA6 CA7 CA8 -0.47455 0.29389 0.21403 0.19541 0.17482 0.11711 0.11207 0.08797 + CA1 CA2 CA3 CA4 CA5 CA6 CA7 CA8 +0.4745 0.2939 0.2140 0.1954 0.1748 0.1171 0.1121 0.0880 (Showed only 8 of all 22 unconstrained eigenvalues) > cca(varespec ~ Ca + Condition(pH), varechem) @@ -1724,12 +1811,12 @@ Inertia is mean squared contingency coefficient Eigenvalues for constrained axes: - CCA1 -0.1827 + CCA1 +0.18269 Eigenvalues for unconstrained axes: - CA1 CA2 CA3 CA4 CA5 CA6 CA7 CA8 -0.38343 0.27487 0.21233 0.17599 0.17013 0.11613 0.10892 0.08797 + CA1 CA2 CA3 CA4 CA5 CA6 CA7 CA8 +0.3834 0.2749 0.2123 0.1760 0.1701 0.1161 0.1089 0.0880 (Showed only 8 of all 21 unconstrained eigenvalues) > ## RDA @@ -1790,18 +1877,18 @@ > > ### Name: clamtest > ### Title: Multinomial Species Classification Method (CLAM) -> ### Aliases: clamtest summary.clamtest print.summary.clamtest plot.clamtest +> ### Aliases: clamtest summary.clamtest plot.clamtest > ### Keywords: htest > > ### ** Examples > > data(mite) > data(mite.env) -> x <- clamtest(mite, mite.env$Shrub=="None", alpha=0.005, specialization = 0.667) -> summary(x) +> sol <- clamtest(mite, mite.env$Shrub=="None", alpha=0.005) +> summary(sol) Two Groups Species Classification Method (CLAM) -Specialization threshold = 0.667 +Specialization threshold = 0.6666667 Alpha level = 0.005 Estimated sample coverage: @@ -1817,7 +1904,7 @@ Specialist_FALSE 14 0.400 Specialist_TRUE 4 0.114 Too_rare 7 0.200 -> head(x) +> head(sol) Species Total_FALSE Total_TRUE Classes 1 Brachy 534 77 Generalist 2 PHTH 89 0 Specialist_FALSE @@ -1825,7 +1912,7 @@ 4 RARD 85 0 Specialist_FALSE 5 SSTR 22 0 Too_rare 6 Protopl 26 0 Too_rare -> plot(x) +> plot(sol) > > > @@ -1847,20 +1934,20 @@ + array(replicate(n, sample(x)), c(dim(x), n)) > (cs <- commsim("r00", fun=f, binary=TRUE, + isSeq=FALSE, mode="integer")) -An object of class "commsim" -"r00" method (binary, non-sequential, integer mode) +An object of class ?commsim? +?r00? method (binary, non-sequential, integer mode) > > ## retrieving the sequential swap algorithm > (cs <- make.commsim("swap")) -An object of class "commsim" -"swap" method (binary, sequential, integer mode) +An object of class ?commsim? +?swap? method (binary, sequential, integer mode) > > ## feeding a commsim object as argument > make.commsim(cs) -An object of class "commsim" -"swap" method (binary, sequential, integer mode) +An object of class ?commsim? +?swap? method (binary, sequential, integer mode) > > ## structural constraints @@ -1877,46 +1964,46 @@ + y <- simulate(m, nsim=n) + out <- rowMeans(sapply(1:dim(y)[3], + function(i) diagfun(attr(y, "data"), y[,,i]))) -+ z <- as.numeric(c(attr(y, "binary"), attr(y, "isSeq"))) -+ names(z) <- c("binary", "isSeq") ++ z <- as.numeric(c(attr(y, "binary"), attr(y, "isSeq"), ++ attr(y, "mode") == "double")) ++ names(z) <- c("binary", "isSeq", "double") + c(z, out) + } > x <- matrix(rbinom(10*12, 1, 0.5)*rpois(10*12, 3), 12, 10) > algos <- make.commsim() > a <- t(sapply(algos, evalfun, x=x, n=10)) -Warning in storage.mode(state) <- object$commsim$mode : - NAs introduced by coercion > print(as.table(ifelse(a==1,1,0)), zero.print = ".") - binary isSeq sum fill rowSums colSums rowFreq colFreq -r00 1 . 1 1 . . . . -c0 1 . 1 1 . 1 . 1 -r0 1 . 1 1 1 . 1 . -r1 1 . 1 1 1 . 1 . -r2 1 . 1 1 1 . 1 . -quasiswap 1 . 1 1 1 1 1 1 -swap 1 1 1 1 1 1 1 1 -tswap 1 1 1 1 1 1 1 1 -backtrack 1 . 1 1 1 1 1 1 -r2dtable . . 1 . 1 1 . . -swap_count . 1 . . . . . . -quasiswap_count . . 1 1 1 1 . . -swsh_samp . . 1 1 . . 1 1 -swsh_both . . 1 1 . . 1 1 -swsh_samp_r . . 1 1 1 . 1 1 -swsh_samp_c . . 1 1 . 1 1 1 -swsh_both_r . . 1 1 1 . 1 1 -swsh_both_c . . 1 1 . 1 1 1 -abuswap_r . 1 1 1 1 . 1 1 -abuswap_c . 1 1 1 . 1 1 1 -r00_samp . . 1 1 . . . . -c0_samp . . 1 1 . 1 . 1 -r0_samp . . 1 1 1 . 1 . -r00_ind . . 1 . . . . . -c0_ind . . 1 . . 1 . . -r0_ind . . 1 . 1 . . . -r00_both . . 1 1 . . . . -c0_both . . 1 1 . 1 . 1 -r0_both . . 1 1 1 . 1 . + binary isSeq double sum fill rowSums colSums rowFreq colFreq +r00 1 . . 1 1 . . . . +c0 1 . . 1 1 . 1 . 1 +r0 1 . . 1 1 1 . 1 . +r0_old 1 . . 1 1 1 . 1 . +r1 1 . . 1 1 1 . 1 . +r2 1 . . 1 1 1 . 1 . +quasiswap 1 . . 1 1 1 1 1 1 +swap 1 1 . 1 1 1 1 1 1 +tswap 1 1 . 1 1 1 1 1 1 +backtrack 1 . . 1 1 1 1 1 1 +r2dtable . . . 1 . 1 1 . . +swap_count . 1 . 1 1 1 1 . . +quasiswap_count . . . 1 1 1 1 . . +swsh_samp . . . 1 1 . . 1 1 +swsh_both . . . 1 1 . . 1 1 +swsh_samp_r . . . 1 1 1 . 1 1 +swsh_samp_c . . . 1 1 . 1 1 1 +swsh_both_r . . . 1 1 1 . 1 1 [TRUNCATED] To get the complete diff run: svnlook diff /svnroot/vegan -r 2488 From noreply at r-forge.r-project.org Tue Apr 9 14:13:31 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 9 Apr 2013 14:13:31 +0200 (CEST) Subject: [Vegan-commits] r2489 - in pkg/gravy: . inst Message-ID: <20130409121331.EB4E1184F60@r-forge.r-project.org> Author: jarioksa Date: 2013-04-09 14:13:31 +0200 (Tue, 09 Apr 2013) New Revision: 2489 Modified: pkg/gravy/DESCRIPTION pkg/gravy/NAMESPACE pkg/gravy/inst/ChangeLog Log: export pick.model Modified: pkg/gravy/DESCRIPTION =================================================================== --- pkg/gravy/DESCRIPTION 2013-04-09 08:43:27 UTC (rev 2488) +++ pkg/gravy/DESCRIPTION 2013-04-09 12:13:31 UTC (rev 2489) @@ -1,7 +1,7 @@ Package: gravy Title: Gradient Analysis of Vegetation -Version: 0.2-0 -Date: August 25, 2011 +Version: 0.2-1 +Date: April 9, 2013 Author: Jari Oksanen Maintainer: Jari Oksanen Suggests: lattice Modified: pkg/gravy/NAMESPACE =================================================================== --- pkg/gravy/NAMESPACE 2013-04-09 08:43:27 UTC (rev 2488) +++ pkg/gravy/NAMESPACE 2013-04-09 12:13:31 UTC (rev 2489) @@ -4,11 +4,11 @@ ## Export export(GaussPara, HOF, betadiversity, betahill, boxgradient, -gaussgradient, gradscale, hillscale, nichelap, plotGrad) +gaussgradient, gradscale, hillscale, nichelap, pick.model, plotGrad) ## Do NOT export the following internal functions: -## export(HOF1, gradder.HOF, pick.model, scale01, ssHOF) +## export(HOF1, gradder.HOF, scale01, ssHOF) ## S3 methods import(stats) Modified: pkg/gravy/inst/ChangeLog =================================================================== --- pkg/gravy/inst/ChangeLog 2013-04-09 08:43:27 UTC (rev 2488) +++ pkg/gravy/inst/ChangeLog 2013-04-09 12:13:31 UTC (rev 2489) @@ -1,3 +1,5 @@ +Version 0.2-1 April 9, 2013 + * NAMESPACE: export pick.model. Version 0.2-0 August 25, 2011 * NAMESPACE: added. Version 0.1-3 September 24, 2010 From noreply at r-forge.r-project.org Sat Apr 20 05:28:22 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 20 Apr 2013 05:28:22 +0200 (CEST) Subject: [Vegan-commits] r2490 - in pkg/vegan: . R inst man Message-ID: <20130420032822.DE33718534B@r-forge.r-project.org> Author: gsimpson Date: 2013-04-20 05:28:22 +0200 (Sat, 20 Apr 2013) New Revision: 2490 Modified: pkg/vegan/DESCRIPTION pkg/vegan/R/ordisurf.R pkg/vegan/inst/ChangeLog pkg/vegan/man/ordisurf.Rd Log: big changes to ordisurf in one nice commit that can be reverted easily. See Changelog for details. Modified: pkg/vegan/DESCRIPTION =================================================================== --- pkg/vegan/DESCRIPTION 2013-04-09 12:13:31 UTC (rev 2489) +++ pkg/vegan/DESCRIPTION 2013-04-20 03:28:22 UTC (rev 2490) @@ -1,7 +1,7 @@ Package: vegan Title: Community Ecology Package -Version: 2.1-28 -Date: March 17, 2013 +Version: 2.1-29 +Date: April 19, 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/R/ordisurf.R =================================================================== --- pkg/vegan/R/ordisurf.R 2013-04-09 12:13:31 UTC (rev 2489) +++ pkg/vegan/R/ordisurf.R 2013-04-20 03:28:22 UTC (rev 2490) @@ -17,17 +17,24 @@ `ordisurf.default` <- function (x, y, choices = c(1, 2), knots = 10, family = "gaussian", - col = "red", thinplate = TRUE, add = FALSE, display = "sites", - w = weights(x), main, nlevels = 10, levels, labcex = 0.6, - bubble = FALSE, cex = 1, select = FALSE, - method = "GCV.Cp", gamma = 1, plot = TRUE, ...) + col = "red", isotropic = TRUE, thinplate = TRUE, bs = "tp", + add = FALSE, display = "sites", + w = weights(x), main, nlevels = 10, levels, + npoints = 31, labcex = 0.6, + bubble = FALSE, cex = 1, select = TRUE, + method = "REML", gamma = 1, plot = TRUE, ...) { weights.default <- function(object, ...) NULL - GRID = 31 + if(!missing(thinplate)) { + warning("Use of 'thinplate' is deprecated and will soon be removed;\nuse 'isotropic' instead.") + isotropic <- thinplate + } + ## GRID no user-definable - why 31? + GRID <- npoints w <- eval(w) if (!is.null(w) && length(w) == 1) w <- NULL - require(mgcv) || stop("Requires package 'mgcv'") + require(mgcv) || stop("Requires package 'mgcv'") X <- scores(x, choices = choices, display = display, ...) ## The original name of 'y' may be lost in handling NA: save for ## plots @@ -40,21 +47,52 @@ } x1 <- X[, 1] x2 <- X[, 2] - if (knots <= 0) + ## handle knots - allow vector of length up to two + if (length(knots) > 2L) + warning("Number of knots supplied exceeds '2'. Only using the first two.") + ## expand knots robustly, no matter what length supplied + knots <- rep(knots, length.out = 2) + ## handle the bs - we only allow some of the possible options + if (length(bs) > 2L) + warning("Number of basis types supplied exceeds '2'. Only using the first two.") + bs <- rep(bs, length.out = 2) + ## check allowed types + BS <- c("tp","ts","cr","cs","ds","ps","ad") + want <- match(bs, BS) + user.bs <- bs ## store supplied (well expanded supplied ones) + bs <- BS[want] + if (any(wrong <- is.na(bs))) { + stop(paste("Supplied basis type of", + paste(sQuote(unique(user.bs[wrong])), collapse = ", "), + "not supported.")) + } + ## linear fit - note we match something close to 0 + if (knots[1] <= 0) { mod <- gam(y ~ x1 + x2, family = family, weights = w) - else if (knots == 1) + } else if (knots[1] == 1) { ## why do we treat this differently? mod <- gam(y ~ poly(x1, 1) + poly(x2, 1), family = family, weights = w, method = method) - else if (knots == 2) + } else if (knots[1] == 2) { mod <- gam(y ~ poly(x1, 2) + poly(x2, 2) + poly(x1, 1):poly(x2, 1), family = family, weights = w, method = method) - else if (thinplate) - mod <- gam(y ~ s(x1, x2, k = knots), family = family, + } else if (isotropic) { + mod <- gam(y ~ s(x1, x2, k = knots[1], bs = bs[1]), + family = family, weights = w, select = select, method = method, gamma = gamma) - else mod <- gam(y ~ s(x1, k = knots) + s(x2, k = knots), family = family, - weights = w, select = select, method = method, - gamma = gamma) + } else { + if (any(bs %in% c("ad"))) { ## only "ad" for now, but "fs" should also not be allowed + mod <- gam(y ~ s(x1, k = knots[1], bs = bs[1]) + + s(x2, k = knots[2], bs[2]), + family = family, weights = w, select = select, + method = method, gamma = gamma) + } else { + mod <- gam(y ~ te(x1, x2, k = knots, bs = bs), + family = family, + weights = w, select = select, method = method, + gamma = gamma) + } + } xn1 <- seq(min(x1), max(x1), len=GRID) xn2 <- seq(min(x2), max(x2), len=GRID) newd <- expand.grid(x1 = xn1, x2 = xn2) Modified: pkg/vegan/inst/ChangeLog =================================================================== --- pkg/vegan/inst/ChangeLog 2013-04-09 12:13:31 UTC (rev 2489) +++ pkg/vegan/inst/ChangeLog 2013-04-20 03:28:22 UTC (rev 2490) @@ -2,8 +2,31 @@ VEGAN DEVEL VERSIONS at http://r-forge.r-project.org/ -Version 2.1-28 (opened March 17, 2013) +Version 2.1-29 (opened April 19, 2013) + * ordisurf: significant changes were made to this function: + + - The default for `method` and `select` were changed to `"REML"` + and `TRUE` respectivelt. + + - Argument `thinplate` is deprecated in favour of `isotropic`. A + warning is now issued if `thinplate` is used. + + - The spline basis for the smoother can now be specified from a + subset of those implemented in the mgcv package. This is achieved + via the `bs` argument, which defaults to `"tp"` for thin plate + regression splines. + + - Argument `knots` and `bs` can now be a vector of length two, one + per ordination dimension considered. This is only of use with + anisotropic surfaces with `isotropic = FALSE`. + + - The number of locations in each ordination dimension at which the + fitted surface is evaluated can now be specified via new argument + `npoints`. + +Version 2.1-28 (closed April 19, 2013) + * betadisper: failed with type = "centroid" when there was only one group (i.e., in estimating the overall beta diversity in the data). Reported by Pierre Legendre. Modified: pkg/vegan/man/ordisurf.Rd =================================================================== --- pkg/vegan/man/ordisurf.Rd 2013-04-09 12:13:31 UTC (rev 2489) +++ pkg/vegan/man/ordisurf.Rd 2013-04-20 03:28:22 UTC (rev 2490) @@ -11,11 +11,12 @@ plots the result on ordination diagram. } \usage{ -\method{ordisurf}{default}(x, y, choices=c(1, 2), knots=10, family="gaussian", col="red", - thinplate = TRUE, add = FALSE, display = "sites", - w = weights(x), main, nlevels = 10, levels, labcex = 0.6, - bubble = FALSE, cex = 1, select = FALSE, method = "GCV.Cp", - gamma = 1, plot = TRUE, ...) +\method{ordisurf}{default}(x, y, choices = c(1, 2), knots = 10, + family = "gaussian", col = "red", isotropic = TRUE, + thinplate = TRUE, bs = "tp", add = FALSE, display = "sites", + w = weights(x), main, nlevels = 10, levels, npoints = 31, + labcex = 0.6, bubble = FALSE, cex = 1, select = TRUE, + method = "REML", gamma = 1, plot = TRUE, ...) \method{ordisurf}{formula}(formula, data, ...) @@ -37,11 +38,23 @@ more than degrees of freedom). If \code{knots = 0} or \code{knots = 1} the function will fit a linear trend surface, and if \code{knots = 2} the function will fit a quadratic trend surface - instead of a smooth surface. } - \item{family}{ Error distribution in \code{\link[mgcv]{gam}}. } + instead of a smooth surface. A vector of length 2 is allowed when + \code{isotropic = FALSE}, with the first and second elements of + \code{knots} refering to the first and second of the ordination + dimensions indicated by \code{choices}.} + \item{family}{Error distribution in \code{\link[mgcv]{gam}}.} \item{col}{ Colour of contours. } - \item{thinplate}{Use thinplate splines in \code{\link[mgcv]{gam}}.} - \item{add}{Add contours on an existing diagram or draw a new plot. } + \item{isotropic, thinplate}{Fit an isotropic smooth surface (i.e. same + smoothness in both ordination dimensions) via + \code{\link[mgcv]{gam}}. Use of \code{thinplate} is deprecated and + will be removed in a future version of the package.} + \item{bs}{a two letter character string indicating the smoothing basis + to use. (eg \code{"tp"} for thin plate regression spline, + \code{"cr"} for cubic regression spline). One of \code{c("tp", "ts", + "cr", "cs", "ds", "ps", "ad")}. See + \code{\link[mgcv]{smooth.terms}} for an over view of what these + refer to. The default is to use thin plate splines \code{"tp"}.} + \item{add}{Add contours to an existing diagram or draw a new plot.} \item{display}{Type of scores known by \code{\link{scores}}: typically "sites" for ordinary site scores or "lc" for linear combination scores.} \item{w}{Prior weights on the data. Concerns mainly \code{\link{cca}} @@ -49,8 +62,11 @@ \item{main}{The main title for the plot, or as default the name of plotted variable in a new plot.} \item{nlevels, levels}{Either a vector of \code{levels} for which contours - are drawn, or suggested number of contours in - \code{nlevels} if \code{levels} are not supplied.} + are drawn, or suggested number of contours in \code{nlevels} if + \code{levels} are not supplied.} + \item{npoints}{numeric; the number of locations at which to evaluate + the fitted surface. This represents the number of locations in each + dimension.} \item{labcex}{Label size in contours. Setting this zero will suppress labels.} \item{bubble}{Use \dQuote{bubble plot} for points, or vary the point @@ -83,7 +99,7 @@ \code{ordisurf}? Useful if all you want is the fitted response surface model.} \item{formula, data}{Alternative definition of the fitted model as - \code{x ~ y}, or left-hand side is the ordination \code{x} and + \code{x ~ y}, where left-hand side is the ordination \code{x} and right-hand side the single fitted continuous variable \code{y}. The variable \code{y} must be in the working environment or in the data frame or environment given by \code{data}. All @@ -104,17 +120,20 @@ \details{ - Function \code{ordisurf} fits a smooth surface using thinplate + Function \code{ordisurf} fits a smooth surface using penalised splines (Wood 2003) in \code{\link[mgcv]{gam}}, and uses \code{\link[mgcv]{predict.gam}} to find fitted values in a regular grid. The smooth surface can be fitted with an extra penalty that allows the entire smoother to be penalized back to 0 degrees of freedom, effectively removing the term from the model (see Marra & Wood, 2011). The addition of this extra penalty is invoked by - setting argument \code{select} to \code{TRUE}. The function plots - the fitted contours with convex hull of data points either over an - existing ordination diagram or draws a new plot. If - \code{select = TRUE} and the smooth is effectively penalised out of + setting argument \code{select} to \code{TRUE}. An alternative is to + use a spline basis that includes shrinkage (\code{bs = "ts"} or + \code{bs = "cs"}). + + The function plots the fitted contours with convex hull of data points + either over an existing ordination diagram or draws a new plot. If + \code{select = TRUE} and the smooth is effectively penalised out of the model, no contours will be plotted. \code{\link[mgcv]{gam}} determines the degree of smoothness for the @@ -128,14 +147,13 @@ The function uses \code{\link{scores}} to extract ordination scores, and \code{x} can be any result object known by that function. - User can supply a vector of prior weights \code{w}. If the ordination - object has weights, these will be used. In practise this means that - the row totals are used as weights with - \code{\link{cca}} or - \code{\link{decorana}} results. If you do not like this, but want to give - equal weights to all sites, you should set \code{w = NULL}. The - behaviour is consistent with \code{\link{envfit}}. For complete - accordance with constrained \code{\link{cca}}, you should set + The user can supply a vector of prior weights \code{w}. If the + ordination object has weights, these will be used. In practise this + means that the row totals are used as weights with \code{\link{cca}} + or \code{\link{decorana}} results. If you do not like this, but want + to give equal weights to all sites, you should set \code{w = + NULL}. The behaviour is consistent with \code{\link{envfit}}. For + complete accordance with constrained \code{\link{cca}}, you should set \code{display = "lc"} (and possibly \code{scaling = 2}). Function \code{calibrate} returns the fitted values of the response @@ -161,10 +179,22 @@ \author{ Dave Roberts, Jari Oksanen and Gavin L. Simpson } \note{ - The default is to use thinplate splines. These make sense in - ordination as they have equal smoothing in all directions and are - rotation invariant. + The default is to use an isotropic smoother via + \code{\link[mgcv]{s}} employing thin plate regression splines + (\code{bs = "tp"}). These make sense in ordination as they have + equal smoothing in all directions and are rotation invariant. However, + if different degrees of smoothness along one dimension, an anisotropic + smooth surface may be more applicable. This can be achieved through + the use of \code{isotropic = FALSE}, wherein the surface is fitted via + a tensor product smoother via \code{\link[mgcv]{te}} (unless \code{bs + = "ad"}, in which case separate splines for each dimension are + fitted using \code{\link[mgcv]{s}}). + Adaptive smooths (\code{bs = "ad"}), especially in two dimensions, + require a large number of observations; without many hundreds of + observations, the default complexities for the smoother will exceed + the number of observations and fitting will fail. + Graphical arguments supplied to \code{plot.ordisurf} are passed on to the underlying plotting functions, \code{contour}, \code{persp}, and \code{\link[mgcv]{plot.gam}}. The exception to this is that arguments @@ -217,6 +247,18 @@ ## or via plot.gam directly plot.gam(fit, cex = 2, pch = 1, col = "blue") ## 'col' effects all objects drawn... + +## Variable selection via additional shrinkage penalties +## This allows non-significant smooths to be selected out +## of the model not just to a linear surface. There are 2 +## options available: +## - option 1: `select = TRUE` +with(varechem, + ordisurf(vare.mds, Baresoil, method = "REML", select = TRUE)) +## - option 2: use a basis with shrinkage +with(varechem, + ordisurf(vare.mds, Baresoil, method = "REML", bs = "ts")) +## or bs = "cs" } \keyword{ multivariate } \keyword{ aplot } From noreply at r-forge.r-project.org Sat Apr 20 23:00:11 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 20 Apr 2013 23:00:11 +0200 (CEST) Subject: [Vegan-commits] r2491 - in pkg/vegan: R inst Message-ID: <20130420210011.C2D5B184C1F@r-forge.r-project.org> Author: gsimpson Date: 2013-04-20 23:00:11 +0200 (Sat, 20 Apr 2013) New Revision: 2491 Modified: pkg/vegan/R/ordisurf.R pkg/vegan/inst/ChangeLog Log: build formulae for different options and fit via a single gam call, not via separate hard-coded gam calls; also allows nicer printing of the actual formula used Modified: pkg/vegan/R/ordisurf.R =================================================================== --- pkg/vegan/R/ordisurf.R 2013-04-20 03:28:22 UTC (rev 2490) +++ pkg/vegan/R/ordisurf.R 2013-04-20 21:00:11 UTC (rev 2491) @@ -66,33 +66,33 @@ paste(sQuote(unique(user.bs[wrong])), collapse = ", "), "not supported.")) } - ## linear fit - note we match something close to 0 + ## Build formula if (knots[1] <= 0) { - mod <- gam(y ~ x1 + x2, family = family, weights = w) + f <- formula(y ~ x1 + x2) } else if (knots[1] == 1) { ## why do we treat this differently? - mod <- gam(y ~ poly(x1, 1) + poly(x2, 1), - family = family, weights = w, method = method) + f <- formula(y ~ poly(x1, 1) + poly(x2, 1)) } else if (knots[1] == 2) { - mod <- gam(y ~ poly(x1, 2) + poly(x2, 2) + poly(x1, 1):poly(x2, 1), - family = family, weights = w, method = method) + f <- formula(y ~ poly(x1, 2) + poly(x2, 2) + poly(x1, 1):poly(x2, 1)) } else if (isotropic) { - mod <- gam(y ~ s(x1, x2, k = knots[1], bs = bs[1]), - family = family, - weights = w, select = select, method = method, - gamma = gamma) + f <- formula(paste0("y ~ s(x1, x2, k = ", knots[1], + ", bs = \"", bs[1], "\")")) } else { - if (any(bs %in% c("ad"))) { ## only "ad" for now, but "fs" should also not be allowed - mod <- gam(y ~ s(x1, k = knots[1], bs = bs[1]) + - s(x2, k = knots[2], bs[2]), - family = family, weights = w, select = select, - method = method, gamma = gamma) + if (any(bs %in% c("ad"))) { + ## only "ad" for now, but "fs" should also not be allowed + f <- formula(paste0("y ~ s(x1, k = ", knots[1], + ", bs = \"", bs[1], "\") + s(x2, k = ", + knots[2], ", bs = \"", bs[1], "\")")) } else { - mod <- gam(y ~ te(x1, x2, k = knots, bs = bs), - family = family, - weights = w, select = select, method = method, - gamma = gamma) + f <- formula(paste0("y ~ te(x1, x2, k = c(", + paste0(knots, collapse = ", "), + "), bs = c(", + paste0("\"", bs, "\"", collapse = ", "), + "))")) } } + ## fit model + mod <- gam(f, family = family, weights = w, select = select, + method = method, gamma = gamma) xn1 <- seq(min(x1), max(x1), len=GRID) xn2 <- seq(min(x2), max(x2), len=GRID) newd <- expand.grid(x1 = xn1, x2 = xn2) @@ -100,14 +100,17 @@ poly <- chull(cbind(x1,x2)) ## Move out points of the convex hull to have contour for all data ## points - xhull1 <- x1[poly] + sign(x1[poly] - mean(x1[poly])) * diff(range(x1))/(GRID - 1) - xhull2 <- x2[poly] + sign(x2[poly] - mean(x2[poly])) * diff(range(x2))/(GRID - 1) + xhull1 <- x1[poly] + sign(x1[poly] - mean(x1[poly])) * + diff(range(x1))/(GRID - 1) + xhull2 <- x2[poly] + sign(x2[poly] - mean(x2[poly])) * + diff(range(x2))/(GRID - 1) npol <- length(poly) np <- nrow(newd) inpoly <- numeric(np) - inpoly <- .C("pnpoly", as.integer(npol), as.double(xhull1), as.double(xhull2), - as.integer(np), as.double(newd[,1]), as.double(newd[,2]), - inpoly = as.integer(inpoly), PACKAGE="vegan")$inpoly + inpoly <- .C("pnpoly", as.integer(npol), as.double(xhull1), + as.double(xhull2), as.integer(np), as.double(newd[,1]), + as.double(newd[,2]), inpoly = as.integer(inpoly), + PACKAGE="vegan")$inpoly is.na(fit) <- inpoly == 0 if(plot) { if (!add) { @@ -126,7 +129,8 @@ if (missing(levels)) levels <- pretty(range(fit, finite = TRUE), nlevels) ## Only plot surface is select is FALSE or (TRUE and EDF is diff from 0) - if(!select || (select && !isTRUE(all.equal(as.numeric(summary(mod)$edf), 0)))) + if(!select || + (select && !isTRUE(all.equal(as.numeric(summary(mod)$edf), 0)))) contour(xn1, xn2, matrix(fit, nrow=GRID), col = col, add = TRUE, levels = levels, labcex = labcex, drawlabels = !is.null(labcex) && labcex > 0) Modified: pkg/vegan/inst/ChangeLog =================================================================== --- pkg/vegan/inst/ChangeLog 2013-04-20 03:28:22 UTC (rev 2490) +++ pkg/vegan/inst/ChangeLog 2013-04-20 21:00:11 UTC (rev 2491) @@ -25,6 +25,10 @@ fitted surface is evaluated can now be specified via new argument `npoints`. + - The formula passed to `gam` is now built in greater detail. When + the model is printed the user can see exactly how the smoother was + constructed. + Version 2.1-28 (closed April 19, 2013) * betadisper: failed with type = "centroid" when there was only From noreply at r-forge.r-project.org Sat Apr 20 23:28:48 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 20 Apr 2013 23:28:48 +0200 (CEST) Subject: [Vegan-commits] r2492 - in pkg/vegan: R inst man Message-ID: <20130420212848.23C1D18423B@r-forge.r-project.org> Author: gsimpson Date: 2013-04-20 23:28:47 +0200 (Sat, 20 Apr 2013) New Revision: 2492 Modified: pkg/vegan/R/ordisurf.R pkg/vegan/inst/ChangeLog pkg/vegan/man/ordisurf.Rd Log: adds fx argument to fit fixed degree freedom regression splines Modified: pkg/vegan/R/ordisurf.R =================================================================== --- pkg/vegan/R/ordisurf.R 2013-04-20 21:00:11 UTC (rev 2491) +++ pkg/vegan/R/ordisurf.R 2013-04-20 21:28:47 UTC (rev 2492) @@ -18,11 +18,10 @@ `ordisurf.default` <- function (x, y, choices = c(1, 2), knots = 10, family = "gaussian", col = "red", isotropic = TRUE, thinplate = TRUE, bs = "tp", - add = FALSE, display = "sites", - w = weights(x), main, nlevels = 10, levels, - npoints = 31, labcex = 0.6, - bubble = FALSE, cex = 1, select = TRUE, - method = "REML", gamma = 1, plot = TRUE, ...) + fx = FALSE, add = FALSE, display = "sites", w = weights(x), + main, nlevels = 10, levels, npoints = 31, labcex = 0.6, + bubble = FALSE, cex = 1, select = TRUE, method = "REML", + gamma = 1, plot = TRUE, ...) { weights.default <- function(object, ...) NULL if(!missing(thinplate)) { @@ -49,9 +48,14 @@ x2 <- X[, 2] ## handle knots - allow vector of length up to two if (length(knots) > 2L) - warning("Number of knots supplied exceeds '2'. Only using the first two.") + warning("Length of 'knots' supplied exceeds '2'. Using the first two.") ## expand knots robustly, no matter what length supplied knots <- rep(knots, length.out = 2) + ## handle fx - allow vector of length up to two + if (length(fx) > 2L) + warning("Length of 'fx' supplied exceeds '2'. Using the first two.") + ## expand fx robustly, no matter what length supplied + fx <- rep(fx, length.out = 2) ## handle the bs - we only allow some of the possible options if (length(bs) > 2L) warning("Number of basis types supplied exceeds '2'. Only using the first two.") @@ -75,18 +79,22 @@ f <- formula(y ~ poly(x1, 2) + poly(x2, 2) + poly(x1, 1):poly(x2, 1)) } else if (isotropic) { f <- formula(paste0("y ~ s(x1, x2, k = ", knots[1], - ", bs = \"", bs[1], "\")")) + ", bs = \"", bs[1], "\", fx = ", fx[1],")")) } else { if (any(bs %in% c("ad"))) { ## only "ad" for now, but "fs" should also not be allowed f <- formula(paste0("y ~ s(x1, k = ", knots[1], - ", bs = \"", bs[1], "\") + s(x2, k = ", - knots[2], ", bs = \"", bs[1], "\")")) + ", bs = \"", bs[1], + "\", fx = ", fx[1], ") + s(x2, k = ", + knots[2], ", bs = \"", bs[2], + "\", fx = ", fx[2], ")")) } else { f <- formula(paste0("y ~ te(x1, x2, k = c(", paste0(knots, collapse = ", "), "), bs = c(", paste0("\"", bs, "\"", collapse = ", "), + "), fx = c(", + paste0(fx, collapse = ", "), "))")) } } Modified: pkg/vegan/inst/ChangeLog =================================================================== --- pkg/vegan/inst/ChangeLog 2013-04-20 21:00:11 UTC (rev 2491) +++ pkg/vegan/inst/ChangeLog 2013-04-20 21:28:47 UTC (rev 2492) @@ -21,6 +21,11 @@ per ordination dimension considered. This is only of use with anisotropic surfaces with `isotropic = FALSE`. + - New argument `fx`; indicates whether the smoothers are fixed + degrees of freedom regression splines (`fx = FALSE`) or a + penalised regression spline (`fx = TRUE`). Can be a vector of + length 2 for anisotropic surfaces (`isotropic = FALSE`). + - The number of locations in each ordination dimension at which the fitted surface is evaluated can now be specified via new argument `npoints`. Modified: pkg/vegan/man/ordisurf.Rd =================================================================== --- pkg/vegan/man/ordisurf.Rd 2013-04-20 21:00:11 UTC (rev 2491) +++ pkg/vegan/man/ordisurf.Rd 2013-04-20 21:28:47 UTC (rev 2492) @@ -13,10 +13,11 @@ \usage{ \method{ordisurf}{default}(x, y, choices = c(1, 2), knots = 10, family = "gaussian", col = "red", isotropic = TRUE, - thinplate = TRUE, bs = "tp", add = FALSE, display = "sites", - w = weights(x), main, nlevels = 10, levels, npoints = 31, - labcex = 0.6, bubble = FALSE, cex = 1, select = TRUE, - method = "REML", gamma = 1, plot = TRUE, ...) + thinplate = TRUE, bs = "tp", fx = FALSE, add = FALSE, + display = "sites", w = weights(x), main, nlevels = 10, + levels, npoints = 31, labcex = 0.6, bubble = FALSE, + cex = 1, select = TRUE, method = "REML", gamma = 1, + plot = TRUE, ...) \method{ordisurf}{formula}(formula, data, ...) @@ -54,6 +55,10 @@ "cr", "cs", "ds", "ps", "ad")}. See \code{\link[mgcv]{smooth.terms}} for an over view of what these refer to. The default is to use thin plate splines \code{"tp"}.} + \item{fx}{indicates whether the smoothers are fixed degree of freedom + regression splines (\code{fx = FALSE}) or penalised regression + splines (\code{fx = TRUE}). Can be a vector of length 2 for + anisotropic surfaces (\code{isotropic = FALSE}).} \item{add}{Add contours to an existing diagram or draw a new plot.} \item{display}{Type of scores known by \code{\link{scores}}: typically "sites" for ordinary site scores or "lc" for linear combination scores.} From noreply at r-forge.r-project.org Sun Apr 21 04:05:45 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 21 Apr 2013 04:05:45 +0200 (CEST) Subject: [Vegan-commits] r2493 - in pkg/vegan: R man Message-ID: <20130421020545.9D274184F90@r-forge.r-project.org> Author: gsimpson Date: 2013-04-21 04:05:40 +0200 (Sun, 21 Apr 2013) New Revision: 2493 Modified: pkg/vegan/R/ordisurf.R pkg/vegan/man/ordisurf.Rd Log: some of the bases don't work in 2-D 's()' smooths; 'fx = TRUE' and 'select = TRUE' are not compatible; updated all examples to reflect new defaults and options; updated the help page significantly with new notes, warnings etc. Modified: pkg/vegan/R/ordisurf.R =================================================================== --- pkg/vegan/R/ordisurf.R 2013-04-20 21:28:47 UTC (rev 2492) +++ pkg/vegan/R/ordisurf.R 2013-04-21 02:05:40 UTC (rev 2493) @@ -46,16 +46,27 @@ } x1 <- X[, 1] x2 <- X[, 2] + ## handle fx - allow vector of length up to two + if(!(missfx <- missing(fx)) && missing(knots)) + warning("Requested fixed d.f. splines but without specifying 'knots'.\nSwitching to 'fx = FALSE'.") + if (length(fx) > 2L) + warning("Length of 'fx' supplied exceeds '2'. Using the first two.") + ## expand fx robustly, no matter what length supplied + fx <- rep(fx, length.out = 2) + ## can't have `fx = TRUE` and `select = TRUE` + if(!missfx) { ## fx set by user + if((miss.select <- missing(select)) && any(fx)) { + warning("'fx = TRUE' requested; using 'select = FALSE'") + select <- FALSE + } else if(!miss.select && isTRUE(select)){ + stop("Fixed d.f. splines ('fx = TRUE') incompatible with 'select = TRUE'") + } + } ## handle knots - allow vector of length up to two if (length(knots) > 2L) warning("Length of 'knots' supplied exceeds '2'. Using the first two.") ## expand knots robustly, no matter what length supplied knots <- rep(knots, length.out = 2) - ## handle fx - allow vector of length up to two - if (length(fx) > 2L) - warning("Length of 'fx' supplied exceeds '2'. Using the first two.") - ## expand fx robustly, no matter what length supplied - fx <- rep(fx, length.out = 2) ## handle the bs - we only allow some of the possible options if (length(bs) > 2L) warning("Number of basis types supplied exceeds '2'. Only using the first two.") @@ -70,6 +81,10 @@ paste(sQuote(unique(user.bs[wrong])), collapse = ", "), "not supported.")) } + ## can't use "cr", "cs", "ps" in 2-d smoother with s() + if(isTRUE(isotropic) && any(bs %in% c("cr", "cs", "ps"))) { + stop("Bases \"cr\", \"cs\", and \"ps\" not allowed in isotropic smooths.") + } ## Build formula if (knots[1] <= 0) { f <- formula(y ~ x1 + x2) Modified: pkg/vegan/man/ordisurf.Rd =================================================================== --- pkg/vegan/man/ordisurf.Rd 2013-04-20 21:28:47 UTC (rev 2492) +++ pkg/vegan/man/ordisurf.Rd 2013-04-21 02:05:40 UTC (rev 2493) @@ -31,9 +31,10 @@ \arguments{ \item{x}{For \code{ordisurf} an ordination configuration, either a matrix or a result known by \code{\link{scores}}. For - \code{plot.ordisurf} and object of class \code{"ordisurf"} as + \code{plot.ordisurf} an object of class \code{"ordisurf"} as returned by \code{ordisurf}.} - \item{y}{ Variable to be plotted. } + \item{y}{Variable to be plotted / modelled as a function of the + ordination scores.} \item{choices}{Ordination axes. } \item{knots}{Number of initial knots in \code{\link[mgcv]{gam}} (one more than degrees of freedom). If \code{knots = 0} or @@ -41,8 +42,8 @@ if \code{knots = 2} the function will fit a quadratic trend surface instead of a smooth surface. A vector of length 2 is allowed when \code{isotropic = FALSE}, with the first and second elements of - \code{knots} refering to the first and second of the ordination - dimensions indicated by \code{choices}.} + \code{knots} refering to the first and second of ordination + dimensions (as indicated by \code{choices}) respectively.} \item{family}{Error distribution in \code{\link[mgcv]{gam}}.} \item{col}{ Colour of contours. } \item{isotropic, thinplate}{Fit an isotropic smooth surface (i.e. same @@ -54,12 +55,16 @@ \code{"cr"} for cubic regression spline). One of \code{c("tp", "ts", "cr", "cs", "ds", "ps", "ad")}. See \code{\link[mgcv]{smooth.terms}} for an over view of what these - refer to. The default is to use thin plate splines \code{"tp"}.} + refer to. The default is to use thin plate splines: \code{bs = "tp"}.} \item{fx}{indicates whether the smoothers are fixed degree of freedom regression splines (\code{fx = FALSE}) or penalised regression splines (\code{fx = TRUE}). Can be a vector of length 2 for - anisotropic surfaces (\code{isotropic = FALSE}).} - \item{add}{Add contours to an existing diagram or draw a new plot.} + anisotropic surfaces (\code{isotropic = FALSE}). It doesn't make + sense to use \code{fx = TRUE} \strong{and} \code{select = TRUE} and + it is an \strong{error} to do so. A warning is issued if you specify + \code{fx = TRUE} and forget to use \code{select = FALSE} though + fitting continues using \code{select = FALSE}.} + \item{add}{Add contours to an existing diagram or draw a new plot?} \item{display}{Type of scores known by \code{\link{scores}}: typically "sites" for ordinary site scores or "lc" for linear combination scores.} \item{w}{Prior weights on the data. Concerns mainly \code{\link{cca}} @@ -74,7 +79,7 @@ dimension.} \item{labcex}{Label size in contours. Setting this zero will suppress labels.} - \item{bubble}{Use \dQuote{bubble plot} for points, or vary the point + \item{bubble}{Use a \dQuote{bubble plot} for points, or vary the point diameter by the value of the plotted variable. If \code{bubble} is numeric, its value is used for the maximum symbol size (as in \code{cex}), or if \code{bubble = TRUE}, the value of \code{cex} gives @@ -99,7 +104,7 @@ of the scale.} \item{gamma}{Multiplier to inflate model degrees of freedom in GCV or UBRE/AIC score by. This effectively places an extra penalty on - complex models. An oft used value if \code{gamma = 1.4}.} + complex models. An oft-used value is \code{gamma = 1.4}.} \item{plot}{logical; should any plotting be done by \code{ordisurf}? Useful if all you want is the fitted response surface model.} @@ -119,7 +124,7 @@ details. \code{"gam"} plots the fitted GAM model, an object that inherits from class \code{"gam"} returned by \code{ordisurf}, see \code{\link[mgcv]{plot.gam}}.} - \item{\dots}{Other parameters passed to \code{\link[mgcv]{gam}}, or + \item{\dots}{Other parameters passed to \code{\link{scores}}, or to the graphical functions. See Note below for exceptions.} } @@ -136,18 +141,24 @@ use a spline basis that includes shrinkage (\code{bs = "ts"} or \code{bs = "cs"}). + \code{ordisurf()} exposes a large number of options from + \code{\link[mgcv]{gam}} for specifying the basis functions used for + the surface. If you stray from the defaults, do read the + \strong{Notes} section below and relevant documentation in + \code{\link[mgcv]{s}} and \code{\link[mgcv]{smooth.terms}}. + The function plots the fitted contours with convex hull of data points either over an existing ordination diagram or draws a new plot. If \code{select = TRUE} and the smooth is effectively penalised out of the model, no contours will be plotted. \code{\link[mgcv]{gam}} determines the degree of smoothness for the - fitted response surface during model fitting. Argument \code{method} - controls how \code{\link[mgcv]{gam}} performs this smoothness - selection. See \code{\link[mgcv]{gam}} for details of the available - options. Using \code{"REML"} or \code{"ML"} yields p-values for - smooths with the best coverage properties if such things matter to - you. + fitted response surface during model fitting, unless \code{fx = + TRUE}. Argument \code{method} controls how \code{\link[mgcv]{gam}} + performs this smoothness selection. See \code{\link[mgcv]{gam}} for + details of the available options. Using \code{"REML"} or \code{"ML"} + yields p-values for smooths with the best coverage properties if such + things matter to you. The function uses \code{\link{scores}} to extract ordination scores, and \code{x} can be any result object known by that function. @@ -169,17 +180,18 @@ } \value{ - Function is usually called for its side effect of drawing the - contour plot. The function returns the result object of class + \code{ordisurf} is usually called for its side effect of drawing the + contour plot. The function returns a result object of class \code{"ordisurf"} that inherits from \code{\link[mgcv]{gam}} used internally to fit the surface, but adds an item \code{grid} that contains the data for the grid surface. The item \code{grid} has elements \code{x} and \code{y} which are vectors of axis coordinates, and element \code{z} that is a matrix of fitted values for \code{\link{contour}}. The values outside the convex hull of observed - points are \code{NA} in \code{z}. The \code{\link[mgcv]{gam}} - component of the result can be used for further analysis like - predicting new values (see \code{\link[mgcv]{predict.gam}}). + points are indicated as \code{NA} in \code{z}. The + \code{\link[mgcv]{gam}} component of the result can be used for + further analysis like predicting new values (see + \code{\link[mgcv]{predict.gam}}). } \author{ Dave Roberts, Jari Oksanen and Gavin L. Simpson } @@ -188,18 +200,26 @@ \code{\link[mgcv]{s}} employing thin plate regression splines (\code{bs = "tp"}). These make sense in ordination as they have equal smoothing in all directions and are rotation invariant. However, - if different degrees of smoothness along one dimension, an anisotropic - smooth surface may be more applicable. This can be achieved through - the use of \code{isotropic = FALSE}, wherein the surface is fitted via - a tensor product smoother via \code{\link[mgcv]{te}} (unless \code{bs - = "ad"}, in which case separate splines for each dimension are - fitted using \code{\link[mgcv]{s}}). + if different degrees of smoothness along dimensions are required, an + anisotropic smooth surface may be more applicable. This can be + achieved through the use of \code{isotropic = FALSE}, wherein the + surface is fitted via a tensor product smoother via + \code{\link[mgcv]{te}} (unless \code{bs = "ad"}, in which case + separate splines for each dimension are fitted using + \code{\link[mgcv]{s}}). + Cubic regression splines and P splines can \strong{only} be used with + \code{isotropic = FALSE}. + Adaptive smooths (\code{bs = "ad"}), especially in two dimensions, require a large number of observations; without many hundreds of observations, the default complexities for the smoother will exceed the number of observations and fitting will fail. + To get the old behaviour of \code{ordisurf} use \code{select = FALSE}, + \code{method = "GCV.Cp"}, \code{fx = FALSE}, and \code{bs = "tp"}. The + latter two options are the current defaults. + Graphical arguments supplied to \code{plot.ordisurf} are passed on to the underlying plotting functions, \code{contour}, \code{persp}, and \code{\link[mgcv]{plot.gam}}. The exception to this is that arguments @@ -212,6 +232,20 @@ illustration of this. } +\section{Warning}{ + The fitted GAM is a regression model and has the usual assumptions of + such models. Of particular note is the assumption of independence of + residuals. If the observations are not independent (e.g. they are + repeat measures on a set of objects, or from an experimental design, + \emph{inter alia}) do not trust the \emph{p}-values from the GAM + output. + + If you need further control (i.e. to add additional fixed effects to + the model, or use more complex smoothers), extract the ordination + scores using the \code{scores} function and then generate your own + \code{\link[mgcv]{gam}} call. +} + \references{ Marra, G.P & Wood, S.N. (2011) Practical variable selection for @@ -235,15 +269,28 @@ vare.mds <- monoMDS(vare.dist) with(varechem, ordisurf(vare.mds, Baresoil, bubble = 5)) -## as above but with extra penalties on smooth terms: -with(varechem, ordisurf(vare.mds, Baresoil, bubble = 5, col = "blue", - add = TRUE, select = TRUE)) +## as above but without the extra penalties on smooth terms, +## and using GCV smoothness selection (old behaviour of `ordisurf()`): +with(varechem, ordisurf(vare.mds, Baresoil,col = "blue", add = TRUE, + select = FALSE, method = "GCV.Cp")) ## Cover of Cladina arbuscula fit <- with(varespec, ordisurf(vare.mds, Cla.arb, family=quasipoisson)) ## Get fitted values calibrate(fit) +## Variable selection via additional shrinkage penalties +## This allows non-significant smooths to be selected out +## of the model not just to a linear surface. There are 2 +## options available: +## - option 1: `select = TRUE` --- the *default* +with(varechem, + ordisurf(vare.mds, Baresoil, method = "REML", select = TRUE)) +## - option 2: use a basis with shrinkage +with(varechem, + ordisurf(vare.mds, Baresoil, method = "REML", bs = "ts")) +## or bs = "cs" with `isotropic = FALSE` + ## Plot method plot(fit, what = "contour") @@ -253,17 +300,24 @@ plot.gam(fit, cex = 2, pch = 1, col = "blue") ## 'col' effects all objects drawn... -## Variable selection via additional shrinkage penalties -## This allows non-significant smooths to be selected out -## of the model not just to a linear surface. There are 2 -## options available: -## - option 1: `select = TRUE` -with(varechem, - ordisurf(vare.mds, Baresoil, method = "REML", select = TRUE)) -## - option 2: use a basis with shrinkage -with(varechem, - ordisurf(vare.mds, Baresoil, method = "REML", bs = "ts")) -## or bs = "cs" +### controlling the basis functions used +## Use Duchon splines +with(varechem, ordisurf(vare.mds, Baresoil, bs = "ds")) + +## A fixed degrees of freedom smooth, must use 'select = FALSE' +with(varechem, ordisurf(vare.mds, Baresoil, knots = 4, + fx = TRUE, select = FALSE)) + +## An anisotropic smoother with cubic regression spline bases +with(varechem, ordisurf(vare.mds, Baresoil, isotropic = FALSE, + bs = "cr", knots = 4)) + +## An anisotropic smoother with cubic regression spline with +## shrinkage bases & different degrees of freedom in each dimension +with(varechem, ordisurf(vare.mds, Baresoil, isotropic = FALSE, + bs = "cs", knots = c(3,4), fx = TRUE, + select = FALSE)) + } \keyword{ multivariate } \keyword{ aplot } From noreply at r-forge.r-project.org Sun Apr 21 10:16:02 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 21 Apr 2013 10:16:02 +0200 (CEST) Subject: [Vegan-commits] r2494 - pkg/vegan/tests/Examples Message-ID: <20130421081602.9C6C718502F@r-forge.r-project.org> Author: jarioksa Date: 2013-04-21 10:16:02 +0200 (Sun, 21 Apr 2013) New Revision: 2494 Modified: pkg/vegan/tests/Examples/vegan-Ex.Rout.save Log: update tests/Examples for ordisurf changes Modified: pkg/vegan/tests/Examples/vegan-Ex.Rout.save =================================================================== --- pkg/vegan/tests/Examples/vegan-Ex.Rout.save 2013-04-21 02:05:40 UTC (rev 2493) +++ pkg/vegan/tests/Examples/vegan-Ex.Rout.save 2013-04-21 08:16:02 UTC (rev 2494) @@ -23,7 +23,7 @@ > options(warn = 1) > library('vegan') Loading required package: permute -This is vegan 2.1-28 +This is vegan 2.1-29 > > assign(".oldSearch", search(), pos = 'CheckExEnv') > cleanEx() @@ -161,10 +161,10 @@ Formula: y ~ poly(x1, 1) + poly(x2, 1) - + Total model degrees of freedom 3 -GCV score: 0.04278782 +REML score: -3.185099 > > > @@ -4959,43 +4959,78 @@ Link function: identity Formula: -y ~ s(x1, x2, k = knots) - +y ~ s(x1, x2, k = 10, bs = "tp", fx = FALSE) + Estimated degrees of freedom: -6.45 total = 7.45 +5.63 total = 6.63 -GCV score: 144.0039 +REML score: 92.96761 > -> ## as above but with extra penalties on smooth terms: -> with(varechem, ordisurf(vare.mds, Baresoil, bubble = 5, col = "blue", -+ add = TRUE, select = TRUE)) +> ## as above but without the extra penalties on smooth terms, +> ## and using GCV smoothness selection (old behaviour of `ordisurf()`): +> with(varechem, ordisurf(vare.mds, Baresoil,col = "blue", add = TRUE, ++ select = FALSE, method = "GCV.Cp")) Family: gaussian Link function: identity Formula: -y ~ s(x1, x2, k = knots) - +y ~ s(x1, x2, k = 10, bs = "tp", fx = FALSE) + Estimated degrees of freedom: -6.12 total = 7.12 +6.45 total = 7.45 -GCV score: 139.9445 +GCV score: 144.0039 > > ## Cover of Cladina arbuscula > fit <- with(varespec, ordisurf(vare.mds, Cla.arb, family=quasipoisson)) > ## Get fitted values > calibrate(fit) - 1 2 3 4 5 6 7 -22.0596535 6.0185659 3.6298559 4.1000950 8.9833600 5.9067472 8.6617389 - 8 9 10 11 12 13 14 -11.0812152 0.6432691 35.2567124 10.4452454 7.2748478 5.5780162 24.6561685 - 15 16 17 18 19 20 21 -18.8879906 29.7642964 5.6095920 9.5945524 3.2753633 2.6966143 10.7869351 - 22 23 24 - 2.9902832 9.8082237 7.3406581 + 1 2 3 4 5 6 7 8 +21.253963 5.675210 3.679486 3.898355 9.643787 7.698255 7.729282 9.758092 + 9 10 11 12 13 14 15 16 + 2.743202 29.700505 11.971987 8.310916 5.390556 24.906203 11.006871 25.330571 + 17 18 19 20 21 22 23 24 + 6.520735 9.410672 4.519645 4.090900 11.558075 4.314814 11.693769 14.244150 > +> ## Variable selection via additional shrinkage penalties +> ## This allows non-significant smooths to be selected out +> ## of the model not just to a linear surface. There are 2 +> ## options available: +> ## - option 1: `select = TRUE` --- the *default* +> with(varechem, ++ ordisurf(vare.mds, Baresoil, method = "REML", select = TRUE)) + +Family: gaussian +Link function: identity + +Formula: +y ~ s(x1, x2, k = 10, bs = "tp", fx = FALSE) + + +Estimated degrees of freedom: +5.63 total = 6.63 + +REML score: 92.96761 +> ## - option 2: use a basis with shrinkage +> with(varechem, ++ ordisurf(vare.mds, Baresoil, method = "REML", bs = "ts")) + +Family: gaussian +Link function: identity + +Formula: +y ~ s(x1, x2, k = 10, bs = "ts", fx = FALSE) + + +Estimated degrees of freedom: +4.43 total = 5.43 + +REML score: 96.2345 +> ## or bs = "cs" with `isotropic = FALSE` +> > ## Plot method > plot(fit, what = "contour") > @@ -5005,8 +5040,77 @@ > plot.gam(fit, cex = 2, pch = 1, col = "blue") > ## 'col' effects all objects drawn... > +> ### controlling the basis functions used +> ## Use Duchon splines +> with(varechem, ordisurf(vare.mds, Baresoil, bs = "ds")) + +Family: gaussian +Link function: identity + +Formula: +y ~ s(x1, x2, k = 10, bs = "ds", fx = FALSE) + + +Estimated degrees of freedom: +5.63 total = 6.63 + +REML score: 93.17149 > +> ## A fixed degrees of freedom smooth, must use 'select = FALSE' +> with(varechem, ordisurf(vare.mds, Baresoil, knots = 4, ++ fx = TRUE, select = FALSE)) + +Family: gaussian +Link function: identity + +Formula: +y ~ s(x1, x2, k = 4, bs = "tp", fx = TRUE) + + +Estimated degrees of freedom: +3 total = 4 + +REML score: 81.86011 > +> ## An anisotropic smoother with cubic regression spline bases +> with(varechem, ordisurf(vare.mds, Baresoil, isotropic = FALSE, ++ bs = "cr", knots = 4)) + +Family: gaussian +Link function: identity + +Formula: +y ~ te(x1, x2, k = c(4, 4), bs = c("cr", "cr"), fx = c(FALSE, + FALSE)) + + +Estimated degrees of freedom: +2.99 total = 3.99 + +REML score: 90.861 +> +> ## An anisotropic smoother with cubic regression spline with +> ## shrinkage bases & different degrees of freedom in each dimension +> with(varechem, ordisurf(vare.mds, Baresoil, isotropic = FALSE, ++ bs = "cs", knots = c(3,4), fx = TRUE, ++ select = FALSE)) + +Family: gaussian +Link function: identity + +Formula: +y ~ te(x1, x2, k = c(3, 4), bs = c("cs", "cs"), fx = c(TRUE, + TRUE)) + + +Estimated degrees of freedom: +11 total = 12 + +REML score: 39.58245 +> +> +> +> > cleanEx() detaching ?package:mgcv? @@ -5143,39 +5247,39 @@ Link function: identity Formula: -y ~ s(x1, x2, k = knots) - +y ~ s(x1, x2, k = 10, bs = "tp", fx = FALSE) + Estimated degrees of freedom: -8.93 total = 9.93 +8.71 total = 9.71 -GCV score: 0.001054656 +REML score: -120.7705 > ordisurf(mite.xy, scores(pcnm1, choi=2), bubble = 4, main = "PCNM 2") Family: gaussian Link function: identity Formula: -y ~ s(x1, x2, k = knots) - +y ~ s(x1, x2, k = 10, bs = "tp", fx = FALSE) + Estimated degrees of freedom: -7.75 total = 8.75 +7.18 total = 8.18 -GCV score: 0.002284958 +REML score: -103.4662 > ordisurf(mite.xy, scores(pcnm1, choi=3), bubble = 4, main = "PCNM 3") Family: gaussian Link function: identity Formula: -y ~ s(x1, x2, k = knots) - +y ~ s(x1, x2, k = 10, bs = "tp", fx = FALSE) + Estimated degrees of freedom: -8.9 total = 9.9 +8.32 total = 9.32 -GCV score: 0.002508871 +REML score: -94.19053 > par(op) > ## Plot first PCNMs against each other > ordisplom(pcnm1, choices=1:4) @@ -7725,13 +7829,13 @@ Link function: identity Formula: -y ~ s(x1, x2, k = knots) - +y ~ s(x1, x2, k = 10, bs = "tp", fx = FALSE) + Estimated degrees of freedom: -2 total = 3 +1.28 total = 2.28 -GCV score: 0.07246275 +REML score: 3.006229 > ### Example 3: analysis of dissimilarites a.k.a. non-parametric > ### permutational anova > adonis(dune ~ ., dune.env) @@ -8278,7 +8382,7 @@ > ### *