[R] How to formulate constraint like abs(x) = y in constrOptim (or other)
rvaradhan at jhmi.edu
Mon Dec 6 23:52:51 CET 2010
If you just had abs(x_i) < c_i, it will reduce to linear inequalities, but
your constraint cannot be reduced to that.
You might try "alabama" or "Rsolnp" packages.
Ravi Varadhan, Ph.D.
Division of Geriatric Medicine and Gerontology School of Medicine Johns
Ph. (410) 502-2619
email: rvaradhan at jhmi.edu
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Hans W Borchers
Sent: Monday, December 06, 2010 1:08 PM
To: r-help at stat.math.ethz.ch
Subject: Re: [R] How to formulate constraint like abs(x) = y in constrOptim
Benjamin B. <benj.bad.ac <at> googlemail.com> writes:
> Hello list reader,
> I am trying to form some constraints for an optimization I am working on.
> I think I have understand the use of the constraints in matrix form. I use
> them like:
> Now I would like to formulate a constraint like
> But I have no idea how I could get such a condition by using the matrix
> constraint formulation.
> I have already searched the help, web and all searchable R resources I
> find, but got no helping result.
> Is constrOptim the right function to use?
> Maybe you can give me a hint or can point me to a good description of
> constraint handling.
> Greetings and thanks in advance,
> Benjamin B.
> Hamburg, Germany
With 'constrOptim' you can formulate linear constraints only, and in most
cases abs() is not linear. You might try one of the nonlinear optimization
Another possibility is to reformulate the absolute value with two binary
values, if your optimization function itself is linear; you didn't tell us
the whole story.
R-help at r-project.org mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
More information about the R-help