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?
Bill Shipley
Associate Editor, Ecology
North American Editor, Annals of Botany
Département de biologie, Université de Sherbrooke,
Sherbrooke (Québec) J1K 2R1 CANADA
Bill.Shipley@USherbrooke.ca
<http://callisto.si.usherb.ca:8080/bshipley/>
http://callisto.si.usherb.ca:8080/bshipley/
[[alternative HTML version deleted]]
"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?"