There is a contradiction between what the help page says and what constrOptim
actually
does with the constraints. The issue is what happens on the boundary.
The help page says
The feasible region is defined by ?ui %*% theta - ci >= 0?,
but the R code for constrOptim reads
if (any(ui %*% theta - ci <= 0))
stop("initial value not feasible")
The following example shows that when the initial point is on the boundary of
the
feasibility region, you get the above error message and execution stops.
> fn <- function(x) { return(sum(x)) }
>
> ui <- diag(rep(1,2))
> ci <- matrix(0,nrow=2,ncol=1)
> constrOptim( c(0,0), fn, NULL, ui, ci )
Error in optim(theta.old, fun, gradient, control = control, method = method, :
function cannot be evaluated at initial parameters>
> version
platform i386-pc-mingw32
arch i386
os mingw32
system i386, mingw32
status
major 2
minor 10.0
year 2009
month 10
day 26
svn rev 50208
language R
version.string R version 2.10.0 (2009-10-26)
In contrast, at a different place in constrOptim - the internal function R -
the boundary of the feasibility region is allowed: if (any(gi < 0))
return(NaN),
and it seems to explicitly allow boundaries at another place:
allowing gi==0 and interpreting log(gi) as -Inf.
John
...........................................................................
John P. Nolan
Math/Stat Department
227 Gray Hall
American University
4400 Massachusetts Avenue, NW
Washington, DC 20016-8050
jpnolan at american.edu
202.885.3140 voice
202.885.3155 fax
http://academic2.american.edu/~jpnolan
...........................................................................
Duncan Murdoch
2010-Jun-17 08:37 UTC
[Rd] constrOptim( ): conflict between help page and code
John Nolan wrote:> There is a contradiction between what the help page says and what constrOptim actually > does with the constraints. The issue is what happens on the boundary. >I don't know if this was a recent change, but the current help says: "The starting value must be in the interior of the feasible region, but the minimum may be on the boundary." The boundary is not in the interior. Duncan Murdoch> The help page says > The feasible region is defined by ?ui %*% theta - ci >= 0?, > but the R code for constrOptim reads > if (any(ui %*% theta - ci <= 0)) > stop("initial value not feasible") > The following example shows that when the initial point is on the boundary of the > feasibility region, you get the above error message and execution stops. > > >> fn <- function(x) { return(sum(x)) } >> >> ui <- diag(rep(1,2)) >> ci <- matrix(0,nrow=2,ncol=1) >> constrOptim( c(0,0), fn, NULL, ui, ci ) >> > Error in optim(theta.old, fun, gradient, control = control, method = method, : > function cannot be evaluated at initial parameters > >> version >> > platform i386-pc-mingw32 > arch i386 > os mingw32 > system i386, mingw32 > status > major 2 > minor 10.0 > year 2009 > month 10 > day 26 > svn rev 50208 > language R > version.string R version 2.10.0 (2009-10-26) > > In contrast, at a different place in constrOptim - the internal function R - > the boundary of the feasibility region is allowed: if (any(gi < 0)) return(NaN), > and it seems to explicitly allow boundaries at another place: > allowing gi==0 and interpreting log(gi) as -Inf. > > > John > > ........................................................................... > > John P. Nolan > Math/Stat Department > 227 Gray Hall > American University > 4400 Massachusetts Avenue, NW > Washington, DC 20016-8050 > > jpnolan at american.edu > 202.885.3140 voice > 202.885.3155 fax > http://academic2.american.edu/~jpnolan > ........................................................................... > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >
Ravi Varadhan
2010-Jun-22 22:18 UTC
[Rd] constrOptim( ): conflict between help page and code
Dear R-devel, I have re-worked the `constrOptim' function extensively to fix some bugs, and also to provide some extended functionality. Please find attached the patch (with comments on the bug fixes and improvements). I am also attaching a "test" file that shows the difference between the "old" and "new" versions of `constrOptim'. Best, Ravi. ____________________________________________________________________ Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvaradhan at jhmi.edu ----- Original Message ----- From: Martin Maechler <maechler at stat.math.ethz.ch> Date: Tuesday, June 22, 2010 3:33 am Subject: Re: [Rd] constrOptim( ): conflict between help page and code To: Ravi Varadhan <rvaradhan at jhmi.edu> Cc: maechler at stat.math.ethz.ch> Dear Ravi, > What we (R-core) really want with such postings is a "diff" aka "patch" > against the R-devel (!) sources, > which you can get from > > > > You produce a patch with e.g. > > diff -ubBw <previousversion>constrOptim.R <myversion>constrOptim.R > > send that (possibly as attached file e.g. constrOptim.patch) > to R-devel > > Best regards, > Martin-------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: constrOptim_PATCH_no_comments.txt URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20100622/f86e10af/attachment.txt> -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: constrOptim_test.txt URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20100622/f86e10af/attachment-0001.txt>