[Rd] nls.control(warnOnly = TRUE) gives error rather than warning

Gabor Grothendieck ggrothendieck at gmail.com
Sun Aug 22 13:30:51 CEST 2010


In ?nls.control it says:

warnOnly a logical specifying whether nls() should return instead of
signalling an error in the case of termination before convergence.
Termination before convergence happens upon completion of maxiter
iterations, in the case of a singular gradient, and in the case that
the step-size factor is reduced below minFactor.

however,

1. here we have a singular gradient but it gave an error rather than
the expected behavior of returning:

> set.seed(1)
> y <- exp(x) + rnorm(10)
>
> nls(y ~ a * exp(b * x), start = c(a = 0, b = 0),
+ control = nls.control(warnOnly = TRUE))
Error in nlsModel(formula, mf, start, wts) :
  singular gradient matrix at initial parameter estimates

2. and here we have a failure in numericDeriv and although that is not
documented as one of the conditions I think it would be desirable that
it be included as something that does not result in an error when
warnOnly = TRUE:

> nls(y ~ a * exp(b * x), start = c(a = 10, b = 0),
+ control = nls.control(warnOnly = TRUE))
Error in numericDeriv(form[[3L]], names(ind), env) :
  Missing value or an infinity produced when evaluating the model



More information about the R-devel mailing list