[R] constrOptim parameters
Ravi Varadhan
RVaradhan at jhmi.edu
Fri Sep 11 22:47:09 CEST 2009
Ivo,
Do you only have "box" constraints, i.e. upper and lower bounds on the
parameters themselves? If so, you do not need to use `constrOptim'. You
could use "L-BFGS-B" in `optim' or `nlminb' or `spg'.
You are mistaken about how `ui' is set up. It should be a matrix with
dimension, Ni x p, where Ni is the number of inequality constraints and p is
the number of parameters. So, in your case it should be a 2N x N matrix.
Read the help carefully.
Ravi.
----------------------------------------------------------------------------
-------
Ravi Varadhan, Ph.D.
Assistant Professor, The Center on Aging and Health
Division of Geriatric Medicine and Gerontology
Johns Hopkins University
Ph: (410) 502-2619
Fax: (410) 614-9625
Email: rvaradhan at jhmi.edu
Webpage:
http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadhan.h
tml
----------------------------------------------------------------------------
--------
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of ivo welch
Sent: Friday, September 11, 2009 4:21 PM
To: r-help
Subject: [R] constrOptim parameters
Dear R wizards: I am playing (and struggling) with the example in the
constrOptim function. simple example. let's say I want to constrain my
variables to be within -1 and 1. I believe I want a whole lot of
constraints where ci is -1 and ui is either -1 or 1. That is, I have 2*N
constraints. Should the following work?
N=10
x= rep(1:N)
ci= rep(-1, 2*N)
ui= c(rep(1, N), rep(-1, N))
constrOptim( x, f, NULL, ui, ci, method="Nelder-Mead");
actually, my suggestions would be to give an example in the constrOptim docs
where the number of constraints is something like this example. the current
ones have 2*2 constraints, so it is harder to figure out the appropriate
dimensions for different cases by extending the examples. on another note,
the "non-conformable arguments" error could be a little more informative,
telling the end user what the two incompatible dimensions actually are.
this is not hard to find out by hand, but it would still be useful.
regards,
/iaw
--
Ivo Welch (ivo.welch at brown.edu, ivo.welch at gmail.com)
[[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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
mailing list