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") It is the first time I am trying to use optimization. Could anyone give me some advice? -- View this message in context: http://www.nabble.com/Optimization-tf3941212.html#a11178663 Sent from the R help mailing list archive at Nabble.com.
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?
>From the help page:Note: 'optim' will work with one-dimensional 'par's, but the default method does not work well (and will warn). Use 'optimize' instead. Next, there is a constraint of x>=0 that you are not imposing. Finally, it is easy to see that qnorm(0.7, 0.0032, x) is monotome in x, so the solution is x=0. In fact, x1 = 0.0032 + sqrt(x) * qnorm(0.7). optim(0.0207, fr) does a good enough job, as does optimize(fr, low=0, up=0.05) Advice: numerical optimization is not a black box, and has to be used with some analysis of the problem to hand. See e.g. MASS4, chapter 16. On Mon, 18 Jun 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") > > It is the first time I am trying to use optimization. Could anyone give me > some advice? >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
You don't need optimization for the solution to your problem. You just need an understanding of the meaning of qnorm() and some simple algebra. Try: x<- (0.01-0.0032)/qnorm(0.7,0,1) At 12:01 PM 6/18/2007, you 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") > >It is the first time I am trying to use optimization. Could anyone give me >some advice? >-- >View this message in context: >http://www.nabble.com/Optimization-tf3941212.html#a11178663 >Sent from the R help mailing list archive at Nabble.com. > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code.===============================================================Robert A. LaBudde, PhD, PAS, Dpl. ACAFS e-mail: ral at lcfltd.com Least Cost Formulations, Ltd. URL: http://lcfltd.com/ 824 Timberlake Drive Tel: 757-467-0954 Virginia Beach, VA 23464-3239 Fax: 757-467-2947 "Vere scire est per causas scire"
On 18-Jun-07 16:01:03, 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'm a bit puzzled by the question. If I understand it right, we can ignore x2 (since it is a fixed value) and simply consider minimising x1 (instead of x1-x2). Then, denoting by P(u) the cumulative normal distribution function for mean=0 and variance=1 (i.e. in R: pnorm(u,0,1)), and by Q(p) its inverse, corresponding to qnorm(p,0,1), we have (again if I have understood right): P((x1 - 0.0032)/x) = 0.7 so x1 = 0.0032 + x*Q(0.7) and therefore, since Q(0.7) > 0 and x must be positive, the value of x1 can be made as close to 0.032 as you please (but greater than 0.032) by taking x small enough. Hence there is no strictly minimising value of x, but the greatest lower bound of all possible values of x1 is 0.032. Then you can subtract x2. The fact that there is no positive value of x which gives this bound as the value probably explains the failure of your optim() attempt. Best wishes, Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <ted.harding at nessie.mcc.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 18-Jun-07 Time: 17:46:01 ------------------------------ XFMail ------------------------------
Hi, my first guess is that the algorithm returns a negative value in some step - recall that you start from 0.0207!! This negative value is then passed as standard error to qnorm and that cannot work... My guess is based on a small experiment where I tried a different starting point (.02 is so close to 0 that one cannot see anything): xsd <- optim(20, fr, NULL,method="BFGS",control=list(trace=6)) The warnings which you didn't include also tell you about NaNs in qnorm() - another strong indication of wrong arguments to qnorm(). Try constrained optimization to resctrict to positive values. See ?constrOptim or use optim() with a method allowing for box constraints - see ?optim, arguments lower, upper. Petr livia napsal(a):> 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") > > It is the first time I am trying to use optimization. Could anyone give me > some advice?-- Petr Klasterecky Dept. of Probability and Statistics Charles University in Prague Czech Republic
It is of great help for your advice. Thanks a lot to you all. 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") > > It is the first time I am trying to use optimization. Could anyone give me > some advice? >-- View this message in context: http://www.nabble.com/Optimization-tf3941212.html#a11196890 Sent from the R help mailing list archive at Nabble.com.
Dear all, I need a suggest to obtain the max of this function: Max x1*0.021986+x2*0.000964+x3*0.02913 with these conditions: x1+x2+x3=1; radq((x1*0.114434)^2+(x2*0.043966)^2+(x3*0.100031)^2)=0.04; x1>=0; x1<=1; x2>=0; x2<=1; x3>=0; x3<=1; Any suggests ? Thanks in advanced, Massimiliano
I'm sorry the function is sqrt((x1*0.114434)^2+(x2*0.043966)^2+(x3*0.100031)^2)=0.04; Have you any suggests. Thanks, Massimiliano What is radq? --- "massimiliano.talarico" <massimiliano.talarico at poste.it> wrote:> Dear all, > I need a suggest to obtain the max of this function: > > Max x1*0.021986+x2*0.000964+x3*0.02913 > > with these conditions: > > x1+x2+x3=1; >radq((x1*0.114434)^2+(x2*0.043966)^2+(x3*0.100031)^2)=0.04;> x1>=0; > x1<=1; > x2>=0; > x2<=1; > x3>=0; > x3<=1; > > Any suggests ? > > Thanks in advanced, > Massimiliano > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, > reproducible code. >
Thanks for your suggests, but I need to obtain the MAX of this function: Max x1*0.021986+x2*0.000964+x3*0.02913 with these conditions: x1+x2+x3=1; sqrt((x1*0.114434)^2+(x2*0.043966)^2+(x3*0.100031)^2)=0.04; x1>=0; x2>=0; x3>=0; Thanks and again Thanks, Massimiliano My apologies, didn't see the boundary constraints. Try this one... f <- function(x) (sqrt((x[1]*0.114434)^2+(x[2]*0.043966)^2+(x[3]*0.100031) ^2)-0.04)^2 optim(par=rep(0,3),f,lower=rep(0,3),upper=rep (1,3),method="L-BFGS-B") and check ?optim --- "massimiliano.talarico" <massimiliano.talarico at poste.it> wrote:> I'm sorry the function is > > sqrt((x1*0.114434)^2+(x2*0.043966)^2+(x3*0.100031)^2)=0.04;> > Have you any suggests. > > Thanks, > Massimiliano > > > > What is radq? > > --- "massimiliano.talarico" > <massimiliano.talarico at poste.it> wrote: > > > Dear all, > > I need a suggest to obtain the max of this function: > > > > Max x1*0.021986+x2*0.000964+x3*0.02913 > > > > with these conditions: > > > > x1+x2+x3=1; > > > radq((x1*0.114434)^2+(x2*0.043966)^2+(x3*0.100031)^2)=0.04;> > x1>=0; > > x1<=1; > > x2>=0; > > x2<=1; > > x3>=0; > > x3<=1; > > > > Any suggests ? > > > > Thanks in advanced, > > Massimiliano > > > > ______________________________________________ > > R-help at stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > > http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, > > reproducible code. > > > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained,reproducible code.>____________________________________________________________ ________________________ Fussy? Opinionated? Impossible to please? Perfect. Join Yahoo!'s user panel and lay it on us. http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7
Hi, Your problem can be solved analytically. Eliminate one of the variables, say x3, from the problem by using the equality x1 + x2 + x3 = 1. Then solve for the intersection of the circle (in x1 and x2) defined by the radical constraint, with the straight line defined by the objective function. There will be, at most, two intersection points. The extremum has to be one of these two points, provided they also satisfy the other inequalities (To me, this sounds an awful lot like a homework problem). Ravi. ---------------------------------------------------------------------------- ------- Ravi Varadhan, Ph.D. Assistant Professor, The Center on Aging and Health Division of Geriatric Medicine and Gerontology Johns Hopkins University Ph: (410) 502-2619 Fax: (410) 614-9625 Email: rvaradhan at jhmi.edu Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html ---------------------------------------------------------------------------- -------- -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of massimiliano.talarico Sent: Monday, July 16, 2007 4:50 PM To: r-help Subject: [R] Optimization Dear all, I need a suggest to obtain the max of this function: Max x1*0.021986+x2*0.000964+x3*0.02913 with these conditions: x1+x2+x3=1; radq((x1*0.114434)^2+(x2*0.043966)^2+(x3*0.100031)^2)=0.04; x1>=0; x1<=1; x2>=0; x2<=1; x3>=0; x3<=1; Any suggests ? Thanks in advanced, Massimiliano ______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
This is partially true since both the function to be maximized and the constraint are non-linear. One may substitute 1-x1-x2 for x3 and use (let say) Lagrange multipliers to get two non-linear equations with 2 unknowns for which there should be a function solving them. Then you must find the points where the constraint function intersects with the triangle {x1>=0,x2>=0,x1+x2<=1}, which is easier (for each of the 3 edges you get a non-linear equation in one variable). So even though an (almost) analytical solution can be found it would be much more convenient to use an optimization function which (hopefully) does all this for you. Moshe. --- Ravi Varadhan <rvaradhan at jhmi.edu> wrote:> Hi, > > Your problem can be solved analytically. Eliminate > one of the variables, > say x3, from the problem by using the equality x1 + > x2 + x3 = 1. Then solve > for the intersection of the circle (in x1 and x2) > defined by the radical > constraint, with the straight line defined by the > objective function. There > will be, at most, two intersection points. The > extremum has to be one of > these two points, provided they also satisfy the > other inequalities (To me, > this sounds an awful lot like a homework problem). > > > Ravi. > >----------------------------------------------------------------------------> ------- > > Ravi Varadhan, Ph.D. > > Assistant Professor, The Center on Aging and Health > > Division of Geriatric Medicine and Gerontology > > Johns Hopkins University > > Ph: (410) 502-2619 > > Fax: (410) 614-9625 > > Email: rvaradhan at jhmi.edu > > Webpage: >http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html> > > >----------------------------------------------------------------------------> -------- > > -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf > Of massimiliano.talarico > Sent: Monday, July 16, 2007 4:50 PM > To: r-help > Subject: [R] Optimization > > Dear all, > I need a suggest to obtain the max of this function: > > Max x1*0.021986+x2*0.000964+x3*0.02913 > > with these conditions: > > x1+x2+x3=1; >radq((x1*0.114434)^2+(x2*0.043966)^2+(x3*0.100031)^2)=0.04;> x1>=0; > x1<=1; > x2>=0; > x2<=1; > x3>=0; > x3<=1; > > Any suggests ? > > Thanks in advanced, > Massimiliano > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, > reproducible code. > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, > reproducible code. >