[Vegan-commits] r2212 - branches/2.0/R branches/2.0/inst branches/2.0/man www

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Jun 3 11:11:51 CEST 2012


Author: jarioksa
Date: 2012-06-03 11:11:50 +0200 (Sun, 03 Jun 2012)
New Revision: 2212

Modified:
   branches/2.0/R/predict.cca.R
   branches/2.0/inst/ChangeLog
   branches/2.0/inst/NEWS.Rd
   branches/2.0/man/predict.cca.Rd
   www/NEWS.html
Log:
merge r2006,7: check dims in predcit(<cca() result>, type = 'response'|'working', newdata=)

Modified: branches/2.0/R/predict.cca.R
===================================================================
--- branches/2.0/R/predict.cca.R	2012-06-02 16:52:39 UTC (rev 2211)
+++ branches/2.0/R/predict.cca.R	2012-06-03 09:11:50 UTC (rev 2212)
@@ -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' ignored: it must have the same number of rows as the original community data with type = '%s'", type))
+        }
         if (take > 0) 
             Xbar <- u %*% slam %*% t(v)
         if (!is.null(object$pCCA)) 

Modified: branches/2.0/inst/ChangeLog
===================================================================
--- branches/2.0/inst/ChangeLog	2012-06-02 16:52:39 UTC (rev 2211)
+++ branches/2.0/inst/ChangeLog	2012-06-03 09:11:50 UTC (rev 2212)
@@ -3,7 +3,9 @@
 VEGAN RELEASE VERSIONS at http://cran.r-project.org/
 
 Version 2.0-4 (opened March 9, 2012)
-	
+
+	* merge r2206,7: check 'newdata' dims in predict(..., type =
+	"response"|"working") for CA results.
 	* merge r2195-7, 2204: bias adjusted betadisper.
 	* merge r2191-2193: standardise handling of 'select' arg in
 	those plotting functions that support it. Adds non-exported

Modified: branches/2.0/inst/NEWS.Rd
===================================================================
--- branches/2.0/inst/NEWS.Rd	2012-06-02 16:52:39 UTC (rev 2211)
+++ branches/2.0/inst/NEWS.Rd	2012-06-03 09:11:50 UTC (rev 2212)
@@ -29,6 +29,16 @@
         this. Now \code{ordiplot3d} sets equal axis ranges, and the
         documents urge users to verify that the aspect ratio is
         reasonably equal and the graph looks like a cube.
+
+      \item \code{predict} for \code{cca} results with \code{type =
+        "response"} or \code{type = "working"} failed with
+        \code{newdata} if it did not have the same number of rows as
+        the original model data.  Now the \code{newdata} is ignored if
+        it has a wrong number of rows.  The number of rows must match
+        because the results in these models must be weighted by
+        original row totals.  The problem did not concern \code{rda}
+        or \code{capscale} results which do not need row weights.
+        Reported by Glenn De'ath.
     
     }
   }% end bug fixes

Modified: branches/2.0/man/predict.cca.Rd
===================================================================
--- branches/2.0/man/predict.cca.Rd	2012-06-02 16:52:39 UTC (rev 2211)
+++ branches/2.0/man/predict.cca.Rd	2012-06-03 09:11:50 UTC (rev 2212)
@@ -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

Modified: www/NEWS.html
===================================================================
--- www/NEWS.html	2012-06-02 16:52:39 UTC (rev 2211)
+++ www/NEWS.html	2012-06-03 09:11:50 UTC (rev 2212)
@@ -45,6 +45,17 @@
 documents urge users to verify that the aspect ratio is
 reasonably equal and the graph looks like a cube.
 </p>
+</li>
+<li> <p><code>predict</code> for <code>cca</code> results with <code>type =
+        "response"</code> or <code>type = "working"</code> failed with
+<code>newdata</code> if it did not have the same number of rows as
+the original model data.  Now the <code>newdata</code> is ignored if
+it has a wrong number of rows.  The number of rows must match
+because the results in these models must be weighted by
+original row totals.  The problem did not concern <code>rda</code>
+or <code>capscale</code> results which do not need row weights.
+Reported by Glenn De'ath.
+</p>
 </li></ul>
 
 



More information about the Vegan-commits mailing list