[R] optim()

Mike Lonergan mel at mcs.st-and.ac.uk
Wed Apr 3 19:33:02 CEST 2002

I was having some problems persuading optim() to give me the answers I
 & simplified down to:


I accept this is a hammer to crack a nut, but was still expecting the
answer -1.
I got:

   [1] -0.8

   [1] 0.04

   function gradient
      12       NA

   [1] 0


so I've obviously misunderstood something.
(The default 'robust but slow' method did seem appropriate.)

Repeating this for:
   v2<-1;for(i in 1:201) v2[i]<-optim(v[i],sqr)$par

gave a bit more than 10% unexpected answers. Playing with control reduces
the scatter, but rather relies on knowing the answer in advance.
(function(x){x^2} gives another nice pattern.)

So, with the usual apologies for my ignorance (of both kinds, though I have
had a look in the archives), I'd be grateful for an indication of where I've
messed up.



> version
platform i386-pc-mingw32
arch     x86
os       Win32
system   x86, Win32
status   Patched
major    1
minor    4.0
year     2002
month    01
day      23
language R

(but also tried on a couple of other machines)

Mike Lonergan
Research Unit for Wildlife Population Assessment
Mathematical Institute
University of St Andrews
North Haugh                             Tel: +44 (0) 1334 463760
St Andrews                              Fax: +44 (0) 1334 463714
Fife KY16 9SS                      Email: mel at mcs.st-and.ac.uk

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list