[R] controlling nls errors

Douglas Bates bates at stat.wisc.edu
Thu Feb 19 23:24:06 CET 2004


"Bill Shipley" <bill.shipley at usherbrooke.ca> writes:

> Hello.  I am using the nonlinear least squares function (nls).  The
> function that I am trying to fit seems to be very sensitive to the
> starting values and, if these are not chosen properly, the nls function
> stops and gives an error message:
> 
>  
> 
> Error in numericDeriv(form[[3]], names(ind), env) : 
> 
>         Missing value or an Infinity produced when evaluating the model
> 
> In addition: Warning message: 
> 
> NaNs produced in: sqrt((quantum.yeild * I + Amax)^2 - 4 * theta *
> quantum.yeild *  
> 
>  
> 
> I want to embed the nls function within a loop so that if it gives an
> error message I can automatically adjust the starting value and retry.
> To do this I have to be able to test if the function has converged
> within the loop.  I need something like an if.error(fit) function that
> will return true if there has been an error.  Does such a thing exist?

Recently this issue was discussed on this list - specifically related
to using try() to wrap the call the nls.  The nlsList function in
package nlme does exactly this.

BTW, if I were Google I would ask something like "did you mean to
search for Quantum.yield?"




More information about the R-help mailing list