# [R] Supply linear constrain to optimizer

Philippe Grosjean phgrosje at ulb.ac.be
Fri Sep 14 14:20:57 CEST 2001

```>  I agree with the suggestion to reparameterize the data, but the problem
>here is not readjusting the range (the box constraints in optim/L-BFGS-B
>work just fine).
>  A transformation I have used for compositional data:

>  c(1) <-> p(1)
>  c(2) <-> p(2)/(1-p(1))
>  ...
>  c(n) <-> p(n)/(1-sum p(1)..p(n-1))

Hummm, let me see. I use also min(x, 10) instead of x to constraint a
parameter x <= 10 (same with max)... but it is dangerous and it should be
used carfully. Your problem here is more complex. You want to make sure
1-c1-c2 is in range [0, 1], isn't it? What about replacing (1-c1-c2) by (if
((c1+c2)>1) 1e100 else if ((c1+c2)<0) 1e100 else (1-c1-c2)) in

likelihood = sum( ln(c1*exp(-x/lambda1)/lambda1 +
c2*exp(-x/lambda2)/lambda2 + (1-c1-c2)*exp(-x/lambda3)/lambda3) )

This way, you would not have negative numbers which produces NaN in ln(x)
[by the way, you mean log(x), I presume?]. You will obtain large positive
numbers in each case where the condition is not met. These solutions for c1
and c2 will then be avoided during the minimization process. This is a
mechanism used in nonlinear module of Statistica for instance and it is very
efficient.
All the best,

Philippe Grosjean

...........]<(({?<...............<?}))><...............................
) ) ) ) )	 __               	 __
( ( ( ( ( 	|__)              	|  _
) ) ) ) )	|   hilippe       	|__)rosjean
( ( ( ( ( 	Marine Biol. Lab., ULB, Belgium
) ) ) ) )	                  	 __
( ( ( ( ( 	|\  /|            	|__)
) ) ) ) )	| \/ |ariculture &	|__)iostatistics
( ( ( ( (
) ) ) ) )	e-mail: phgrosje at ulb.ac.be or phgrosjean at sciviews.org
( ( ( ( ( 	SciViews project coordinator (http://www.sciviews.org)
) ) ) ) )      tel: 00-32-2-650.29.70 (lab), 00-32-2-673.31.33 (home)
( ( ( ( (
) ) ) ) )      "I'm 100% confident that p is between 0 and 1"
( ( ( ( (                                  L. Gonick & W. Smith (1993)
) ) ) ) )
.......................................................................

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```