0

I have troubles providing supplementary arguments to optim function. Parameters to be optimized over are sent as a first arguments, and extra arguments are to be provided as named arguments. But this doe not seem to work in my code

I have four arguments to be used for optimization (a,b,c,d) and 4 more to be used as supplementary arguments, with no optimization (e, f, g, h, where e and f are scalars, and g and h are vectors). The function to be optimized is fct.

I am trying:

parm<-c(a,b,c,d)
optim(par=parm,fn=fct,e=e,f=f,g=g,h=h)

Running this constantly returns that the g vector is missing, with no default value... I don't understand my mistake, even after reading on similar problems in discussion lists.

ndrwnaguib
  • 5,623
  • 3
  • 28
  • 51
FredF
  • 1
  • Welcome to SO! This community has a few [rules](https://stackoverflow.com/help/on-topic) and [norms](https://stackoverflow.com/help/how-to-ask) and following them will help you get a good answer to your question. In particular, it’s best to provide an [MCVE](https://stackoverflow.com/help/mcve) (a minimum, complete, and verifiable example). Good advice for R-specific MVCEs is available [here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610) and [here](https://reprex.tidyverse.org/articles/reprex-dos-and-donts.html). – DanY Mar 23 '19 at 20:09
  • Can you post the code for `fct` and give us example values to use for `e`, `f`, `g`, and `h`? – DanY Mar 23 '19 at 20:16

0 Answers0