[R] Optim() package restriction

ilai keren at math.montana.edu
Sat Feb 25 15:56:24 CET 2012


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.



More information about the R-help mailing list