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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Apr 3 16:44:39 CEST 2011


Author: jarioksa
Date: 2011-04-03 16:44:39 +0200 (Sun, 03 Apr 2011)
New Revision: 1567

Modified:
   pkg/vegan/R/monoMDS.R
   pkg/vegan/inst/ChangeLog
Log:
handle missing values in monoMDS

Modified: pkg/vegan/R/monoMDS.R
===================================================================
--- pkg/vegan/R/monoMDS.R	2011-04-03 08:50:04 UTC (rev 1566)
+++ pkg/vegan/R/monoMDS.R	2011-04-03 14:44:39 UTC (rev 1567)
@@ -12,6 +12,13 @@
         dist <- mat[lower.tri(mat)]
         iidx <- row(mat)[lower.tri(mat)]
         jidx <- col(mat)[lower.tri(mat)]
+        ## Remove missing values
+        if (any(nas <- is.na(dist))) {
+            dist <- dist[!nas]
+            iidx <- iidx[!nas]
+            jidx <- jidx[!nas]
+        }
+        ## non-metric/metric: Fortran parameter 'iregn'
         if (model == "global")
             iregn <- 1
         else
@@ -23,13 +30,26 @@
         ## local NMDS: whole matrix without the diagonal, and rows in
         ## a row (hence transpose)
         mat <- t(as.matrix(dist))
+        ## Get missing values
+        nas <- is.na(mat)
+        ## groups by rows, except missing values
+        rs <- rowSums(!nas)
+        istart <- cumsum(rs)
+        istart <- c(1, istart[-length(istart)] + 1)
+        ## Full matrix expect the diagonal
         dist <- mat[col(mat) != row(mat)]
         iidx <- col(mat)[col(mat) != row(mat)]  # transpose!
         jidx <- row(mat)[col(mat) != row(mat)]
+        ## Remove missing values
+        if (any(nas)) {
+            nas <- nas[col(mat) != row(mat)]
+            dist <- dist[!nas]
+            iidx <- iidx[!nas]
+            jidx <- jidx[!nas]
+        }
         iregn <- 1
         nobj <- nrow(mat)
         ngrp <- nobj
-        istart <- seq(1, length(dist), by = (nobj-1))
     } else if (model == "hybrid") {
         ## Hybrid NMDS: two lower triangles, first a complete one,
         ## then those with dissimilarities below the threshold
@@ -37,6 +57,12 @@
         dist <- mat[lower.tri(mat)]
         iidx <- row(mat)[lower.tri(mat)]
         jidx <- col(mat)[lower.tri(mat)]
+        ## Missing values
+        if (any(nas <- is.na(dist))) {
+            dist <- dist[!nas]
+            iidx <- iidx[!nas]
+            jidx <- jidx[!nas]
+        }
         ## second group: dissimilarities below threshold
         ngrp <- 2
         istart <- c(1, length(dist) + 1)

Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog	2011-04-03 08:50:04 UTC (rev 1566)
+++ pkg/vegan/inst/ChangeLog	2011-04-03 14:44:39 UTC (rev 1567)
@@ -13,8 +13,10 @@
 	code is highly tuned, and much faster than other alternatives in
 	R. The R interfaces allows access to most features of the Fortan90
 	code, except adding new points to the ordination (which will need
-	a separate function). The function will eventually replaces
-	isoMDS() of the MASS package as the main NMDS engine in metaMDS().
+	a separate function). The missing values in dissimilarities are
+	also handled in the R interface. The function will eventually
+	replace isoMDS() of the MASS package as the main NMDS engine in
+	metaMDS().
 	
 Version 1.18-27 (closed April 1, 2011)
 



More information about the Vegan-commits mailing list