Bug 14427 - function nls does not return ("hangs")
Summary: function nls does not return ("hangs")
Alias: None
Product: R
Classification: Unclassified
Component: Analyses (show other bugs)
Version: R 2.12.0
Hardware: ix86 (32-bit) Windows 32-bit
: P5 major
Assignee: R-core
Depends on:
Reported: 2010-10-29 15:44 UTC by RoelandV
Modified: 2010-11-03 12:46 UTC (History)
0 users

See Also:

zip file with script and data to reproduce bug (16.74 KB, application/zip)
2010-10-29 15:44 UTC, RoelandV

Note You need to log in before you can comment on or make changes to this bug.
Description RoelandV 2010-10-29 15:44:57 UTC
Created attachment 1139 [details]
zip file with script and data to reproduce bug

In version 2.12.0, function nls (stats package, nonlinear least squares) sometimes fails to return; the R gui then does not respond any more.

This did not occur in versions 2.9.1 and 2.9.2. It occurs infrequently (I spotted 3 cases in 1600 different nls calls) but reproducibly. 
In almost all cases when nls returns, the values are somewhat different from those in the earlier versions (at 7th decimal or smaller). 

The enclosed script shows a case using algorithm="port", but the same problem also occurs (with other data) with the default Gauss-Newton algorithm
Comment 1 Brian Ripley 2010-10-30 22:43:49 UTC
This is highly platform-specific: I presume that 32-bit R is meant, 
but we were not told.  It works on x86_64 Linux, x64 Windows, i386 Mac OS X,
but they all give different iteration paths (set trace=TRUE to see).

As far as I can tell the starting values are poor and the problem is
not well-conditioned.  Numerical instability with such data is a fact
of life, and unless this can be reproduced on a platform more amenable
to Fortran debugging we will not be spending more time on it.

For the record, the most likely change since the long-obsolete R 2.9.x is in
the compiler used: but you could try 2.11.1 to verify this.
Comment 2 Brian Ripley 2010-10-31 08:59:59 UTC
However, a hunch that this is due to incorrect assumptions about
computer arithmetic in portsrc.f that would be circumvented by 
-ffloat-store seems to have been inspired.  The flags have been changed
in 2.12.0 patched.
Comment 3 RoelandV 2010-11-03 12:46:56 UTC

I tested the fix in R version 2.12.0 Patched (2010-11-01 r53509),
with 250000 calls to nls (60% the Gauss-Newton algorithm, 40% the port algorithm) including the 3 cases where the problem was noted. Everything works fine now - thanks a lot!

And yes, I (have to) work with the Windows 32-bit version

Regards, Roeland