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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Feb 9 17:19:39 CET 2010


Author: jarioksa
Date: 2010-02-09 17:19:39 +0100 (Tue, 09 Feb 2010)
New Revision: 1119

Modified:
   pkg/vegan/R/predict.cca.R
   pkg/vegan/R/predict.rda.R
   pkg/vegan/inst/ChangeLog
   pkg/vegan/man/predict.cca.Rd
Log:
predict.cca/rda gained choice type = 'working' similarly as fitted.cca/rda

Modified: pkg/vegan/R/predict.cca.R
===================================================================
--- pkg/vegan/R/predict.cca.R	2010-02-09 15:44:55 UTC (rev 1118)
+++ pkg/vegan/R/predict.cca.R	2010-02-09 16:19:39 UTC (rev 1119)
@@ -1,5 +1,5 @@
 "predict.cca" <-
-    function (object, newdata, type = c("response", "wa", "sp", "lc"), 
+    function (object, newdata, type = c("response", "wa", "sp", "lc", "working"), 
               rank = "full", model = c("CCA", "CA"), scaling = FALSE, ...) 
 {
     type <- match.arg(type)
@@ -18,14 +18,17 @@
     if (is.null(w)) 
         w <- u
     slam <- diag(sqrt(object[[model]]$eig[1:take]), nrow = take)
-    if (type == "response") {
+    if (type %in%  c("response", "working")) {
         Xbar <- 0
         if (take > 0) 
             Xbar <- u %*% slam %*% t(v)
         if (!is.null(object$pCCA)) 
             warning("Conditional ('partial') component ignored")
         rc <- outer(rs, cs)
-        out <- (Xbar + 1) * rc * gtot
+        if (type == "response") 
+            out <- (Xbar + 1) * rc * gtot
+        else                 # type == "working"
+            out <- Xbar * sqrt(rc)
     }
     else if (type == "lc") {
         if (model == "CA") 

Modified: pkg/vegan/R/predict.rda.R
===================================================================
--- pkg/vegan/R/predict.rda.R	2010-02-09 15:44:55 UTC (rev 1118)
+++ pkg/vegan/R/predict.rda.R	2010-02-09 16:19:39 UTC (rev 1119)
@@ -1,5 +1,5 @@
 `predict.rda` <-
-    function (object, newdata, type = c("response", "wa", "sp", "lc"), 
+    function (object, newdata, type = c("response", "wa", "sp", "lc", "working"), 
               rank = "full", model = c("CCA", "CA"), scaling = FALSE, ...) 
 {
     type <- match.arg(type)
@@ -22,7 +22,7 @@
     if (is.null(w)) 
         w <- u
     slam <- diag(sqrt(object[[model]]$eig[1:take] * nr), nrow = take)
-    if (type == "response") {
+    if (type %in% c("response", "working")) {
         if (!is.null(object$pCCA)) 
             warning("Conditional ('partial') component ignored")
         if (inherits(object, "capscale")) {
@@ -36,9 +36,13 @@
                 rownames(out) <- rownames(u)
                 colnames(out) <- rownames(v)
             }
-            if (!is.null(scal)) 
-                out <- sweep(out, 2, scal, "*")
-            out <- sweep(out, 2, cent, "+")
+            if (type == "response") {
+                if (!is.null(scal)) 
+                    out <- sweep(out, 2, scal, "*")
+                out <- sweep(out, 2, cent, "+")
+            } else {
+                out <- out/sqrt(nrow(out) - 1)
+            }
         }
     }
     else if (type == "lc") {

Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog	2010-02-09 15:44:55 UTC (rev 1118)
+++ pkg/vegan/inst/ChangeLog	2010-02-09 16:19:39 UTC (rev 1119)
@@ -6,7 +6,8 @@
 
 	* predict.cca, predict.rda: match 'newdata' by row names or column
 	names in type = "wa" and type = "sp". This is similar as
-	predict.prcomp/princomp.
+	predict.prcomp/princomp. Gained choice type = "working" for
+	working residuals (as fitted.cca/rda). 
 
 Version 1.18-0 (closeed January 11, 2010 with release 1.17-0)
 

Modified: pkg/vegan/man/predict.cca.Rd
===================================================================
--- pkg/vegan/man/predict.cca.Rd	2010-02-09 15:44:55 UTC (rev 1118)
+++ pkg/vegan/man/predict.cca.Rd	2010-02-09 16:19:39 UTC (rev 1119)
@@ -24,7 +24,7 @@
 \method{fitted}{capscale}(object, model = c("CCA", "CA", "Imaginary"),
     type = c("response", "working"), ...)
 \method{residuals}{cca}(object, ...)
-\method{predict}{cca}(object, newdata, type = c("response", "wa", "sp", "lc"),
+\method{predict}{cca}(object, newdata, type = c("response", "wa", "sp", "lc", "working"),
     rank = "full", model = c("CCA", "CA"), scaling = FALSE, ...)
 \method{calibrate}{cca}(object, newdata, rank = "full", ...)
 \method{coef}{cca}(object, ...)
@@ -43,20 +43,19 @@
     this a new community data frame, but for \code{predict.cca}
     \code{type = "lc"} it must be an environment data frame, and for
     \code{type = "response"} this is ignored.}
-  \item{type}{The type of prediction, fitted values or residuals: In
-    \code{fitted} and \code{residuals}, \code{"response"} scales results so
-    that the same ordination gives the same results, and \code{"working"}
-    gives the values used internally, that is after Chi-square
-    standardization in \code{\link{cca}} and scaling and centring in 
-    \code{\link{rda}}. In \code{\link{capscale}} the \code{"response"} gives
-    the dissimilarities, and \code{"working"} the scaled scores that produce
-    the dissimilarities as Euclidean distances.
-    In \code{predict} \code{"response"} 
-    gives an approximation of the original data matrix or dissimilarities, 
-    \code{"wa"} the site scores as weighted averages of the community data, 
-    \code{"lc"} the site scores as linear combinations of environmental data, 
-    and \code{"sp"} the species scores. In \code{predict.decorana} the
-    alternatives are scores for \code{"sites"} or \code{"species"}.} 
+  \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
+    internally, that is after Chi-square standardization in
+    \code{\link{cca}} and scaling and centring in
+    \code{\link{rda}}. In \code{\link{capscale}} the \code{"response"}
+    gives the dissimilarities, and \code{"working"} the scaled scores
+    that produce the dissimilarities as Euclidean
+    distances. Alternative \code{"wa"} gives the site scores as
+    weighted averages of the community data, \code{"lc"} the site
+    scores as linear combinations of environmental data, and
+    \code{"sp"} the species scores. In \code{predict.decorana} the
+    alternatives are scores for \code{"sites"} or \code{"species"}.}
   \item{rank}{The rank or the number of axes used in the approximation.
     The default is to use all axes (full rank) of the \code{"model"} or
     all available four axes in \code{predict.decorana}.}



More information about the Vegan-commits mailing list