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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Feb 9 16:44:55 CET 2010


Author: jarioksa
Date: 2010-02-09 16:44:55 +0100 (Tue, 09 Feb 2010)
New Revision: 1118

Modified:
   pkg/vegan/DESCRIPTION
   pkg/vegan/R/predict.cca.R
   pkg/vegan/R/predict.rda.R
   pkg/vegan/inst/ChangeLog
Log:
predict.cca/rda match 'newdata' by row/column names

Modified: pkg/vegan/DESCRIPTION
===================================================================
--- pkg/vegan/DESCRIPTION	2010-01-12 13:16:19 UTC (rev 1117)
+++ pkg/vegan/DESCRIPTION	2010-02-09 15:44:55 UTC (rev 1118)
@@ -1,7 +1,7 @@
 Package: vegan
 Title: Community Ecology Package
-Version: 1.18-0
-Date: January 2, 2010
+Version: 1.18-1
+Date: February 9, 2010
 Author: Jari Oksanen, F. Guillaume Blanchet, Roeland Kindt, Pierre Legendre, 
    R. G. O'Hara, Gavin L. Simpson, Peter Solymos, M. Henry H. Stevens, 
    Helene Wagner  

Modified: pkg/vegan/R/predict.cca.R
===================================================================
--- pkg/vegan/R/predict.cca.R	2010-01-12 13:16:19 UTC (rev 1117)
+++ pkg/vegan/R/predict.cca.R	2010-02-09 15:44:55 UTC (rev 1118)
@@ -59,10 +59,17 @@
         if (!missing(newdata)) {
             if (!is.null(object$pCCA)) 
                 stop("No 'wa' scores available (yet) in partial CCA")
+            nm <- rownames(v)
+            if (!is.null(nm)) { # Got rownames: keep only species with scores
+                if (!all(nm %in% colnames(newdata)))
+                    stop("'newdata' does not have named columns matching one or more the original columns")
+                newdata <-  newdata[, nm, drop = FALSE]
+            } else { #Rownames are NULL: still try to remove exclude.spec
+                exclude.spec <- attr(object[[model]]$v, "na.action")
+                if (!is.null(exclude.spec)) 
+                    Xbar <- Xbar[, -exclude.spec]
+            }
             Xbar <- as.matrix(newdata)
-            exclude.spec <- attr(object[[model]]$v, "na.action")
-            if (!is.null(exclude.spec)) 
-                Xbar <- Xbar[, -exclude.spec]
             rs <- rowSums(Xbar)
             Xbar <- (Xbar - outer(rs, cs))/sqrt(outer(rs, cs))
             v <- sweep(v, 1, sqrt(cs), "*")
@@ -81,6 +88,12 @@
     }
     else if (type == "sp") {
         if (!missing(newdata)) {
+            nm <- rownames(u)
+            if (!is.null(nm)) {
+                if (!all(nm %in% rownames(newdata)))
+                    stop("'newdata' does not have named rows matching one or more of the original rows")
+                newdata <- newdata[nm, , drop = FALSE]
+            }
             Xbar <- as.matrix(newdata)
             cs <- colSums(Xbar)
             Xbar <- (Xbar - outer(rs, cs))/sqrt(outer(rs, cs))

Modified: pkg/vegan/R/predict.rda.R
===================================================================
--- pkg/vegan/R/predict.rda.R	2010-01-12 13:16:19 UTC (rev 1117)
+++ pkg/vegan/R/predict.rda.R	2010-02-09 15:44:55 UTC (rev 1118)
@@ -73,6 +73,12 @@
                 stop("'wa' scores not available in capscale with 'newdata'")
             if (!is.null(object$pCCA)) 
                 stop("No 'wa' scores available (yet) in partial RDA")
+            nm <- rownames(v)
+            if (!is.null(nm)) {
+                if (!all(nm %in% colnames(newdata)))
+                    stop("'newdata' does not have named columns matching one or more the original columns")
+                newdata <-  newdata[, nm, drop = FALSE]
+            }
             Xbar <- as.matrix(newdata)
             Xbar <- sweep(Xbar, 2, cent, "-")
             if (!is.null(scal)) {
@@ -93,6 +99,12 @@
         if (inherits(object, "capscale")) 
             warning("'sp' scores may be meaningless in 'capscale'")
         if (!missing(newdata)) {
+            nm <- rownames(u)
+            if (!is.null(nm)) {
+                if (!all(nm %in% rownames(newdata)))
+                    stop("'newdata' does not have named rows matching one or more of the original rows")
+                newdata <- newdata[nm, , drop = FALSE]
+            }
             Xbar <- as.matrix(newdata)
             Xbar <- scale(Xbar, center = TRUE, scale = scaled.PCA)
             if (!is.null(object$pCCA)) 

Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog	2010-01-12 13:16:19 UTC (rev 1117)
+++ pkg/vegan/inst/ChangeLog	2010-02-09 15:44:55 UTC (rev 1118)
@@ -2,8 +2,14 @@
 
 VEGAN DEVEL VERSIONS at http://r-forge.r-project.org/
 
-Version 1.18-0 (opened January 2, 2010)
+Version 1.18-1 (opened February 9, 2010)
 
+	* 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.
+
+Version 1.18-0 (closeed January 11, 2010 with release 1.17-0)
+
 	* Documented na.action in cca.object.
 
 	* Opened concurrently with copying 1.16-34 (at rev 1087) to



More information about the Vegan-commits mailing list