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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Jun 1 10:01:34 CEST 2012


Author: jarioksa
Date: 2012-06-01 10:01:34 +0200 (Fri, 01 Jun 2012)
New Revision: 2206

Modified:
   pkg/vegan/R/predict.cca.R
   pkg/vegan/inst/ChangeLog
   pkg/vegan/man/predict.cca.Rd
Log:
check dimensions of 'newdata' in preict(..., type = 'response'|'working') of a cca() result

Modified: pkg/vegan/R/predict.cca.R
===================================================================
--- pkg/vegan/R/predict.cca.R	2012-05-28 06:58:16 UTC (rev 2205)
+++ pkg/vegan/R/predict.cca.R	2012-06-01 08:01:34 UTC (rev 2206)
@@ -1,4 +1,4 @@
-"predict.cca" <-
+`predict.cca` <-
     function (object, newdata, type = c("response", "wa", "sp", "lc", "working"), 
               rank = "full", model = c("CCA", "CA"), scaling = FALSE, ...) 
 {
@@ -22,9 +22,13 @@
     slam <- diag(sqrt(object[[model]]$eig[1:take]), nrow = take)
     if (type %in%  c("response", "working")) {
         Xbar <- 0
-        if (!missing(newdata))
-            u <- predict(object, type = if(model == "CCA") "lc" else "wa",
-                         newdata = newdata, rank = take)
+        if (!missing(newdata)) {
+            if (NROW(u) == NROW(newdata))
+                u <- predict(object, type = if(model == "CCA") "lc" else "wa",
+                             newdata = newdata, rank = take)
+            else
+                warning(gettextf("'newdata' must have the same number of rows as the original community data with type = '%s' -- 'newdata' ignored", type))
+        }
         if (take > 0) 
             Xbar <- u %*% slam %*% t(v)
         if (!is.null(object$pCCA)) 

Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog	2012-05-28 06:58:16 UTC (rev 2205)
+++ pkg/vegan/inst/ChangeLog	2012-06-01 08:01:34 UTC (rev 2206)
@@ -4,6 +4,12 @@
 
 Version 2.1-16 (opened May 11, 2012)
 
+	* predict.cca: number of rows must match in the original data and
+	'newdata' of cca() result, because original row weights are used
+	in scaling the results.  Now the match is checked, and
+	non-matching 'newdata' is ignored with warning.  Earlier this gave
+	an error.  Reported by Glenn De'ath.
+
 	* betadisper: the method is biased with small, unequal group
 	sizes. Bias corrected version can now be used with new argument
 	'bias.adjust' (defaults 'FALSE'). The problem was analysed and

Modified: pkg/vegan/man/predict.cca.Rd
===================================================================
--- pkg/vegan/man/predict.cca.Rd	2012-05-28 06:58:16 UTC (rev 2205)
+++ pkg/vegan/man/predict.cca.Rd	2012-06-01 08:01:34 UTC (rev 2206)
@@ -39,16 +39,22 @@
     \code{\link{rda}}, \code{\link{capscale}} or \code{\link{decorana}}. }
   \item{model}{Show constrained (\code{"CCA"}) or unconstrained
     (\code{"CA"}) results. For \code{\link{capscale}} this can also be 
-    \code{"Imaginary"} for imaginary components with negative eigenvalues. }
+    \code{"Imaginary"} for imaginary components with negative
+    eigenvalues. }
+  
   \item{newdata}{New data frame to be used in prediction or in
-    calibration.  Usually this a new community data frame, but for
-    \code{predict.cca} \code{type = "lc"} and for constrained component
-    with \code{type} \code{"response"} and \code{"working"} it must be
-    an environment data frame, If the original model had row or column
-    names, then new data must contain rows or columns with the same
-    names (row names for species scores, column names for \code{"wa"}
-    scores and constraint names of \code{"lc"} scores). In other cases
-    the rows or columns must match directly. }
+    calibration.  Usually this a new community data frame, but with
+    \code{type = "lc"} and for constrained component with \code{type =
+    "response"} and \code{type = "working"} it must be an environment
+    data frame.  The \code{newdata} must have the same number of rows as
+    the original community data for a \code{\link{cca}} result with
+    \code{type = "response"} or \code{type = "working"}.  If the
+    original model had row or column names, then new data must contain
+    rows or columns with the same names (row names for species scores,
+    column names for \code{"wa"} scores and constraint names of
+    \code{"lc"} scores). In other cases the rows or columns must match
+    directly. }
+
   \item{type}{The type of prediction, fitted values or residuals:
     \code{"response"} scales results so that the same ordination gives
     the same results, and \code{"working"} gives the values used
@@ -112,7 +118,11 @@
   residual or unconstrained component is desired.  With these types, the
   function uses \code{newdata} to find new \code{"lc"} (constrained) or
   \code{"wa"} scores (unconstrained) and then finding the response or
-  working data from these new row scores and species scores.
+  working data from these new row scores and species scores.  The
+  original site (row) and species (column) weights are used for
+  \code{type = "response"} and \code{type = "working"} in correspondence
+  analysis (\code{\link{cca}}) and therefore the number of rows must
+  match in the original data and \code{newdata}.
 
   If a completely new data frame is created, extreme care is needed
   defining variables similarly as in the original model, in particular



More information about the Vegan-commits mailing list