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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Apr 5 14:51:34 CEST 2009


Author: gsimpson
Date: 2009-04-05 14:51:34 +0200 (Sun, 05 Apr 2009)
New Revision: 790

Modified:
   pkg/vegan/R/betadisper.R
   pkg/vegan/man/betadisper.Rd
Log:
add handling of missing observations to betadisper

Modified: pkg/vegan/R/betadisper.R
===================================================================
--- pkg/vegan/R/betadisper.R	2009-04-05 07:01:18 UTC (rev 789)
+++ pkg/vegan/R/betadisper.R	2009-04-05 12:51:34 UTC (rev 790)
@@ -15,6 +15,28 @@
     n <- attr(d, "Size")
     x <- matrix(0, ncol = n, nrow = n)
     x[row(x) > col(x)] <- d^2
+    ## site labels
+    labs <- attr(d, "Labels")
+    ## remove NAs in group
+    if(any(gr.na <- is.na(group))) {
+        group <- group[!gr.na]
+        x <- x[!gr.na, !gr.na]
+        ## update n otherwise C call crashes
+        n <- n - sum(gr.na)
+        ## update labels
+        labs <- labs[!gr.na]
+        warning("Missing observations due to 'group' removed.")
+    }
+    ## remove NA's in d
+    if(any(x.na <- apply(x, 1, function(x) any(is.na(x))))) {
+        x <- x[!x.na, !x.na]
+        group <- group[!x.na]
+        ## update n otherwise C call crashes
+        n <- n - sum(x.na)
+        ## update labels
+        labs <- labs[!x.na]
+        warning("Missing observations due to 'd' removed.")
+    }
     x <- x + t(x)
     storage.mode(x) <- "double"
     .C("dblcen", x, as.integer(n), DUP = FALSE, PACKAGE="stats")
@@ -63,7 +85,7 @@
         colnames(centroids) <- names(eig)
     else
         names(centroids) <- names(eig)
-    rownames(vectors) <- names(zij) <- attr(d, "Labels")
+    rownames(vectors) <- names(zij) <- labs
     retval <- list(eig = eig, vectors = vectors, distances = zij,
                    group = group, centroids = centroids, call = match.call())
     class(retval) <- "betadisper"

Modified: pkg/vegan/man/betadisper.Rd
===================================================================
--- pkg/vegan/man/betadisper.Rd	2009-04-05 07:01:18 UTC (rev 789)
+++ pkg/vegan/man/betadisper.Rd	2009-04-05 12:51:34 UTC (rev 790)
@@ -170,6 +170,9 @@
   If \code{group} consists of a single level or group, then the
   \code{anova} and \code{permutest} methods are not appropriate and if
   used on such data will stop with an error.
+
+  Missing values in either \code{d} or \code{group} will be removed
+  prior to performing the analysis.
 }
 \references{
   Anderson, M.J. (2006) Distance-based tests for homogeneity of
@@ -213,6 +216,17 @@
 
 ## Draw a boxplot of the distances to centroid for each group
 boxplot(mod)
+
+## simulate missing values in 'd' and 'group'
+groups[c(2,20)] <- NA
+dis[c(2, 20)] <- NA
+mod2 <- betadisper(dis, groups) ## warnings
+mod2
+permutest(mod, control = permControl(nperm = 100))
+anova(mod2)
+plot(mod2)
+boxplot(mod2)
+plot(TukeyHSD(mod2))
 }
 \keyword{methods}
 \keyword{multivariate}



More information about the Vegan-commits mailing list