[Vegan-commits] r2260 - in pkg/vegan: R inst
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Aug 26 19:27:36 CEST 2012
Author: jarioksa
Date: 2012-08-26 19:27:36 +0200 (Sun, 26 Aug 2012)
New Revision: 2260
Modified:
pkg/vegan/R/adonis.R
pkg/vegan/inst/ChangeLog
Log:
Streamline adonis (internal changes)
Modified: pkg/vegan/R/adonis.R
===================================================================
--- pkg/vegan/R/adonis.R 2012-08-23 15:13:58 UTC (rev 2259)
+++ pkg/vegan/R/adonis.R 2012-08-26 17:27:36 UTC (rev 2260)
@@ -41,17 +41,18 @@
dmat <- dist.lhs^2
}
n <- nrow(dmat)
- I <- diag(n)
- ones <- matrix(1,nrow=n)
- A <- -(dmat)/2
- G <- -.5 * dmat %*% (I - ones%*%t(ones)/n)
+ ## G is -dmat/2 centred by rows
+ G <- -sweep(dmat, 1, rowMeans(dmat))/2
SS.Exp.comb <- sapply(H.s, function(hat) sum( G * t(hat)) )
SS.Exp.each <- c(SS.Exp.comb - c(0,SS.Exp.comb[-nterms]) )
H.snterm <- H.s[[nterms]]
+ ## t(I - H.snterm) is needed several times and we calculate it
+ ## here
+ tIH.snterm <- t(diag(n)-H.snterm)
if (length(H.s) > 1)
for (i in length(H.s):2)
H.s[[i]] <- H.s[[i]] - H.s[[i-1]]
- SS.Res <- sum( G * t(I-H.snterm))
+ SS.Res <- sum( G * tIH.snterm)
df.Exp <- sapply(u.grps[-1], function(i) sum(grps==i) )
df.Res <- n - qrhs$rank
## Get coefficients both for the species (if possible) and sites
@@ -66,8 +67,6 @@
colnames(beta.sites) <- rownames(lhs)
F.Mod <- (SS.Exp.each/df.Exp) / (SS.Res/df.Res)
-
-
f.test <- function(tH, G, df.Exp, df.Res, tIH.snterm) {
## HERE I TRY CHANGING t(H) TO tH, and
## t(I - H.snterm) to tIH.snterm, so that we don't have
@@ -105,7 +104,6 @@
}
tH.s <- lapply(H.s, t)
- tIH.snterm <- t(I-H.snterm)
## Apply permutations for each term
## This is the new f.test (2011-06-15) that uses fewer arguments
## Set first parallel processing for all terms
Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog 2012-08-23 15:13:58 UTC (rev 2259)
+++ pkg/vegan/inst/ChangeLog 2012-08-26 17:27:36 UTC (rev 2260)
@@ -4,6 +4,15 @@
Version 2.1-19 (opened August 20, 2012)
+ * adonis: Small changes in calculations. Simplified calculations
+ of matrix G as centred distance matrix, and does not keep n x n
+ matrices that are not needed (A) or used only once (identity
+ matrix I). These can make calculations marginally faster and
+ reduce the memory usage, but probably there are no observable
+ effects in most data sets. The new centring is probably more
+ accurate than older, and therefore the last significant digits can
+ slightly change (magnitude 1e-12 in tests).
+
* betadisper: An effective R stats .C function was used for double
centring, but it was removed from the API in r60360 | ripley |
2012-08-22 07:59:00 UTC (Wed, 22 Aug 2012). This removal stopped
More information about the Vegan-commits
mailing list