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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Sep 19 15:06:35 CEST 2012


Author: jarioksa
Date: 2012-09-19 15:06:35 +0200 (Wed, 19 Sep 2012)
New Revision: 2292

Modified:
   pkg/vegan/R/predict.radline.R
   pkg/vegan/inst/ChangeLog
Log:
predict.radfit gained argument to set the 'total' community size

Modified: pkg/vegan/R/predict.radline.R
===================================================================
--- pkg/vegan/R/predict.radline.R	2012-09-18 18:49:44 UTC (rev 2291)
+++ pkg/vegan/R/predict.radline.R	2012-09-19 13:06:35 UTC (rev 2292)
@@ -5,47 +5,49 @@
 ### the extrapolations may be NaN.
 
 `predict.radline`  <-
-    function(object, newdata, ...)
+    function(object, newdata, total, ...)
 {
+    ## newdata can be ranks
     if (missing(newdata))
         x <- seq_along(object$y)
     else
         x <- drop(as.matrix(newdata))
+    ## total number of individuals in the community
+    if (missing(total))
+        total <- sum(object$y)
+    ## adjustment for chagned total in call
+    adj <- total/sum(object$y)
     nobs <- length(object$y)
     p <- coef(object)
-    switch(object$model,
-           ## linear interpolation, no extrapolation
-           `Brokenstick` = approx(seq_len(nobs), object$fitted.values, x, ...)$y,
-           `Preemption` = exp(log(sum(object$y)) + log(p) + log(1 - p)*(x-1)),
-           ## NaN when rank outside proportional rank 0...1 
-           `Log-Normal` = {
-               slope <- diff(range(ppoints(nobs)))/(nobs-1)
-               intcpt <- 0.5 - slope * (nobs + 1) / 2
-               xnorm <- -qnorm(intcpt + slope * x)
-               exp(p[1] + p[2]*xnorm)
-           },
-           `Zipf` = exp(log(sum(object$y)) + log(p[1]) + p[2]*log(x)),
-           `Zipf-Mandelbrot` = exp(log(sum(object$y)) + log(p[1]) +
-           p[2]*log(x + p[3]))
-           )
+    out <-
+        switch(object$model,
+               ## linear interpolation, no extrapolation
+               `Brokenstick` = approx(seq_len(nobs),
+               object$fitted.values, x, ...)$y * adj,
+               `Preemption` = exp(log(total) + log(p) + log(1 - p)*(x-1)),
+               ## NaN when rank outside proportional rank 0...1 
+               `Log-Normal` = {
+                   slope <- diff(range(ppoints(nobs)))/(nobs-1)
+                   intcpt <- 0.5 - slope * (nobs + 1) / 2
+                   xnorm <- -qnorm(intcpt + slope * x)
+                   exp(p[1] + p[2]*xnorm)*adj
+               },
+               `Zipf` = exp(log(total) + log(p[1]) + p[2]*log(x)),
+               `Zipf-Mandelbrot` = exp(log(total) + log(p[1]) +
+               p[2]*log(x + p[3]))
+               )
+    names(out) <- names(object$y)
+    out
 }
 
 `predict.radfit`<-
-    function(object, newdata, ...)
+    function(object, ...)
 {
-    if (missing(newdata))
-        sapply(names(object$models), function(x, ...)
-               predict(object$models[[x]], ...))
-    else
-        sapply(names(object$models), function(x, ...)
-               predict(object$models[[x]], newdata, ...))
+    sapply(object$models, predict, ...)
 }
 
 `predict.radfit.frame`  <-
-    function(object, newdata, ...)
+    function(object, ...)
 {
-    if(missing(newdata))
-        lapply(object, predict, ...)
-    else
-        lapply(object, predict, newdata = newdata)
+    lapply(object, predict, ...)
 }

Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog	2012-09-18 18:49:44 UTC (rev 2291)
+++ pkg/vegan/inst/ChangeLog	2012-09-19 13:06:35 UTC (rev 2292)
@@ -17,7 +17,8 @@
 	and this gives an error message "object is not a matrix".
 
 	* radfit: added fitted() method for radfit.frame objects similar
-	to predict.
+	to predict. The predict() method gained new argument to change the
+	expected 'total' size of communities.
 	
 Version 2.1-19 (closed September 16, 2012)
 



More information about the Vegan-commits mailing list