# [Rd] problem with function 'optimise' (PR#9438)

From: <karsten_krug_at_gmx.net>
Date: Thu 04 Jan 2007 - 10:24:29 GMT

Full_Name: Karsten Krug
Version: 2.4.0
OS: Open Suse 10.0, Windows XP
Submission from: (NULL) (88.134.13.50)

I found a problem in the 'optimise' function for one dimensional optimisation.

Example 1:
Try to find a maximum of the function below with the use of 'optimise' in the interval [0,0.5]. The function follows a parabola and has two local maxima located at the margins of the interval [0,0.5]. Please try the following code which performs this optimisation, produces a plot of the function within the given interval and adds the computed maximum returned by 'optimise()'

ex1 <- function(x) log(4 * x^2 - 2 * x + 0.5) opt1 <- optimise(ex1, lower=0, upper=0.5, maximum=T) x <- seq(0,0.5,0.001)
plot(x, ex1(x), type="l")
abline(v=opt1\$maximum, col="red")

The returned value of the maximum is 0.309017 which is definitely wrong.

Example 2:
The next function has also two equivalent maxima this time not located at the margins of the interval [0, 9/41]. Thus, the maxima are real analytic extrema. The function 'optimise()' again returns a wrong value.

ex2 <- function(x) log((18/41) * x - 2 * x^2) + 16 * log(4 * x^2 - (36/41) * x + (9/41)) + 24 * log((23/82) + (18/41) * x - 2 * x^2) opt2 <- optimise(ex2, lower=0, upper=(9/41), maximum=T) x <- seq(0,9/41,0.001)
plot(x,ex2(x),type="l")
abline(v=opt2\$maximum, col="red")

The two functions are not only of theoretical interest but have to be optimised as likelihood functions when dealing with SNP data.

I observed this problem on Windows XP and Open Suse 10.0. Other platforms have to be tested.

Some informations:

Open Suse 10.0

```platform       i686-pc-linux-gnu
arch           i686
os             linux-gnu
system         i686, linux-gnu
status
major          2
minor          4.0
year           2006
month          10
day            03
svn rev        39566
language       R
```

version.string R version 2.4.0 (2006-10-03)

Windows XP:

```platform       i386-pc-mingw32
arch           i386
os             mingw32
system         i386, mingw32
status
major          2
minor          4.0
year           2006
month          10
day            03
svn rev        39566
language       R
```
version.string R version 2.4.0 (2006-10-03)

With best regards,

Karsten Krug
Student at University of Leipzig

R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu Jan 04 21:37:44 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 05 Jan 2007 - 03:31:04 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.