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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Aug 24 07:06:27 CEST 2011


Author: jarioksa
Date: 2011-08-24 07:06:26 +0200 (Wed, 24 Aug 2011)
New Revision: 1747

Added:
   pkg/vegan/R/fitted.specaccum.R
   pkg/vegan/R/predict.fitspecaccum.R
Modified:
   pkg/vegan/NAMESPACE
   pkg/vegan/inst/ChangeLog
   pkg/vegan/inst/NEWS.Rd
   pkg/vegan/man/specaccum.Rd
Log:
predict methods for specaccum and fitspecaccum

Modified: pkg/vegan/NAMESPACE
===================================================================
--- pkg/vegan/NAMESPACE	2011-08-23 15:50:30 UTC (rev 1746)
+++ pkg/vegan/NAMESPACE	2011-08-24 05:06:26 UTC (rev 1747)
@@ -157,6 +157,7 @@
 S3method(fitted, procrustes)
 S3method(fitted, radfit)
 S3method(fitted, rda)
+S3method(fitted, specaccum)
 # goodness: vegan
 S3method(goodness, cca)
 S3method(goodness, metaMDS)
@@ -249,9 +250,11 @@
 # predict: stats
 S3method(predict, cca)
 S3method(predict, decorana)
+S3method(predict, fitspecaccum)
 S3method(predict, humpfit)
 S3method(predict, procrustes)
 S3method(predict, rda)
+S3method(predict, specaccum)
 # print: base
 S3method(print, CCorA)
 S3method(print, MOStest)

Added: pkg/vegan/R/fitted.specaccum.R
===================================================================
--- pkg/vegan/R/fitted.specaccum.R	                        (rev 0)
+++ pkg/vegan/R/fitted.specaccum.R	2011-08-24 05:06:26 UTC (rev 1747)
@@ -0,0 +1,25 @@
+`fitted.specaccum` <-
+    function(object, ...)
+{
+    object$richness
+}
+
+`predict.specaccum` <-
+    function(object, newdata, interpolation = c("linear", "spline"), ...)
+{
+    if (missing(newdata))
+        out <- object$richness
+    else {
+        interpolation <- match.arg(interpolation)
+        newdata <- drop(as.matrix(newdata))
+        if (length(dim(newdata)) > 1)
+            stop("function accepts only one variable as 'newdata'")
+        if (interpolation == "linear")
+            out <- approx(x = object$sites, y = object$richness,
+                          xout = newdata, rule = 1)$y
+        else
+            out <- spline(x = object$sites, y = object$richness,
+                          xout = newdata, ...)$y
+    }
+    out
+}

Added: pkg/vegan/R/predict.fitspecaccum.R
===================================================================
--- pkg/vegan/R/predict.fitspecaccum.R	                        (rev 0)
+++ pkg/vegan/R/predict.fitspecaccum.R	2011-08-24 05:06:26 UTC (rev 1747)
@@ -0,0 +1,13 @@
+`predict.fitspecaccum` <-
+    function(object, newdata, ...)
+{
+    mods <- object$models
+    if (!missing(newdata)) {
+        newdata <- drop(as.matrix(newdata))
+        if (length(dim(newdata)) > 1)
+            stop("function accepts only one variable as 'newdata'")
+        drop(sapply(mods, predict, newdata = data.frame(x = newdata), ...))
+    } else {
+        drop(sapply(mods, predict, ...))
+    }
+}

Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog	2011-08-23 15:50:30 UTC (rev 1746)
+++ pkg/vegan/inst/ChangeLog	2011-08-24 05:06:26 UTC (rev 1747)
@@ -4,6 +4,14 @@
 
 Version 1.92-1 (opened August 23, 2011)
 
+	* specaccum, fitspecaccum: fitted() and predict() methods for
+	specaccum. The fitted() method returns the fitted richness, and
+	predict(..., newdata) can select items from richness with integer
+	'newdata'. For fitspecaccum(), the predict() is performed to each
+	fitted model, allowing non-interger values. There is no special
+	fitted() models, but fitspecaccum() is written so that default
+	fitted(), residuals() and coef() work.  
+
 	* NAMESPACE: imports nobs from permute_0.5-3 in R 2.12.2 and older
 	which do not yet have nobs() generic.
 

Modified: pkg/vegan/inst/NEWS.Rd
===================================================================
--- pkg/vegan/inst/NEWS.Rd	2011-08-23 15:50:30 UTC (rev 1746)
+++ pkg/vegan/inst/NEWS.Rd	2011-08-24 05:06:26 UTC (rev 1747)
@@ -50,7 +50,8 @@
       in \pkg{vegan} or other self-starting non-linear regression
       models in \R. The functin can fit Arrhenius, Gleason, Gitay,
       Lomolino (in \pkg{vegan}), asymptotic, Gompertz,
-      Michaelis-Menten, logistic and Weibull (in base \R) models.
+      Michaelis-Menten, logistic and Weibull (in base \R) models. The
+      function has \code{plot} and \code{predict} methods.
       
       \item Self-starting non-linear species accumulation models
       \code{SSarrhenius}, \code{SSgleason}, \code{SSgitay} and
@@ -76,6 +77,10 @@
       with \code{isoMDS} because it cannot handle adequately these tied
       maximum dissimilarities. 
       
+      \item \code{specaccum} gained \code{predict} method which uses
+      either linear or spline interpolation. Extrapolation is possible
+      with spline interpolation, but may make little sense.
+
     }
   } % end NEW FEATURES
   

Modified: pkg/vegan/man/specaccum.Rd
===================================================================
--- pkg/vegan/man/specaccum.Rd	2011-08-23 15:50:30 UTC (rev 1746)
+++ pkg/vegan/man/specaccum.Rd	2011-08-24 05:06:26 UTC (rev 1747)
@@ -23,6 +23,9 @@
 fitspecaccum(object, model, method = "random", ...)
 \method{plot}{fitspecaccum}(x, col = par("fg"), lty = 1, xlab = "Sites", 
     ylab = x$method, ...) 
+\method{fitted}{specaccum}(object, ...)
+\method{predict}{specaccum}(object, newdata, interpolation = c("linear", "spline"), ...)
+\method{predict}{fitspecaccum}(object, newdata, ...)
 }
 
 \arguments{
@@ -63,6 +66,13 @@
   \item{object}{Either a community data set or fitted \code{specaccum} model.}
   \item{model}{Nonlinear regression model (\code{\link{nls}}). See Details.}
   \item{lty}{line type code (see \code{\link{par}}.}
+  
+  \item{newdata}{Optional data used in prediction interpreted as
+    number of sampling units (sites). If missing, fitted values are
+    returned. }
+  
+  \item{interpolation}{Interpolation method used with \code{newdata}.}
+
   \item{...}{Other parameters to functions.}
 }
 \details{
@@ -91,8 +101,16 @@
   corresponding to average number of individuals per site.
 
   The function has a \code{plot} method. In addition, \code{method =
-    "random"} has \code{summary} and \code{boxplot} methods. 
+  "random"} has \code{summary} and \code{boxplot} methods. 
 
+  Function \code{fitted} returns the fitted values, and \code{predict}
+  can return the values corresponding to \code{newdata} using linear
+  (function \code{\link{approx}}) or spline (function
+  \code{\link{spline}}) interpolation. The function cannot extrapolate
+  with linear interpolation, and with spline the type and sensibility
+  of the extrapolation depends on argument \code{method} which can be
+  given and is passed to \code{\link{spline}}.
+
   Function \code{fitspecaccum} fits a nonlinear (\code{\link{nls}})
   self-starting species accumulation model. The input \code{object}
   can be a result of \code{specaccum} or a community in data frame. In
@@ -111,6 +129,11 @@
   \code{"weibull"} (\code{\link{SSweibull}}). See these functions for
   model specification and details.
 
+  Function \code{predict} uses \code{\link{predict.nls}}, and you can
+  pass all arguments to that function. In addition, \R default methods
+  \code{fitted}, \code{residuals} and \code{coef} work on the result
+  object.
+
   Nonlinear regression may fail for any reason, and some of the
   \code{fitspecaccum} models are fragile and may not succeed.  
 }



More information about the Vegan-commits mailing list