[Vegan-commits] r320 - in pkg: . R inst

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Apr 19 08:11:59 CEST 2008


Author: jarioksa
Date: 2008-04-19 08:11:59 +0200 (Sat, 19 Apr 2008)
New Revision: 320

Modified:
   pkg/DESCRIPTION
   pkg/R/adonis.R
   pkg/inst/ChangeLog
Log:
permutation statistics fixed in adonis

Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION	2008-04-17 20:53:47 UTC (rev 319)
+++ pkg/DESCRIPTION	2008-04-19 06:11:59 UTC (rev 320)
@@ -1,7 +1,7 @@
 Package: vegan
 Title: Community Ecology Package
-Version: 1.12-10
-Date: Apr 13, 2008
+Version: 1.12-11
+Date: Apr 19, 2008
 Author: Jari Oksanen, Roeland Kindt, Pierre Legendre, Bob O'Hara, Gavin L. Simpson, 
   M. Henry H. Stevens  
 Maintainer: Jari Oksanen <jari.oksanen at oulu.fi>

Modified: pkg/R/adonis.R
===================================================================
--- pkg/R/adonis.R	2008-04-17 20:53:47 UTC (rev 319)
+++ pkg/R/adonis.R	2008-04-19 06:11:59 UTC (rev 320)
@@ -37,22 +37,23 @@
     I <- diag(n)
     ones <- matrix(1,nrow=n)
     A <- -(dmat)/2
-
     G <- -.5 * dmat %*% (I - ones%*%t(ones)/n)
-    
     SS.Exp.comb <- sapply(H.s, function(hat) sum( diag(G %*% hat) ) )
-    
     SS.Exp.each <- c(SS.Exp.comb - c(0,SS.Exp.comb[-nterms]) )
-    SS.Res <- sum(diag( ( G %*% (I-H.s[[nterms]]) )))
+    H.snterm <- H.s[[nterms]]
+    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(diag( ( G %*% (I-H.snterm))))
     df.Exp <- sapply(u.grps[-1], function(i) sum(grps==i) )
     df.Res <- n - qrhs$rank
     beta <-  qr.coef(qrhs, as.matrix(lhs) )
     colnames(beta) <- colnames(lhs)
     F.Mod <- (SS.Exp.each/df.Exp) / (SS.Res/df.Res)
 
-    f.test <- function(H, G, I, df.Exp, df.Res){
+    f.test <- function(H, G, I, df.Exp, df.Res, H.snterm){
         (sum( diag(G %*% H) )/df.Exp) /
-            ( sum(diag( G %*% (I-H) ))/df.Res) }
+            ( sum(diag( G %*% (I-H.snterm) ))/df.Res) }
     
     SS.perms <- function(H, G, I){
         c(SS.Exp.p = sum( diag(G%*%H) ),
@@ -69,7 +70,7 @@
     ## SS.s <- sapply(G.p, function(Gs) { SS.perms(H, Gs, I) } )
     f.perms <- sapply(1:nterms, function(i) {
         sapply(1:permutations, function(j) {
-            f.test(H.s[[i]], G.p[[j]], I, df.Exp[i], df.Res)
+            f.test(H.s[[i]], G.p[[j]], I, df.Exp[i], df.Res, H.snterm)
         } )
     })
     SumsOfSqs = c(SS.Exp.each, SS.Res, sum(SS.Exp.each) + SS.Res)

Modified: pkg/inst/ChangeLog
===================================================================
--- pkg/inst/ChangeLog	2008-04-17 20:53:47 UTC (rev 319)
+++ pkg/inst/ChangeLog	2008-04-19 06:11:59 UTC (rev 320)
@@ -2,8 +2,17 @@
 
 VEGAN DEVEL VERSIONS at http://r-forge.r-project.org/
 
-Version 1.12-10 (opened April 13, 2008)
+Version 1.12-11 (opened April 19, 2009)
 
+	* adonis: permutation tests fixed. The permutation statistics were
+	wrongly calculated. The results will now be different than in
+	older version, including the example(adonis). Basically, the
+	reported statitistic used SS improvement compared to the residual
+	of the complete model, but permutations used SS accumulation
+	compared to the residual after the current model.
+	
+Version 1.12-10 (closed April 19, 2008)
+
 	* adonis: the fix for the unused factor levels (r312) revealed
 	that adonis did not handle properly aliased variables and
 	pivoting. Results need checking.



More information about the Vegan-commits mailing list