# [R-sig-ME] Optimize multiple confounded parameters using optim()

Jeff Newmiller jdnewmil @ending from dcn@d@vi@@c@@u@
Thu May 17 18:12:15 CEST 2018

```I am not sure I follow your explanation of the problem domain, but the equations look like the kind of thing that linear programming was designed to solve. There are a few options for that among the contributed packages (look in the Optimization Task View on CRAN).

On May 17, 2018 4:07:10 AM PDT, Keren Halabi <halabikeren at gmail.com> wrote:
>Dear list,
>
>My apologies in advance if this is not the relevant forum for the below
>question.
>
>I wish to define a codon site model, which is mixture model over
>multiple
>dN/dS ratios.
>Thus, I want to constrain each  dN/dS ratio by its preceding ratio in
>the
>mixture and its following ratio in the mixture. I was thinking of using
>the
>bounds parameter of the optim() function to achieve this.
>
>However, I am experiencing an issue while attempting to optimize a
>function
>with regards to multiple parameters. Specifically, due to setting the
>bounds to be dependent on one another.
>
>Here is a basic example: say that I want to optimize the below function
>named "test', with regards to vector v, with the following constraint:
>0<=v<=v<=1:
>test <-function(v=c(0,1)) {return(v-v)}
>
>Now, calling optim() with the following settings:
>a=0
>b=1
>res = optim(c(a,b), test, lower=c(0,a), upper=c(b,1),method="L-BFGS-B")
>
>Yields optimized values:
>a=1
>b=0
>test(c(a,b))=-1
>
>It appears that the constraint was not satisfied, but the bounds still
>some  affect on the result. This makes me suspect that I didn't set the
>lower and upper bounds correctly when calling optim().
>Could you please let me know what I did wrong?
>
>Many thanks!
>Keren
>
>	[[alternative HTML version deleted]]
>
>_______________________________________________
>R-sig-mixed-models at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models

--
Sent from my phone. Please excuse my brevity.

```