[R] Stuck using constrOptim

Ravi Varadhan RVaradhan at jhmi.edu
Fri Apr 24 00:32:49 CEST 2009


My bad.  It skipped my mind that constrOptim requires that you specify the
gradient function for using BFGS.  I have writtten a constrOPtim function
that computes the gradient numerically and also can incorporate non-linear
inequality constraints.  I will send it to you, if you are interested.

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/Varadhan.html

 

----------------------------------------------------------------------------
--------


-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of dre968
Sent: Thursday, April 23, 2009 5:23 PM
To: r-help at r-project.org
Subject: Re: [R] Stuck using constrOptim


if i run the same program with
constrOptim(p0,minsquare,keys=keys,benKeys=benKeys,NULL,ui=A,ci=B,method="BF
GS")

i get the following error:
Error in dR(theta, theta.old, ...) : could not find function "grad"

i'm not very mathematically inclined, i dont even know what a gradient is. 
any suggestions?


dre968 wrote:
> 
> Trying to use constrOptim to minimize the sum of squared deviations.  
> I put the objective function in as: sum((x %*% Y - Z)^2) so i'm trying 
> to get values for x to minimize the sum of the squared deviations 
> between the product of x and Y and Z.
> 
> Anyways i have no problem using this when x is a 3x1 test variable.  
> it works great with the constraints and everything.  when i actually 
> use it on my data x is 3x900 or so and it wont optimize it just gives 
> me back my initial guess....this is the output i'm getting:
> 
> $value
> [1] 22.7438
> 
> $counts
> function gradient 
>      906       NA 
> 
> $convergence
> [1] 1
> 
> $message
> NULL
> 
> $outer.iterations
> [1] 1
> 
> $barrier.value
> [1] 1.381551e-06
> 
> this is definitely not the right answer and it is just spitting back 
> my initial guess back.
> 
> Any ideas?  are there limits as to how big the variables can be for 
> this function?
> 

--
View this message in context:
http://www.nabble.com/Stuck-using-constrOptim-tp23197912p23203595.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
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