[R] Re: Is there a minimization function?

Thomas Lumley tlumley at u.washington.edu
Sat Nov 24 22:11:46 CET 2001


On Sat, 24 Nov 2001, Bernardo Ribeiro wrote:

> I was trying to minimize this function but got this error:
>
> > L_function(alfa,beta,sigma2){
> + -1* (-n/2*log(sigma2))+0.5*sum((y-g(alfa,beta))^2)/sigma2
> + }
> > inic_c(0.3893,0.507,0.00228)
> > optim(inic,L)
> Error in log(sigma2) : Argument "sigma2" is missing, with no default
>
>     Any clues?

In help(optim)

       fn: A function to be minimized (or maximized), with first
          argument the vector of parameters over which minimization is
          to take place. It should return a scalar result.


Optimisation is only done over the first argument for fixed values of the
others. If you want to optimise over three parameters put them in a vector
 L <- function(theta){
   alfa <- theta[1]
   beta <- theta[2]
   sigma2 <- theta[3]
   -1* (-n/2*log(sigma2))+0.5*sum((y-g(alfa,beta))^2)/sigma2
 }

or if you want to optimise alfa for fixed values of the other two
parameters you need to supply them
eg
 optim(inic, L, alfa=1, sigma2=1)


	-thomas

Thomas Lumley			Asst. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list