?try
This will catch the error and let you take alternative action.
On 9/21/07, Dan Rabosky <dlr32 at cornell.edu>
wrote:>
> Hello -
>
> I am having a problem with the function 'integrate'. I am running
R
> on OSX (R 2.5.1).
>
> I am trying to suppress the error message when 'integrate' attempts
> to integrate across a parameter set giving a non-finite function
> value. I'm using it in a MCMC / simulated annealing algorithm, and
> it is entirely possible that some parameter sets will give non-
> integrable functions. I thought that the argument
>
> stop.on.error = FALSE
>
> would cause the function to return NA or at least not return an error
> (I can work around the situation where integrate returns garbage, but
> if it generates an error, it terminates my chain and all appears lost).
>
> This may not be necessary, but here is a simplification of an
> instance that generates the error. If you send any B > 500 to
> "questionableFunction", the integration fails and returns an
error
> message - even with stop.on.error = FALSE. Is there any way I can
> work around this? Perhaps there is something similar to
> "suppressWarnings()" that I might be able to use?
>
> questionableFunction <- function(B = 10)
> {
> fx4 <- function(B, y, z){
> 1 + exp(B*y - B*z);
> }
>
> fx1 <- function(x, r0 = 0.12, k=-0.10, a=0.5, tshift=8.36){
> (r0*exp(r0*t0 + (k/B)*log(fx4(B, t0, tshift)) - r0*x -
(k/B)*log(fx4
> (B, x, tshift))))
> }
>
> integrate(fx1, 8.36, 10, stop.on.error = FALSE);
> }
>
>
>
> Thanks in advance for your help...
>
> Dan Rabosky
> Department of Ecology and Evolutionary Biology &
> Fuller Evolutionary Biology Program
> Cornell Lab of Ornithology
> Cornell University
> Ithaca, NY 14853-2701
>
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem you are trying to solve?