[Vegan-commits] r1341 - in pkg/vegan: R inst man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Nov 1 15:25:51 CET 2010


Author: jarioksa
Date: 2010-11-01 15:25:51 +0100 (Mon, 01 Nov 2010)
New Revision: 1341

Modified:
   pkg/vegan/R/nestednodf.R
   pkg/vegan/inst/ChangeLog
   pkg/vegan/man/nestedtemp.Rd
Log:
nestednodf breaks ties of col/row frequencies by col/row sums: upgrade by Gustavo Carvalho

Modified: pkg/vegan/R/nestednodf.R
===================================================================
--- pkg/vegan/R/nestednodf.R	2010-11-01 13:20:43 UTC (rev 1340)
+++ pkg/vegan/R/nestednodf.R	2010-11-01 14:25:51 UTC (rev 1341)
@@ -1,75 +1,71 @@
 `nestednodf` <- 
-    function(comm, order = TRUE, weighted = FALSE)
+    function(comm, order = TRUE, weighted = FALSE) 
 {
-    ## Keep it consistent with similar functions
-    if (!weighted) {
-        comm <- ifelse(comm > 0, 1, 0)
-    }
+    bin.comm <- ifelse(comm > 0, 1, 0)
+    rfill <- rowSums(bin.comm)
+    cfill <- colSums(bin.comm)
     if (order) {
-        comm <- comm[order(rowSums(comm), decreasing=TRUE),
-                     order(colSums(comm), decreasing=TRUE)]    
+        if (weighted) {
+            rgrad <- rowSums(comm)
+            cgrad <- colSums(comm)
+            rorder <- order(rfill, rgrad, decreasing = TRUE)
+            corder <- order(cfill, cgrad, decreasing = TRUE)
+        } else {
+            rorder <- order(rfill, decreasing = TRUE)
+            corder <- order(cfill, decreasing = TRUE)
+            comm <- bin.comm
+        }
+        comm <- comm[rorder, corder]
+        rfill <- rfill[rorder]
+        cfill <- cfill[corder]
     }
-    fill <- comm > 0
-    rfill <- rowSums(fill)
-    cfill <- colSums(fill)
     nr <- NROW(comm)
     nc <- NCOL(comm)
     fill <- sum(rfill)/length(comm)
-    ## Initializing the vectors that will hold nodf values
-    ## for each combination of rows and columns
-    N.paired.rows <- numeric(nr * (nr - 1) / 2)
-    N.paired.cols <- numeric(nc * (nc - 1) / 2)
+    N.paired.rows <- numeric(nr * (nr - 1)/2)
+    N.paired.cols <- numeric(nc * (nc - 1)/2)
     counter <- 0
-    ## Nested loops to get every combination of rows/columns
-    ## Row i
-    for (i in 1:(nr-1)) {
+    for (i in 1:(nr - 1)) {
         first <- comm[i, ]
-        ## Row j
-        for(j in (i + 1):nr) {
-            ## Counting the number of nodfs calculated so far
+        for (j in (i + 1):nr) {
             counter <- counter + 1
-            if (rfill[i] <= rfill[j] || any(rfill[c(i, j)] == 0))
+            if (rfill[i] <= rfill[j] || any(rfill[c(i, j)] == 0)) 
                 next
             if (weighted) {
                 second <- comm[j, ]
-                N.paired.rows[counter] <- sum(first - second > 0 & second > 0) /
-                    sum(second > 0)
+                N.paired.rows[counter] <-
+                    sum(first - second > 0 & second > 0)/sum(second > 0)
             }
             else {
-                N.paired.rows[counter] <- sum(first + comm[j, ] == 2) /
-                    rfill[j]
+                N.paired.rows[counter] <-
+                    sum(first + comm[j, ] == 2)/rfill[j]
             }
         }
     }
-    ## Reseting the counter
     counter <- 0
-    ## Column i
-    for (i in 1:(nc-1)) {
+    for (i in 1:(nc - 1)) {
         first <- comm[, i]
-        ## Column j
-        for(j in (i + 1):nc) {
+        for (j in (i + 1):nc) {
             counter <- counter + 1
-            if (cfill[i] <= cfill[j] || any(cfill[c(i, j)] == 0))
+            if (cfill[i] <= cfill[j] || any(cfill[c(i, j)] == 0)) 
                 next
             if (weighted) {
                 second <- comm[, j]
-                N.paired.cols[counter] <- sum(first - second > 0 & second > 0) /
-                    sum(second > 0)
+                N.paired.cols[counter] <-
+                    sum(first - second > 0 & second > 0)/sum(second > 0)
             }
             else {
-                N.paired.cols[counter] <- sum(first + comm[, j] == 2) /
-                    cfill[j]
+                N.paired.cols[counter] <-
+                    sum(first + comm[, j] == 2)/cfill[j]
             }
         }
     }
-    ## Calculating the means and the NODF for the whole matrix
     N.columns <- mean(N.paired.cols) * 100
     N.rows <- mean(N.paired.rows) * 100
     NODF <- (sum(c(N.paired.rows, N.paired.cols)) * 100)/
         ((nc * (nc - 1)/2) + (nr * (nr - 1)/2))
-    out <- list(comm = comm, fill = fill, 
-                statistic=c("N.columns" = N.columns, "N.rows" = N.rows,
-                "NODF" = NODF))
+    out <- list(comm = comm, fill = fill,
+                statistic = c(N.columns = N.columns, N.rows = N.rows, NODF = NODF))
     class(out) <- "nestednodf"
     return(out)
 }

Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog	2010-11-01 13:20:43 UTC (rev 1340)
+++ pkg/vegan/inst/ChangeLog	2010-11-01 14:25:51 UTC (rev 1341)
@@ -7,6 +7,11 @@
 	* prc: coefficients folded in a wrong way. Diagnosed, reported and
 	fixed by Cajo ter Braak.
 
+	* nestednodf: breaks ties in column and row totals by row sums and
+	column sums in quantitative data ('weighted = TRUE'). Version
+	submitted by Gustavo Carvalho in a follow-up to Feature Request
+	#1097. 
+
 Version 1.18-14 (closed November 1, 2010)
 
 	* treedist: works now with zero-height trees (for instance, only

Modified: pkg/vegan/man/nestedtemp.Rd
===================================================================
--- pkg/vegan/man/nestedtemp.Rd	2010-11-01 13:20:43 UTC (rev 1340)
+++ pkg/vegan/man/nestedtemp.Rd	2010-11-01 14:25:51 UTC (rev 1341)
@@ -106,7 +106,8 @@
   the whole matrix (\code{NODF}).  If you set \code{order = FALSE},
   the statistic is evaluated with the current matrix ordering allowing
   tests of other meaningful hypothesis of matrix structure than
-  ordering by row and column totals (see Almeida-Neto et
+  default ordering by row and column totals (breaking ties by total
+  abundances when \code{weighted = TRUE}) (see Almeida-Neto et
   al. 2008). With \code{weighted = TRUE}, the function finds the
   weighted version of the index (Almeida-Neto & Ulrich,
   2010). However, this requires quantitative null models for adequate



More information about the Vegan-commits mailing list