A question about optim function in R

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

A question about optim function in R

Cisy
Hi,

I encounter a problem in R. My program is as follows.
lower <- c(-Inf,-Inf,-Inf,-Inf,0,0,0,-1,-1,-1)
upper <- c(Inf,Inf,Inf,Inf,Inf,Inf,Inf,1,1,1)
out <- optim(parm,logLik,method='L-BFGS-B',lower=lower,upper=upper,hessian=hessian)

As you can see, I have restricted parameter[5], parameter[6] and parameter[7] to be greater than 0, but the program error is shown in the attached picture ('产生' means 'produce'). The reason for this error seems to be the limit in the function does not work. I don't know why.

Can you help me? Thanks very much!.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.

picture.png (47K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: A question about optim function in R

Jeff Newmiller
This is not reproducible.

[1] http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example

[2] http://adv-r.had.co.nz/Reproducibility.html

[3] https://cran.r-project.org/web/packages/reprex/index.html (read the vignette)


On July 26, 2020 7:33:32 AM PDT, Zixuan Qi <[hidden email]> wrote:

>Hi,
>
>I encounter a problem in R. My program is as follows.
>lower <- c(-Inf,-Inf,-Inf,-Inf,0,0,0,-1,-1,-1)
>upper <- c(Inf,Inf,Inf,Inf,Inf,Inf,Inf,1,1,1)
>out <-
>optim(parm,logLik,method='L-BFGS-B',lower=lower,upper=upper,hessian=hessian)
>
>As you can see, I have restricted parameter[5], parameter[6] and
>parameter[7] to be greater than 0, but the program error is shown in
>the attached picture ('产生' means 'produce'). The reason for this error
>seems to be the limit in the function does not work. I don't know why.
>
>Can you help me? Thanks very much!.

--
Sent from my phone. Please excuse my brevity.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: A question about optim function in R

J C Nash
In reply to this post by Cisy
For this and the nlminb posting, a reproducible example would be useful.

The optimx package (I am maintainer) would make your life easier in that it
wraps nlminb and optim() and other solvers, so you can use a consistent call.
Also you can compare several methods with opm(), but do NOT use this for
production work as it chews cpu cycles. It is intended to test and compare
methods for a family of objective functions.

JN


On 2020-07-26 10:33 a.m., Zixuan Qi wrote:

> Hi,
>
> I encounter a problem in R. My program is as follows.
> lower <- c(-Inf,-Inf,-Inf,-Inf,0,0,0,-1,-1,-1)
> upper <- c(Inf,Inf,Inf,Inf,Inf,Inf,Inf,1,1,1)
> out <- optim(parm,logLik,method='L-BFGS-B',lower=lower,upper=upper,hessian=hessian)
>
> As you can see, I have restricted parameter[5], parameter[6] and parameter[7] to be greater than 0, but the program error is shown in the attached picture ('产生' means 'produce'). The reason for this error seems to be the limit in the function does not work. I don't know why.
>
> Can you help me? Thanks very much!.
>
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: A question about optim function in R

Rasmus Liland-3
In reply to this post by Jeff Newmiller
Dear Zixuan,

On 2020-07-26 07:36 -0700, Jeff Newmiller wrote:
> On July 26, 2020 7:33:32 AM PDT, Zixuan Qi <[hidden email]> wrote:
> > Hi,
> >
> > I encounter a problem in R. My program is as follows.
> > lower <- c(-Inf, -Inf, -Inf, -Inf, 0, 0, 0, -1, -1, -1)
> > upper <- c(Inf, Inf, Inf, Inf, Inf, Inf, Inf, 1, 1, 1)
> > out <- optim(parm, logLik, method='L-BFGS-B', lower=lower, upper=upper, hessian=hessian)

Can you include parm?

> > As you can see, I have restricted
> > parameter[5], parameter[6] and
> > parameter[7] to be greater than 0,
> > but the program error is shown in
> > the attached picture ('产生' means
> > 'produce'). The reason for this
> > error seems to be the limit in the
> > function does not work. I don't know
> > why.
> >
> > Can you help me? Thanks very much!.
>
> This is not reproducible.
>
> [1] http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example
> [2] http://adv-r.had.co.nz/Reproducibility.html
> [3] https://cran.r-project.org/web/packages/reprex/index.html (read the vignette)
Best,
Rasmus

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.

signature.asc (849 bytes) Download Attachment