Re: [R] Passing parameters to 'optim' fn function

2007-09-12 Thread Duncan Murdoch
José Luis Aznarte M. wrote: > Hi again! I'm using the 'optim' method to fix the parameters of a > model. I have written the function to be minimised and another function > which returns the gradient of the error. Now my problem is that, in > order to compute that gradient, it would be extrem

Re: [R] Passing parameters to 'optim' fn function

2007-09-12 Thread Dimitris Rizopoulos
you need to use the `...' argument; look at ?optim() for more info. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http:

Re: [R] Passing parameters to 'optim' fn function

2007-09-12 Thread Robin Hankin
Hi Use the dots argument at the end to pass in named parameters. This is documented as the last in the argument list under ?optim. Here's a toy example using x and p: > f <- function(x,p){sum(x^2)+p*sum(x)} > gr <- function(x,p){2*x+p*rep(1,length(x))} > optim(par=c(10,10),fn=f,gr=gr,p=13) $