Dear Prof. Ripley,

thank you very much for the fast response. I am very grateful for all the work that the R Core does and so I try to contribute my humble part as a tester.

Prof Brian Ripley wrote:
On Wed, 3 Dec 2008, Thomas Petzoldt wrote:

Dear R developers,

I tried to use nlminb instead of optim for a current problem (fitting parameters of a differential equation model). The PORT algorithm converged much better than any of optim's methods and the identified parameters are plausible. However, it took me a while before spotting the reason of a technical problem that nlminb, in contrast to optim, does not pass names of the start parameters to the objective function.

Please find below a minimum reproducible example. There is, of course, a workaround, but in order to make optim and nlme more compatible I would ask whether it would be possible to change this idiosyncratic behavior?

The 'idiosyncratic behavior' is to expect that a new vector of parameters will magically inherit names from the start vector. optim() was changed (and documented) because some users asked for this, and if a user who wants it for nlminb provides a tested patch, I am sure it will be considered.

O.K., than I will make my, surely naive, suggestion to change file:

src/library/stats/R/nlminb.R

As far I can oversee it, names are dropped at the beginning in:

 ## Establish the working vectors and check and set options
    n <- length(par <- as.double(start))

so it may be sufficient to add something like:

    names(par) <- names(start)

anywhere before:

   assign(".par", par, envir = rho)

This change was sufficient to make my example working and (at a first look) I did not find negative side-effects. At least:

R CMD check stats

passed without problems. I had also a look into port.c and found nothing obvious there so I, again naively, assume that there is (hopefully) nothing to do at the C level. It would be very kind if someone more experienced can validate (or falsify) this.

Thank you very much

Thomas Petzoldt



Index: nlminb.R
===================================================================
--- nlminb.R    (revision 47039)
+++ nlminb.R    (working copy)
@@ -48,6 +48,7 @@
     ## Establish the objective function and its environment
     obj <- quote(objective(.par, ...))
     rho <- new.env(parent = environment())
+    names(par) <- names(start)
     assign(".par", par, envir = rho)

     ## Create values of other arguments if needed

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to