[R] optim with constraints

Prof. John C Nash nashjc at uottawa.ca
Sun Dec 6 15:15:19 CET 2009


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/?group_id=395
is a wrapper that allows some other methods too.

JN




> Message: 72
> Date: Sun, 6 Dec 2009 02:53:55 -0800 (PST)
> From: Steven <ytsteven at gmail.com>
> Subject: [R] optim with constraints
> To: r-help at r-project.org
> Message-ID:
> 	<5e293933-91f2-48f7-98e5-bc87905c59d2 at x25g2000prf.googlegroups.com>
> Content-Type: text/plain; charset=ISO-8859-1
> 
> Hi, dear R users
> 
> I am a newbie in R and I wantto use the method of meximum likelihood
> to fit a Weibull distribution to my survival data. I use "optim" as
> follows:
> 
> 
> optim(c(1, 0.25),weibull.like,mydata=mydata,method="L-BFGS-B",hessian
> = TRUE)
> 
> My question is: how do I setup the constraints so that the two
> parametrs of Weibull to be pisotive? Or should I use other function
> like"nlm"?
> 
> Many thanks! Any comments are greatly appreciated!
> 
> Steven




More information about the R-help mailing list