[Vegan-commits] r774 - in branches/1.15: R inst man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Apr 1 13:48:00 CEST 2009


Author: jarioksa
Date: 2009-04-01 13:47:59 +0200 (Wed, 01 Apr 2009)
New Revision: 774

Modified:
   branches/1.15/R/mrpp.R
   branches/1.15/R/print.mrpp.R
   branches/1.15/inst/ChangeLog
   branches/1.15/man/mrpp.Rd
Log:
mrpp upgrade merged to branches/1.15 (rev 755 to 760)

Modified: branches/1.15/R/mrpp.R
===================================================================
--- branches/1.15/R/mrpp.R	2009-03-31 16:46:53 UTC (rev 773)
+++ branches/1.15/R/mrpp.R	2009-04-01 11:47:59 UTC (rev 774)
@@ -2,9 +2,13 @@
 function (dat, grouping, permutations = 1000, distance = "euclidean", 
     weight.type = 1, strata) 
 {
+    classmean <- function(ind, dmat, indls) {
+        sapply(indls, function(x)
+               mean(c(dmat[ind == x, ind == x]),
+                    na.rm = TRUE))
+    }
     mrpp.perms <- function(ind, dmat, indls, w) {
-        weighted.mean(sapply(indls, function(x) mean(c(dmat[ind == 
-            x, ind == x]), na.rm = TRUE)), w = w, na.rm = TRUE)
+        weighted.mean(classmean(ind, dmat, indls), w = w, na.rm = TRUE)
     }
     if (inherits(dat, "dist")) 
         dmat <- dat
@@ -18,22 +22,31 @@
     dmat <- as.matrix(dmat)
     diag(dmat) <- NA
     N <- nrow(dmat)
-    ind <- as.numeric(grouping)
-    indls <- unique(ind)
-    w <- sapply(indls, function(x) sum(ind == x))
-    w <- switch(weight.type, w, w - 1, w * (w - 1)/2)
-    del <- mrpp.perms(ind, dmat, indls, w)
+    grouping <- factor(grouping)
+    indls <- levels(grouping)
+    ncl <- sapply(indls, function(x) sum(grouping == x))
+    w <- switch(weight.type, ncl, ncl - 1, ncl * (ncl - 1)/2)
+    classdel <- classmean(grouping, dmat, indls)
+    names(classdel) <- names(ncl) <- indls
+    del <- weighted.mean(classdel, w = w, na.rm = TRUE)
+    E.del <- mean(dmat, na.rm = TRUE)
+    ## 'Classification strength' if weight.type == 3
+    if (weight.type == 3) {
+        CS <- N*(N-1)/2*(E.del - del)/(N*(N-1)/2 - sum(w))
+    } else {
+        CS <- NA
+    }
     if (missing(strata)) 
         strata <- NULL
-    perms <- sapply(1:permutations, function(x) ind[permuted.index(N, 
+    perms <- sapply(1:permutations, function(x) grouping[permuted.index(N, 
         strata = strata)])
     m.ds <- numeric(permutations)
     m.ds <- apply(perms, 2, function(x) mrpp.perms(x, dmat, indls, 
         w))
-    E.del <- mean(m.ds)
     p <- (1 + sum(del >= m.ds))/(permutations + 1)
     r2 <- 1 - del/E.del
-    out <- list(call = match.call(), delta = del, E.delta = E.del, 
+    out <- list(call = match.call(), delta = del, E.delta = E.del, CS = CS,
+        n = ncl, classdelta = classdel,
         Pvalue = p, A = r2, distance = distance, weight.type = weight.type, 
         boot.deltas = m.ds, permutations = permutations)
     if (!is.null(strata)) {
@@ -43,4 +56,3 @@
     class(out) <- "mrpp"
     out
 }
-

Modified: branches/1.15/R/print.mrpp.R
===================================================================
--- branches/1.15/R/print.mrpp.R	2009-03-31 16:46:53 UTC (rev 773)
+++ branches/1.15/R/print.mrpp.R	2009-04-01 11:47:59 UTC (rev 774)
@@ -8,6 +8,14 @@
     cat(deparse(x$call), "\n\n") 
     cat("Dissimilarity index:", x$distance, "\n")
     cat("Weights for groups: ", switch(x$weight.type, "n", "n-1", "n(n-1)", "n(n-1)/2"), "\n\n")
+    cat("Class means and counts:\n\n")
+    print(noquote(rbind("delta" = formatC(x$classdelta, digits = digits),
+                        "n" = formatC(x$n, digits=0))))
+    cat("\n")
+    if (!is.na(x$CS)) {
+        cat("Classification strength: ")
+        cat(formatC(x$CS, digits = digits), "\n")
+    }
     cat("Chance corrected within-group agreement A: ")
     cat(formatC(x$A, digits = digits), "\n")
     cat("Based on observed delta", formatC(x$delta), "and expected delta",
@@ -23,4 +31,3 @@
     cat("\n\n")
     invisible(x)
 }
-

Modified: branches/1.15/inst/ChangeLog
===================================================================
--- branches/1.15/inst/ChangeLog	2009-03-31 16:46:53 UTC (rev 773)
+++ branches/1.15/inst/ChangeLog	2009-04-01 11:47:59 UTC (rev 774)
@@ -5,7 +5,10 @@
 
 Version 1.15-2 (opened January 14, 2009)
 
-	* merger rev 762, 763, 765: better heuristics for detecting
+	* merged rev 755 to 760: mrpp upgrade: group statistics,
+	classification strength.
+	
+	* merged rev 762, 763, 765: better heuristics for detecting
 	open-ended dissimilarities (Euclidean, Manhattan) and triggering
 	half-change scaling. metaMDS honours 'halfchange'.
 

Modified: branches/1.15/man/mrpp.Rd
===================================================================
--- branches/1.15/man/mrpp.Rd	2009-03-31 16:46:53 UTC (rev 773)
+++ branches/1.15/man/mrpp.Rd	2009-04-01 11:47:59 UTC (rev 774)
@@ -63,6 +63,13 @@
 \eqn{A = 1 -\delta/E(\delta)}, where \eqn{E(\delta)} is the expected
 \eqn{\delta} assessed as the average of permutations.
 
+With \code{weight.type = 3}, the function also calculates classification
+strength (Van Sickle 1997) which is defined as the difference between
+average between group dissimilarities and within group
+dissimilarities. With \code{weight.type = 3} the classification strength
+is a simple transformation of \eqn{\delta}, and has the same permutation
+significance.
+
 If the first argument \code{dat} can be interpreted as dissimilarities,
 they will be used directly. In other cases the function treats
 \code{dat} as observations, and uses \code{\link{vegdist}} to find 
@@ -75,7 +82,13 @@
   \item{call }{	Function call.}
   \item{delta }{The overall weighted mean of group mean distances.}
   \item{E.delta}{expected delta, under the null hypothesis of no group
-    structure. This is the mean of the permuted deltas.}
+    structure. This is the mean of original dissimilarities.}
+  \item{CS}{Classification strength (Van Sickle 1997) with
+    \code{weight.type = 3} and \code{NA} with other weights.}
+  \item{n}{Number of observations in each class.}
+  \item{classdelta}{Mean dissimilarities within classes. The overall
+    \eqn{\delta} is the weighted average of these values with given
+    \code{weight.type}}. 
   \item{Pvalue}{Significance of the test.}
   \item{A}{A chance-corrected estimate of the proportion of the distances
     explained by group identity; a value analogous to a coefficient of 
@@ -88,13 +101,18 @@
   \item{permutations}{The number of permutations used.}
 }
 \references{
- P. W. Mielke and K. J. Berry. 2001. \emph{Permutation Methods: A
-   Distance  Function Approach.} Springer Series in
- Statistics. Springer.  
+  B. McCune and J. B. Grace. 2002. \emph{Analysis of Ecological
+  Communities.} MjM  Software Design, Gleneden Beach, Oregon, USA.
 
-B. McCune and J. B. Grace. 2002. \emph{Analysis of Ecological
-  Communities.} MjM  Software Design, Gleneden Beach, Oregon, USA. 
 
+  P. W. Mielke and K. J. Berry. 2001. \emph{Permutation Methods: A
+  Distance  Function Approach.} Springer Series in
+  Statistics. Springer.  
+
+  J. Van Sickle 1997. Using mean similarity dendrograms to evaluate
+  classifications. \emph{Journal of Agricultural, Biological, and Environmental
+  Statistics} 2:370-388.
+
 }
 \author{
 M. Herny H. Stevens \email{HStevens at muohio.edu} and Jari Oksanen.



More information about the Vegan-commits mailing list