[R] optim question

2012-05-09 Thread John C Nash
When I run your problem in optimx (with all.methods=TRUE), L-BFGS-B fails 
because the
function is evaluated out of range. optimx (actually the optfntools package) 
from R-forge
can trap these, and it is usually a good idea to stop and figure out what is 
going on.
Nevertheless, it seems a solution can be found by other methods, and even by 
L-BFGS-B if
one is prepared to ignore these glitches.

A big +++ for including an executable example. Of course, I would not have 
answered otherwise.

Note that the optimx and optfntools on R-forge are at the moment undergoing a 
lot of
review and change.

Best, JN


 Message: 4
 Date: Tue, 8 May 2012 14:35:10 -0500
 From: Wenhao Gui guiwen...@gmail.com
 To: r-help@r-project.org
 Subject: [R] optim question
 Message-ID:
   CABZdO=zKr1wsXmTOQ54UieVQfpkAx=cyt0dzip7yt1cjb6e...@mail.gmail.com
 Content-Type: text/plain
 
 Hello,
 
 I used optim to find the MLE estimates of some parameters.  See the code
 below.  It works for data1(x). but It did not work for data2 and the error
 says L-BFGS-B needs finite values of 'fn' .
 
 data2:   c(x, 32)  that is, if I added the number 32 at the end of data1.
 The error appears non-finite function value etc.
 
 Any comments or suggestions?
 
 Thanks!
 
 Wenhao


__
R-help@r-project.org 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] optim question

2012-05-08 Thread Wenhao Gui
Hello,

I used optim to find the MLE estimates of some parameters.  See the code
below.  It works for data1(x). but It did not work for data2 and the error
says L-BFGS-B needs finite values of 'fn' .

data2:   c(x, 32)  that is, if I added the number 32 at the end of data1.
The error appears non-finite function value etc.

Any comments or suggestions?

Thanks!

Wenhao


##

x-c(8, 11, 20, 15, 21, 16, 19, 15, 19, 17, 14, 8, 20, 7, 20, 25, 4, 17,
10, 28, 14, 13, 6, 109, 11, 29, 14, 17, 43, 75, 7, 19, 14, 12, 16, 3, 42,
40, 15,42,31,33,52, 45, 46,54)



n-length(x)

j-1

int-numeric(n)

log.lik-function(theta,x){

repeat{

integrand-function(t,theta){

((2*pnorm(x[j]*t)-1)^(theta[1]-1))*((1-(pnorm(x[j]*t)))^(theta[2]-1))*(dnorm(x[j]*t))*(t^theta[4])

}

int[j]-integrate(integrand, lower=0,upper=1/theta[3],theta=theta)$val

j-j+1

if(jlength(x))

break

}

-length(x)*(log((2^theta[2]*theta[3]^theta[4]*theta[4]/(beta(theta[1],theta[2])-sum(log(int))

}


aaa-optim(c(2,2,10,5),method=L-BFGS-B,fn=log.lik,lower=c(1,1,1,1),
hessian=T,x=x, control=list(trace=T))

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] optim() question

2009-05-27 Thread John C Nash

Some thought about this overnight led to conclusion that a capability
to follow from one method to another could be quite useful. Moreover,
it should be pretty easy to fit it into our current trial version of 
optimx()

as we call the function. More at UseR.

JN


Ravi Varadhan wrote:
 
Stephen,


No.  Currently, AFAIK, there is no such switching algorithm for optimization
in R.  John Nash and I are working on a package for integrating various
optimization tools (for smooth, box-constrained optimization) in R.  This
will have a function that can run through multiple algorithms.  While this
is not exactly what you are asking for, it can be quite useful for your
purposes, which I assume is to find a local optimum in a reliable fashion.

Ravi.

...
-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Stephen Collins
Sent: Tuesday, May 26, 2009 2:48 PM
To: r-h...@stat.math.ethz.ch
Subject: [R] optim() question

I've seen with other software the capability for the optimizer to switch
algorithms if it is not making progress between iterations.  Is this
capability available in optim()?

Thanks,
 
Stephen Collins, MPP | Analyst

Health  Benefits | Aon Consulting



__
R-help@r-project.org 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] optim() question

2009-05-26 Thread Stephen Collins
I've seen with other software the capability for the optimizer to switch 
algorithms if it is not making progress between iterations.  Is this 
capability available in optim()?

Thanks,
 
Stephen Collins, MPP | Analyst
Health  Benefits | Aon Consulting

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.