[R] Optimization

Uwe Ligges ligges at statistik.uni-dortmund.de
Mon Jun 18 18:29:27 CEST 2007



livia wrote:
> Hi, I would like to minimize the value of x1-x2, x2 is a fixed value of 0.01,
> x1 is the quantile of normal distribution (0.0032,x) with probability of
> 0.7, and the changing value should be x. Initial value for x is 0.0207. I am
> using the following codes, but it does not work.
> 
> fr <- function(x) {
>       x1<-qnorm(0.7,0.0032,x)
>       x2=0.01
>       x1-x2
> }
> xsd <- optim(0.0207, fr, NULL,method="BFGS")


I guess you want to use optimize() and change the last line of fr to 
(x1-x2)^2 as in:


fr <- function(x) {
       x1 <- qnorm(0.7, 0.0032, x)
       x2 <- 0.01
       (x1-x2)^2
}

optimize(fr, c(-5, 5))

Uwe Ligges




> It is the first time I am trying to use optimization. Could anyone give me
> some advice?



More information about the R-help mailing list