[R] Q. regarding optim()

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Jul 21 08:12:59 CEST 2006

On Fri, 21 Jul 2006, N. Goodacre wrote:

Dear R mailing group,
>   The second parameter for the function optim()is a function whose 
> parameters are to be optimized. The description of this function given in 
> the help file is the following:
>       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.
> Let's say the second argument is x, a vector of x values

But it says `parameters'.  Please look at the examples on that help page.  
optim is concerned with optimizing functions of more than one parameter. 
In a statistical setting 'x' may be the data, but e.g. for fitting a gamma 
distribution c(scale, shape) are the parameters.

> I would have thought that fn should return a vector full of y values for 
> the x values entered as the second argument. If the function just takes one 
> value at a time and outputs a scalar, how can I specify for fn which x 
> value, of the vector x, to take?
>  Sincerely,
> Norman Goodacre
> ______________________________________________
> R-help at stat.math.ethz.ch 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.

Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

More information about the R-help mailing list