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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Nov 30 16:53:07 CET 2011


Author: jarioksa
Date: 2011-11-30 16:53:07 +0100 (Wed, 30 Nov 2011)
New Revision: 2016

Modified:
   pkg/vegan/R/ordimedian.R
   pkg/vegan/inst/ChangeLog
Log:
betadisper failed if 'groups' was a factor with empty levels

Modified: pkg/vegan/R/ordimedian.R
===================================================================
--- pkg/vegan/R/ordimedian.R	2011-11-20 17:53:25 UTC (rev 2015)
+++ pkg/vegan/R/ordimedian.R	2011-11-30 15:53:07 UTC (rev 2016)
@@ -21,12 +21,13 @@
     #dmedfun <- NULL
     pts <- scores(ord, display = display, ...)
     inds <- names(table(groups))
-    medians <- matrix(0, nrow = length(inds), ncol = ncol(pts))
+    medians <- matrix(NA, nrow = length(inds), ncol = ncol(pts))
     rownames(medians) <- inds
     colnames(medians) <- colnames(pts)
     for (i in inds) {
         X <- pts[groups == i, , drop = FALSE]
-        medians[i, ] <- optim(apply(X, 2, median, na.rm = TRUE),
+        if (NROW(X) > 0)
+            medians[i, ] <- optim(apply(X, 2, median, na.rm = TRUE),
                               fn = medfun, gr = dmedfun,
                               ord = X, method = "BFGS")$par
         if(label)

Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog	2011-11-20 17:53:25 UTC (rev 2015)
+++ pkg/vegan/inst/ChangeLog	2011-11-30 15:53:07 UTC (rev 2016)
@@ -4,6 +4,13 @@
 
 Version 2.1-8 (opened November 19, 2011)
 
+	* betadisper: failed with an error in internal function
+	betadisper() if there were empty levels. This could happen when
+	'groups' was a factor with empty levels, and was reported in 
+	https://stat.ethz.ch/pipermail/r-sig-ecology/2011-November/002525.html
+	The behaviour is now corrected in ordimedian() which will return NA
+	for empty factor levels. 
+	
 	* rarecurve: new function to draw rarefaction curves for each
 	plot, optionally with sample size vertical and corresponding
 	horizontal richness lines. Soil microbiologists with sequencing



More information about the Vegan-commits mailing list