[R] using optimize() correctly ...

Berend Hasselman bhh at xs4all.nl
Sun May 24 15:27:35 CEST 2009

On 24-05-2009, at 14:24, Esmail wrote:

> Hello Berend,
> Berend Hasselman wrote:
>> Your function is not unimodal.
>> The help for optimize states: "If f is not unimodal, then  
>> optimize() may approximate a local, but perhaps
>> non-global, minimum to the same accuracy."
> Ah ok, I didn't read the manual page carefully enough.
> Do you know if R has a function to find the global maximum/minimum  
> of a
> function of x over a given interval?
If you do

  resopt <- optim(-5,f, method="SANN",control=list(fnscale=-1))

you will get the global maximum. SANN: simulated annealing. But  
starting in -4 takes you to the local maximum.

But the help for optim recommends optimize for one-dimensional  

As far as I know there is no general foolproof method for finding a  
global optimum except trying different initial points.
No method can really replace one's own knowledge about a function.


btw. i am away during this week so i won't be replying.

More information about the R-help mailing list