[Vegan-commits] r2273 - in branches/2.0: R inst
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Sep 10 09:02:23 CEST 2012
Author: jarioksa
Date: 2012-09-10 09:02:23 +0200 (Mon, 10 Sep 2012)
New Revision: 2273
Modified:
branches/2.0/R/adonis.R
branches/2.0/inst/ChangeLog
Log:
merge r2260: internal streamlining of adonis
Modified: branches/2.0/R/adonis.R
===================================================================
--- branches/2.0/R/adonis.R 2012-09-10 06:58:43 UTC (rev 2272)
+++ branches/2.0/R/adonis.R 2012-09-10 07:02:23 UTC (rev 2273)
@@ -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
@@ -98,7 +97,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
f.perms <- sapply(1:nterms, function(i) {
Modified: branches/2.0/inst/ChangeLog
===================================================================
--- branches/2.0/inst/ChangeLog 2012-09-10 06:58:43 UTC (rev 2272)
+++ branches/2.0/inst/ChangeLog 2012-09-10 07:02:23 UTC (rev 2273)
@@ -4,6 +4,7 @@
Version 2.0-5 (opened June 18, 2012)
+ * merge r2260: streamline adonis (internal changes).
* merge r2258: protect betadisper against changes in R-devel API.
* merge r2254: stylistic in examples of Rd files.
* merge r2250: do not use paste0 in envift.Rd (fails in R 2.14).
More information about the Vegan-commits
mailing list