Re: [R] optim with constraints

2009-12-07 Thread JPO
Steven, A quick trick to deal with problems of this nature (i.e. forcing parameters to stay positive although the parameter search isn't bound to non-negatives or positives) without resorting to another package is to re-parametrize the density function. Notice, x \in (-\infty,\infty) for x \in (-

Re: [R] optim with constraints

2009-12-07 Thread Ravi Varadhan
-help-boun...@r-project.org] On Behalf Of Prof. John C Nash Sent: Monday, December 07, 2009 9:01 AM To: r-help@r-project.org Subject: Re: [R] optim with constraints Without the data / script, I'm guessing that it is likely an attempt to evaluate the loss function at an inadmissible point e.g., at

Re: [R] optim with constraints

2009-12-07 Thread Prof. John C Nash
other things) on trying to provide a nice wrapper to catch these exceptions so that they can be handled better. JN Message: 56 Date: Sun, 6 Dec 2009 17:32:54 -0800 (PST) From: Steven Subject: Re: [R] optim with constraints To: r-help@r-project.org Message-ID: <88d5c01d-c30c-4

Re: [R] optim with constraints

2009-12-06 Thread Steven
Hi, Prof Nash Thanks for your comment! I modified my code to be (added an extra parametr): optim(c(1.14,0.25,0.06), weibull.like, mydata=mydata, method="L-BFGS- B", hessian = TRUE, lower = c(0, 0, 0), upper = c(Inf, Inf, 1)) But I had the following error: Error in optim(c(1.14, 0.25, 0.06), we

Re: [R] optim with constraints

2009-12-06 Thread Ravi Varadhan
Read the help page for `optim'. You already seem to be aware that "L-BFGS-B" should be used. How much more harder is to read the help page further to figure out how to supply the constraints? There are also various other algorithms, but "L-BFGS-B" should be able to do the job. Ravi. __

Re: [R] optim with constraints

2009-12-06 Thread Prof. John C Nash
As per ?optim Usage: optim(par, fn, gr = NULL, ..., method = c("Nelder-Mead", "BFGS", "CG", "L-BFGS-B", "SANN"), lower = -Inf, upper = Inf, control = list(), hessian = FALSE) Note that the optimx() function on R-forge http://r-forge.r-project.org/R/?grou