[R] NLS error
bbolker at gmail.com
Wed Sep 21 01:30:43 CEST 2011
Diviya Smith <diviya.smith <at> gmail.com> writes:
> I dont think *r* is related to the problem. I am not trying to
> estimate *r* and
> so basically I am giving the model the correct value of *r* and so log(1-r)
> should not go to infinity.
> For test data, I generate data from the same model and add noise (using *r
> norm*), with the following parameters -
> A <- 20
> > B <- 500
> > r <- 0.6881
> > d <- (1:1000)/1000
[snip snip snip snip]
The quick and dirty way to deal with this would be to wrap your
nls() attempts in try() (see ?try), and throw away any cases where
things went wrong.
That of course avoids the problem rather than resolving it, which
you might not want to do.
The way through this if you do need to know exactly what's going on
is to either set.seed() in a systematic way or save the data each time
before you try to run nls() so that you can recover a data set where
nls() fails. Then instrument your functions, or use any tracing options
in nls(), to figure out at exactly what point the derivative gives
a non-finite value, and then why -- and then you may be able to figure
out how to fix or work around the problem. It is probably, as Jean
suggested, some sort of underflow/overflow problem.
More information about the R-help