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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Sep 1 07:50:22 CEST 2009


Author: jarioksa
Date: 2009-09-01 07:50:20 +0200 (Tue, 01 Sep 2009)
New Revision: 969

Added:
   pkg/vegan/R/ordiNAexclude.R
Modified:
   pkg/vegan/inst/ChangeLog
   pkg/vegan/man/vegan-internal.Rd
Log:
infrastructure for implementing na.action = na.exclude for constrained ordination

Added: pkg/vegan/R/ordiNAexclude.R
===================================================================
--- pkg/vegan/R/ordiNAexclude.R	                        (rev 0)
+++ pkg/vegan/R/ordiNAexclude.R	2009-09-01 05:50:20 UTC (rev 969)
@@ -0,0 +1,27 @@
+### na.action = na.exclude puts NA values to removed observations, but
+### in constrained ordination WA scores can be found for observations
+### with NA values in constraints.
+`ordiNAexclude` <-
+    function(object, newdata)
+{
+    ## Embed NA for excluded cases
+    nas <- object$na.action
+    object$rowsum <- napredict(nas, object$rowsum)
+    object$CCA$u <- napredict(nas, object$CCA$u)
+    object$CCA$u.eig <- napredict(nas, object$CCA$u.eig)
+    object$CCA$wa <- napredict(nas, object$CCA$wa)
+    object$CCA$wa.eig <- napredict(nas, object$CCA$wa.eig)
+    object$CA$u <- napredict(nas, object$CA$u)
+    object$CA$u.eig <- napredict(nas, object$CA$u.eig)
+    ## Estimate WA scores for NA cases with newdata of excluded
+    ## obseravations
+    wa <- predict(object, newdata = newdata, type = "wa", model = "CCA")
+    wa.eig <- sweep(wa, 2, sqrt(object$CCA$eig), "*")
+    object$CCA$wa[nas,] <- wa
+    object$CCA$wa.eig[nas,] <- wa.eig
+    wa <- predict(object, newdata = newdata, type = "wa", model = "CA")
+    wa.eig <- sweep(wa, 2, sqrt(object$CA$eig), "*")
+    object$CA$u[nas,] <- wa
+    object$CA$u.eig[nas,] <- wa.eig
+    object
+}

Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog	2009-08-31 19:11:30 UTC (rev 968)
+++ pkg/vegan/inst/ChangeLog	2009-09-01 05:50:20 UTC (rev 969)
@@ -12,6 +12,15 @@
 	ripley.subs() and ripley.subsets() from vegan. The result should
 	be unchanged.
 
+	* ordiNAexclude: internal infrastructure to implement na.action =
+	na.exclude for cca and rda (and capscale?). The option returns
+	scores where the excluded sites get NA results and are not
+	omitted. In constrained ordination, LC scores will NA, but WA
+	scores are found from the community data, and the current function
+	uses predict.cca/predict.rda with 'newdata' of removed
+	observations to estimate WA scores of excluded observation. The
+	calling functions won't use this yet (working...).
+	
 	* ordiParseFormula: handles missing values with na.action. The
 	calling functions (cca, rda, capscale) won't use this
 	yet (working...).

Modified: pkg/vegan/man/vegan-internal.Rd
===================================================================
--- pkg/vegan/man/vegan-internal.Rd	2009-08-31 19:11:30 UTC (rev 968)
+++ pkg/vegan/man/vegan-internal.Rd	2009-09-01 05:50:20 UTC (rev 969)
@@ -1,6 +1,7 @@
 \name{vegan-internal}
 \alias{ordiGetData}
 \alias{ordiParseFormula}
+\alias{ordiNAexclude}
 \alias{permuted.index}
 \alias{centroids.cca}
 \alias{ordiTerminfo}
@@ -17,6 +18,7 @@
 ordiGetData(call, env)
 ordiParseFormula(formula, data, xlev = NULL, envdepth = 2, na.action = na.fail)
 ordiTerminfo(d, data)
+ordiNAexclude(object, newdata)
 ordiArrowMul(x, at = c(0,0), fill = 0.75)
 ordiArgAbsorber(..., shrink, origin, scaling, triangular,
                 display, choices, const, FUN)
@@ -30,19 +32,23 @@
   these functions are not intended for users, but they only should be
   used within functions
   
-  \code{ordiGetData} finds the model frame of constraints and conditions
-  in constrained ordination in the defined \code{env}ironment.
-  \code{ordiParseFormula} returns a list of three matrices (dependent
-  variables, and \code{\link{model.matrix}} of constraints and
-  conditions, possibly \code{NULL}) needed in constrained
-  ordination. Argument \code{xlev} is passed to
+  \code{ordiGetData} finds the model frame of constraints and
+  conditions in constrained ordination in the defined
+  \code{env}ironment.  \code{ordiParseFormula} returns a list of three
+  matrices (dependent variables, and \code{\link{model.matrix}} of
+  constraints and conditions, possibly \code{NULL}) needed in
+  constrained ordination. Argument \code{xlev} is passed to
   \code{\link{model.frame}} and argument \code{envdepth} specifies the
   depth at which the community data (dependent data) are evaluated;
   default \code{envdepth = 2} evaluates that in the environment of the
   parent of the calling function, and \code{envdepth = 1} within the
-  calling function (see \code{\link{eval.parent}}). \code{ordiTermInfo}
-  finds the term information for constrained ordination as described in
-  \code{\link{cca.object}}.
+  calling function (see
+  \code{\link{eval.parent}}). \code{ordiTermInfo} finds the term
+  information for constrained ordination as described in
+  \code{\link{cca.object}}. \code{ordiNAexclude} implements
+  \code{na.action = na.exclude} for constrained ordination finding WA
+  scores of CCA components and site scores of unconstrained component
+  from \code{newdata} of excluded observations.
 
   \code{ordiArgAbsorber} absorbs arguments of \code{\link{scores}}
   function of \pkg{vegan} so that these do not cause superfluous



More information about the Vegan-commits mailing list