Just pass the additional arguments as extra arguments to nlminb:
> f <- function(x, aa=0, bb=0, cc=0) aa*x^2 + bb*x + cc
> nlminb(0, f, aa=1, bb=2, cc=1)[1:2]
$parameters:
[1] -1
$objective:
[1] 0
> nlminb(0, f, aa=1, bb=4, cc=1)[1:2]
$parameters:
[1] -2.000001
$objective:
[1] -3
>
Unfortunately, this is not documented correctly in the nlminb help page:
the arguments "..." are not listed in the USAGE section. However, the
"..." arguments are described in the ARGUMENTS section, and you can also
see them by doing args(nlminb).
Something you have to be very careful of with this feature is that your
actual arguments names do not partially (or fully) match other arguments
of nlminb.
E.g., if your function definition was function(x, s=1), and you called
nlminb(0, f, s=1), then the "s" argument would get matched to the
"scale" argument of nlminb, and would NOT get passed to your function f().
hope this helps,
Tony Plate
stephane.g.zebouni@jpmorgan.com wrote:
Hello,
I am using S-plus 6.1 and the function nlminb to optimize a function of
one parameter (a target function ofr an ewma model). I want to be able
to pass an argument to the function that is not supposed to be optimized
(i.e. i am minimizing on a given set of data,and i want to be able to
change this set of data as i want to call the optimization several times
on different sets of data) Is there a simple way to do that?
Thanks a lot
Stephane
This communication is for informational purposes only. It is not intended
as an offer or solicitation for the purchase or sale of any financial
instrument or as an official confirmation of any transaction. All market prices,
data and other information are not warranted as to completeness or accuracy and
are subject to change without notice. Any comments or statements made herein
do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries
and affiliates.
|