[R] nlsrob fails with puzzling error message on input accepted by nls

Oren Cheyette ocheyett at bonddesk.com
Tue Dec 23 00:57:44 CET 2008


I have a nonlinear model estimation problem with ~50,000 data records
and a simple 3 parameter model (logistic type - please don't tell me
that there are linear methods for such a problem).  I run nls with
constraints once to get a good initial parameter guess, then try to run
nlrob to get improved estimates. The model is well-behaved for the
parameters that come from nls - no huge values, NAs or infinities for
the values of the independent variables.  But nlrob fails immediately
(on the first pass) with the error message

>  pxe2 <- nlrob(dpx ~ peFnc(tradeSide, tradeSz, tcScale, szScale,
alpha), data=fitData, start= pxe$m$getAllPars(), trace=TRUE);
robust iteration 1 
2138.747 :  2.19 2.31 0.45 
Error in numericDeriv(form[[3]], names(ind), env) :
<--------------------
  Missing value or an infinity produced when evaluating the model
<-------------------

With debug(), I've traced the problem to the call to nls() inside nlrob.
For reasons I haven't been able to track down, when called outside nlrob
(with algorithm='port') it runs fine. But I get the error in nlrob, even
if I include algorithm='port' in the call. 

Given the size of this problem, it's extremely difficult to identify the
inputs that are causing the failure. However, a fairly simple tweak to
the error reporting would simplify the task hugely. The error message is
coming (I think) from nls.c, at line 318: 
    for(i = 0; i < LENGTH(ans); i++) {
	if (!R_FINITE(REAL(ans)[i]))
	    error(_("Missing value or an infinity produced when
evaluating the model"));	/* <---------- */
    }

Would it be possible to add reporting of the record causing the problem,
e.g., by modifying the error line to
    error(_("Missing value or an infinity produced when evaluating the
model at record %d"), i); 
(I'm not a maintainer of the package and have been using the precompiled
binaries, so I'm hesitant to try to do this myself...)

Alternatively, does anyone have a suggestion as to how to identify the
source of the trouble? 

R-Version: 2.7.2.
Platform: i386 (WinXP)

Thanks.
Oren Cheyette



More information about the R-help mailing list