On Fri, Oct 01, 2021 at 03:45:48PM +0200, Martin Maechler wrote: > Is there anything special (system libraries, compilers, ..) > on your platform?
No. As far as I know this is an ordinary SuperMicro x86-64 server, nothing strange or unusual. /proc/cpuinfo says "Intel(R) Xeon(R) CPU E5-2670 0 @ 2.60GHz". > o2 <- options(digits = 10) # more accuracy for 'trace' > ## central differencing works here typically (PR#18165: not converging on > *some*): > ctr2 <- nls.control(nDcentral=TRUE, tol = 8e-8, # <- even smaller than above > warnOnly = (grepl("^aarch64.*linux", R.version$platform) && > grepl("^NixOS", osVersion) > )) > (nlm2 <- update(nlmod, control = ctr2, trace = TRUE)); options(o2) > > ... now would that run w/o error on your Ubuntu-installed R ? Interactively, the code above runs fine. In fact, the original code ALSO seems to run fine, no errors at all! See output below. I get the error when running the tests via either "make check" or tools::testInstalledPackages(scope="base"), but outside of that testing framework it runs fine. Ah, interactively, if I ALSO run the code for the immediately prior test in stats-Ex.R, THEN the nlm2 code fails the same way as with "make check". That prior test does set.seed(27), which seems to trigger the downstream failures. Simply skipping the set.seed(27) (interactively) makes the failure go away for me. But if the set.seed(27) is necessary, maybe the second test should be doing its own set.seed() of some sort? I don't know how/where to comment out that set.seed(27) to try running tests without it. Editing "src/library/stats/man/nls.Rd" and re-running "make check" still does the set.seed(27). Just run code from the single failing test, it works fine: ------------------------------------------------------------ ## R --vanilla R version 4.1.1 Patched (2021-09-21 r80946) -- "Kick Things" Copyright (C) 2021 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu/x86_64 (64-bit) > Sys.setenv(LC_COLLATE = "C", LC_TIME = "C", LANGUAGE = "en") > options(digits = 10) > x <- -(1:100)/10 > y <- 100 + 10 * exp(x / 2) + rnorm(x)/10 > nlmod <- nls(y ~ Const + A * exp(B * x)) Warning message: In nls(y ~ Const + A * exp(B * x)) : No starting values specified for some parameters. Initializing 'Const', 'A', 'B' to '1.'. Consider specifying 'start' or using a selfStart model > nlm1 <- update(nlmod, control = list(tol = 1e-7)) Warning message: In nls(formula = y ~ Const + A * exp(B * x), algorithm = "default", : No starting values specified for some parameters. Initializing 'Const', 'A', 'B' to '1.'. Consider specifying 'start' or using a selfStart model > nlm2 <- update(nlmod, control = list(tol = 8e-8, nDcentral=TRUE), trace=TRUE) 1017400.445 (4.11e+02): par = (1 1 1) 752239.9094 (1.96e+02): par = (13.41553998 1.959746504 0.01471383253) 668978.9926 (1.65e+02): par = (189.3774772 -162.3882591 1.397507535) 375910.4745 (1.20e+02): par = (167.1787529 -119.9960435 1.42386803) 93230.26788 (5.49e+01): par = (133.8879258 -56.45697809 1.498055399) 382.9221937 (2.42e+00): par = (100.6364489 6.806405333 1.84811172) 138.7915397 (9.68e+00): par = (100.6763251 6.489793899 0.7564107501) 24.47843640 (5.42e+00): par = (100.4024547 8.003646622 0.4918079622) 0.8056918383 (4.49e-03): par = (99.9629562 10.01549373 0.4913706525) 0.8056755692 (4.09e-06): par = (99.96295295 10.01549135 0.4914577719) 0.8056755692 (7.83e-09): par = (99.96295344 10.01549217 0.4914579487) Warning message: In nls(formula = y ~ Const + A * exp(B * x), algorithm = "default", : No starting values specified for some parameters. Initializing 'Const', 'A', 'B' to '1.'. Consider specifying 'start' or using a selfStart model > nlm1 Nonlinear regression model model: y ~ Const + A * exp(B * x) data: parent.frame() Const A B 99.9629534 10.0154922 0.4914579 residual sum-of-squares: 0.8056756 Number of iterations to convergence: 10 Achieved convergence tolerance: 1.586349e-08 > nlm2 Nonlinear regression model model: y ~ Const + A * exp(B * x) data: parent.frame() Const A B 99.9629534 10.0154922 0.4914579 residual sum-of-squares: 0.8056756 Number of iterations to convergence: 10 Achieved convergence tolerance: 7.832984e-09 Instead run BOTH these tests, now the last one fails: ------------------------------------------------------------ ## R --vanilla R version 4.1.1 Patched (2021-09-21 r80946) -- "Kick Things" Copyright (C) 2021 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu/x86_64 (64-bit) ## The two examples below show that you can fit a model to ## artificial data with noise but not to artificial data ## without noise. > x <- 1:10 > y <- 2*x + 3 # perfect fit ## terminates in an error, because convergence cannot be confirmed: > try(nls(y ~ a + b*x, start = list(a = 0.12345, b = 0.54321))) > Error in nls(y ~ a + b * x, start = list(a = 0.12345, b = 0.54321)) : number of iterations exceeded maximum of 50 ## adjusting the convergence test by adding 'scaleOffset' to its denominator RSS: > nls(y ~ a + b*x, start = list(a = 0.12345, b = 0.54321), control = list(scaleOffset = 1, printEval=TRUE)) > + It. 1, fac= 1, eval (no.,total): ( 1, 1): new dev = > 1.05935e-12 Nonlinear regression model model: y ~ a + b * x data: parent.frame() a b 3 2 residual sum-of-squares: 1.059e-12 Number of iterations to convergence: 1 Achieved convergence tolerance: 3.639e-07 > ## Alternatively jittering the "too exact" values, slightly: set.seed(27) > yeps <- y + rnorm(length(y), sd = 0.01) # added noise > nls(yeps ~ a + b*x, start = list(a = 0.12345, b = 0.54321)) Nonlinear regression model model: yeps ~ a + b * x data: parent.frame() a b 3.001 2.000 residual sum-of-squares: 0.001346 Number of iterations to convergence: 2 Achieved convergence tolerance: 8.658e-09 > > ## the nls() internal cheap guess for starting values can be sufficient: > x <- -(1:100)/10 > y <- 100 + 10 * exp(x / 2) + rnorm(x)/10 > nlmod <- nls(y ~ Const + A * exp(B * x)) Warning message: In nls(y ~ Const + A * exp(B * x)) : No starting values specified for some parameters. Initializing 'Const', 'A', 'B' to '1.'. Consider specifying 'start' or using a selfStart model > options(digits = 10) # more accuracy for 'trace' > try(nlm1 <- update(nlmod, control = list(tol = 1e-7))) # where central diff. > work here: Warning message: In nls(formula = y ~ Const + A * exp(B * x), algorithm = "default", : No starting values specified for some parameters. Initializing 'Const', 'A', 'B' to '1.'. Consider specifying 'start' or using a selfStart model > (nlm2 <- update(nlmod, control = list(tol = 8e-8, nDcentral=TRUE), > trace=TRUE)) 1017460.306 (4.15e+02): par = (1 1 1) 758164.7503 (2.34e+02): par = (13.42031396 1.961485 0.05947543745) 269506.3538 (3.23e+02): par = (51.75719816 -13.09155957 0.8428607709) 68969.21893 (1.03e+02): par = (76.0006985 -1.935226745 1.0190858) 633.3672230 (1.29e+00): par = (100.3761515 8.624648402 5.104490259) 151.4400218 (9.39e+00): par = (100.6344391 4.913490985 0.2849209569) 53.08739850 (7.24e+00): par = (100.6830407 6.899303317 0.4637755074) 1.344478640 (5.97e-01): par = (100.0368306 9.897714142 0.5169294939) 0.9908415909 (1.55e-02): par = (100.0300625 9.9144191 0.5023516843) 0.9906046057 (1.84e-05): par = (100.0288724 9.916224018 0.5025207336) 0.9906046054 (9.95e-08): par = (100.028875 9.916228366 0.50252165) 0.9906046054 (9.93e-08): par = (100.028875 9.916228366 0.50252165) Error in nls(formula = y ~ Const + A * exp(B * x), algorithm = "default", : step factor 0.000488281 reduced below 'minFactor' of 0.000976562 In addition: Warning message: In nls(formula = y ~ Const + A * exp(B * x), algorithm = "default", : No starting values specified for some parameters. Initializing 'Const', 'A', 'B' to '1.'. Consider specifying 'start' or using a selfStart model ------------------------------------------------------------ -- Andrew Piskorski <a...@piskorski.com> ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel