Skip to content
Prev 25783 / 63424 Next

Optimization in R

On 04/08/2007 10:30 AM, Andrew Clausen wrote:
No there isn't, but I don't really see it as necessary.  The R optim() 
function is reasonably short, mainly setting up defaults specific to 
each of the supported optimization methods.  The C do_optim() function 
has a bit more code common to the methods, but still only about 50 
lines. You could copy this common part into your own function following 
the same argument and return value conventions and a user would just 
need to change the function name in addition to specifying your method, 
not really that much harder.  (You could call your function optim and 
use it as a wrapper for stats::optim if you wanted to avoid even this, 
but I wouldn't recommend it, since then behaviour would depend on the 
search list ordering.)

There's a small risk that the argument list to optim() will change 
incompatibly sometime in the future, but I think that's unlikely.
If you return more than optim() returns it shouldn't have any serious 
ill effects.
I'd suggest always returning it if it's useful and the calculation is 
reliable and cheap.  Adding "inv.hessian" as a general parameter would 
be troublesome with some of the other methods, where the inverse Hessian 
isn't already calculated, because of the inversion problem you mention 
above.

Duncan Murdoch