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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Nov 16 12:24:28 CET 2010


Author: jarioksa
Date: 2010-11-16 12:24:27 +0100 (Tue, 16 Nov 2010)
New Revision: 1372

Modified:
   pkg/vegan/R/fitted.procrustes.R
   pkg/vegan/R/procrustes.R
   pkg/vegan/inst/ChangeLog
   pkg/vegan/man/procrustes.Rd
Log:
fix translation in fitted.procrustes and add predict

Modified: pkg/vegan/R/fitted.procrustes.R
===================================================================
--- pkg/vegan/R/fitted.procrustes.R	2010-11-15 17:22:39 UTC (rev 1371)
+++ pkg/vegan/R/fitted.procrustes.R	2010-11-16 11:24:27 UTC (rev 1372)
@@ -1,8 +1,24 @@
-"fitted.procrustes" <-
+`fitted.procrustes` <-
   function(object, truemean = TRUE, ...)
 {
   fit <- object$Yrot
   if (truemean)
-    fit <- sweep(fit, 2, object$translation, "+")
+    fit <- sweep(fit, 2, object$xmean, "+")
   fit
 }
+
+## Like above, except when takes 'newata'
+
+`predict.procrustes` <-
+    function(object, newdata, truemean = TRUE, ...)
+{
+    if (missing(newdata))
+        return(fitted(object, truemean = truemean))
+    Y <- as.matrix(newdata)
+    ## scaling and rotation
+    Y <- object$scale * Y %*% object$rotation
+    ## translation
+    if (truemean)
+        Y <- sweep(Y, 2, object$translation, "+")
+    Y
+}

Modified: pkg/vegan/R/procrustes.R
===================================================================
--- pkg/vegan/R/procrustes.R	2010-11-15 17:22:39 UTC (rev 1371)
+++ pkg/vegan/R/procrustes.R	2010-11-16 11:24:27 UTC (rev 1372)
@@ -34,8 +34,8 @@
     b <- xmean - c * ymean %*% A
     R2 <- ctrace(X) + c * c * ctrace(Y) - 2 * c * sum(sol$d)
     reslt <- list(Yrot = Yrot, X = X, ss = R2, rotation = A, 
-                  translation = b, scale = c, symmetric = symmetric,
-                  call = match.call())
+                  translation = b, scale = c, xmean = xmean, 
+                  symmetric = symmetric, call = match.call())
     reslt$svd <- sol
     class(reslt) <- "procrustes"
     return(reslt)

Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog	2010-11-15 17:22:39 UTC (rev 1371)
+++ pkg/vegan/inst/ChangeLog	2010-11-16 11:24:27 UTC (rev 1372)
@@ -4,6 +4,10 @@
 
 Version 1.18-16 (opened November 9, 2010)
 
+	* procrustes: fixed centring of fitted(). Added predict() method
+	that can be used to add new rotated coordinates to the
+	target. Need to check working with 'symmetric = TRUE'.
+
 	* vignette on design decision: updated to changes in 'const' in
 	scores.rda()  in 1.18-15 and to Canoco 4. Explains now 'const'
 	more thoroughly.

Modified: pkg/vegan/man/procrustes.Rd
===================================================================
--- pkg/vegan/man/procrustes.Rd	2010-11-15 17:22:39 UTC (rev 1371)
+++ pkg/vegan/man/procrustes.Rd	2010-11-16 11:24:27 UTC (rev 1372)
@@ -9,6 +9,7 @@
 \alias{lines.procrustes}
 \alias{residuals.procrustes}
 \alias{fitted.procrustes}
+\alias{predict.procrustes}
 \alias{protest}
 \alias{print.protest}
 
@@ -28,6 +29,7 @@
 \method{lines}{procrustes}(x, type = c("segments", "arrows"), choices = c(1, 2), ...)  
 \method{residuals}{procrustes}(object, ...)
 \method{fitted}{procrustes}(object, truemean = TRUE, ...)
+\method{predict}{procrustes}(object, newdata, truemean = TRUE, ...)
 protest(X, Y, scores = "sites", permutations = 999, strata, ...)
 }
 
@@ -56,6 +58,8 @@
     segments or arrows.}
   \item{truemean}{Use the original range of target matrix instead of
     centring the fitted values.}
+  \item{newdata}{Matrix of coordinates to be rotated (and translated if
+    \code{truemean = TRUE}) to the target.}
   \item{permutations}{Number of permutation to assess the significance
     of the symmetric Procrustes statistic. }
   \item{strata}{An integer vector or factor specifying the strata for
@@ -119,7 +123,9 @@
   \code{Y}, then matrix \code{X} will be filled with zero columns to
   match dimensions. This means that the function can be used to rotate
   an ordination configuration to an environmental variable (most
-  practically extracting the result with the \code{fitted} function).
+  practically extracting the result with the \code{fitted}
+  function). Function \code{predict} can be usd to add new rotated
+  coordinates to the target. 
 
   Function \code{protest} calls \code{procrustes(..., symmetric = TRUE)}
   repeatedly to estimate the `significance' of the Procrustes
@@ -141,6 +147,7 @@
   \item{rotation}{Orthogonal rotation matrix.}
   \item{translation}{Translation of the origin.}
   \item{scale}{Scaling factor.}
+  \item{xmean}{The centroid of the target.}
   \item{symmetric}{Type of \code{ss} statistic.}
   \item{call}{Function call.}
   \item{t0}{This and the following items are only in class



More information about the Vegan-commits mailing list