Hi I need a "phi" restriction in my code. That is "0<phi<1 " How can I do that ? Linn=function(param){ phi=param[1] sigw=param[2] sigv=param[3] Betam=param[4] kf=kfilter1(n,st[,k],st[,1],0,1,phi,Betam,sigw,sigv) return(kf$like) } init.par<-c(1,1,1,1) estimate<- optim(init.par,Linn,gr=NULL,method= "BFGS", hessian=FALSE,control = list(trace=1)) Regards, res -- View this message in context: http://r.789695.n4.nabble.com/Optim-package-restriction-tp4418379p4418379.html Sent from the R help mailing list archive at Nabble.com.
On Fri, Feb 24, 2012 at 12:18 PM, nserdar <snes1982 at hotmail.com> wrote:> Hi > > I need a "phi" restriction in my code. That is ? "0<phi<1 " > > How can I do that ?> init.par<-c(1,1,1,1) > estimate<- optim(init.par,Linn,gr=NULL,method= "BFGS", hessian=FALSE,control > = list(trace=1)) >You want method "L-BFGS-B" not "BFGS". See details in ?optim Best> Regards, > res > > -- > View this message in context: http://r.789695.n4.nabble.com/Optim-package-restriction-tp4418379p4418379.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at 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.
Thanks for your attention. I searched this function but I can not find " special example about box constraint". Can you give an example for my code? Regards, Ser -- View this message in context: http://r.789695.n4.nabble.com/Optim-package-restriction-tp4418379p4418858.html Sent from the R help mailing list archive at Nabble.com.
I did it like above but got an error message.> estimate<- optim(init.par,Linn,gr=NULL,method= "L-BFGS-B", > hessian=FALSE,control > list(trace=1),lower=c(0,-Inf,Inf,Inf),upper=c(1,Inf,Inf,Inf))Error in solve.default(sig[, , 1]) : system is computationally singular: reciprocal condition number = 0 "how to derive constrain for only 1 variable" Regards, Ser -- View this message in context: http://r.789695.n4.nabble.com/Optim-package-restriction-tp4418379p4418865.html Sent from the R help mailing list archive at Nabble.com.
On Fri, Feb 24, 2012 at 4:03 PM, nserdar <snes1982 at hotmail.com> wrote:> I did it like above ?but got an error message. > >> estimate<- optim(init.par,Linn,gr=NULL,method= "L-BFGS-B", >> hessian=FALSE,control >> list(trace=1),lower=c(0,-Inf,Inf,Inf),upper=c(1,Inf,Inf,Inf))Your lower bound for parameters 3,4 needs to be -Inf not Inf. Otherwise this looks right, any other errors are your data/function.> Error in solve.default(sig[, , 1]) : > ?system is computationally singular: reciprocal condition number = 0 > > "how to derive constrain for only 1 variable" >Adopted from the examples in optim: fr <- function(x) { ## Rosenbrock Banana function x1 <- x[1] x2 <- x[2] 100 * (x2 - x1 * x1)^2 + (1 - x1)^2 } optim(c(-1.2,1), fr, method = "L-BFGS-B") optim(c(-1.2,1), fr, method = "L-BFGS-B",upper=c(Inf,Inf)) optim(c(-1.2,1), fr, method = "L-BFGS-B",upper=c(Inf,.7)) HTH> Regards, > Ser > > -- > View this message in context: http://r.789695.n4.nabble.com/Optim-package-restriction-tp4418379p4418865.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at 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.